Create the wince Control Panel

Source: Internet
Author: User

// ================================================ ========================================================== ======================================
// Author:
// Norains
// Date:
// Saturday 25-feb-2006
// ================================================ ========================================================== ======================================
The control panel component is actually a directory DLL file, which is different from its suffix. cpl. the control panel component must implement a cplapplet interface. Its prototype is long callback cplapplet (hwnd hwndcpl, uint message, lparam lparam1, lparam lparam2 ). in this function, in order to make the component operate normally, we must process the following messages: cpl_init (initialization, where memory can be allocated, etc.), cpl_getcount (number of components displayed ), cpl_newinquire (component information can be displayed normally), cpl_dblclk (executed when the icon is double-clicked ).
To facilitate viewing, list this function body:

// =- =-=
// The entry point to the control panel application.
// =- =-=
Extern "C" Long callback cplapplet (hwnd hwndcpl, uint message, lparam lparam1, lparam lparam2)
{
Switch (Message)
{
Case cpl_init:
// Perform global initializations, especially memory
// Allocations, here.
// Return 1 for success or 0 for failure.
// Control panel does not load if failure is returned.
Return 1;

Case cpl_getcount:
// The number of actions supported by this control
// Panel application.
Return 1;

Case cpl_newinquire:
{
// This message is sent once for each dialog box,
// Determined by the value returned from cpl_getcount.
// Lparam1 is the 0-based index of the dialog box.
// Lparam2 is a pointer to the newcplinfo structure.
Return 0; // means cplapplet succeed
Return 1; // nonzero value means cplapplet failed.
}
Case cpl_dblclk:
{
// The user has double-clicked the icon for
// Dialog box in lparam1 (zero-based ).
Return 0; // cplapplet succeed.
Return 1; // cplapplet failed.
}

Case cpl_stop:
// Called once for each dialog box. Used for cleanup.

Case cpl_exit:
// Called only once for the application. Used for cleanup.

Default:
Return 0;
}

Return 1; // cplapplet failed.
} // Cplapplet

Components need to perform related operations, generally in. cpl files are operated internally, but we can. the CPL file is used as a shell to display an icon in the "control panel". The actual processing is to call another EXE file. the advantage is that. cpl code is versatile. If you want to add another component, you only need to change it. cpl a small amount of Code. In addition, the separation of function modules makes debugging more convenient if you want to change the relevant functions, as long as you modify the corresponding EXE file.

Now let's take a look at how to call the EXE file in the control panel.
We need to double-click the icon in the control panel to call our corresponding exe program. Obviously, we only need to add the call code in the cpl_dblclk message.
Extern "C" Long callback cplapplet (hwnd hwndcpl, uint message, lparam lparam1, lparam lparam2)
{
Switch (Message)

....

Case cpl_dblclk:
{
//-----------------------------------------------------------------
// Description of the findwindow function:
// Prototype: hwnd findwindow (maid, lpwindowname );
// Lpclassname: the value to be assigned is the string name of the class. You can run remote spy ++ in CE to view it. In this example, you can use this tool to see "dialog ".
// This parameter can also be null, provided that the headers of all running Windows are different.
// Lpwindowname: name of the window title string, that is, the window title we can see
//------------------------------------------------------------------
// Because our EXE file has only one window, the following function can also write findwindow (null, text ("backlight adjustment "))
Hwnd = findwindow (L "dialog", text ("backlight adjustment "));
If (hwnd)
{
// If an instance has been run, it is mentioned before the window
Setforegroundwindow (hwnd );
Closehandle (hwnd );
Return 0;
}
Else
{
// Call the EXE file.
If (CreateProcess (_ T ("// windows // backlight.exe"), null, false, 0, null, & PI ))
{
Closehandle (PI. hthread );
Closehandle (PI. hprocess );
Return 0;
}
}
Return 1; // cplapplet failed.
}

....

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.