Wince6.0 Add a control panel application on the control panel

Source: Internet
Author: User

 

* ****************************** Loongembedded ******* *************************

Author: loongembedded (Kandi)

Time: 2011.8.25

Category: wince System Development

* ****************************** Loongembedded ******* *************************

1. wince Control Panel Architecture

 

And some Control Panel files (. CPL ). Ctlpnl.exeand control.exe are used by the operating system to control the display and mechanism of control panel folders. These two parts constitute the most fundamental part of the control panel system architecture, and those. Cpl files correspond to applications of Control Panel functions. If you want to create a control panel application for the sub-set, we will create a. c file, which leads to the callback function for the architecture created by control.exe.

 

A Control Panel application is actually a DLL, but its extension is. cpl file. This file exports the callback function cplapplet to process the cpl_init, cpl_getcount, cpl_newinqure, and cpl_stop | volumes sent by the Control Panel System to execute the corresponding applications. It can also be processed directly. When you open the control panel, the OS searches for the directory located under "\ Windows. the CPL file lists the control panel applications in the control panel system. For example, the current system has the following. CPL:

Figure 1

When I double-click the "control panel" icon to enter the control panel, the following error message is displayed:

CPL: failed to load '\ WINDOWS \ SYSTEM. Cpl'

It indicates that system. Cpl loading failed. In the system where I added my own application hellocpl. CPL, When I double-click "Control Panel", the following information is also prompted:

CPL: failed to load '\ windows \ hellocpl. Cpl'

After adding the following content to the hellocpl. file, the hellocpl. CPL

Library hellocpl

Exports

Cplapplet

You can not find the place where system. CPL is generated in the wince600 directory, only in the following directory

\ Wince600 \ public \ datasync \ oak \ ctlpanel \ system find and generate systemcpl. the source code of CPL is located, but its export function is killallapps and is empty. Therefore, the icon corresponding to the control panel application cannot be seen in the control panel.

 

The ctlpnl folder contains nine folders corresponding to different CPL files:

Advbacklight: Advanced backlight management.

Bthpnl: Bluetooth.

Connpnl: Dial-Up Network.

Control: the main console. This is the control panel we see in explorer.

Cplmain: cplmain. CPL is generated. Most options on the control panel are derived from this.

Ctlpnl: associated with control

Dmpnl: The corresponding Device Manager.

Intl2: Region and language settings.

Stgui: memory management.

Figure 2

2. Control Panel application entry and export functions

2.1 portal function dllmain

Because the. Cpl file is actually a DLL, And the DLL entry function is dllmain, it is natural that the entry function of the Control Panel application is dllmain. When the process and field are initialized and terminated, the system will call this function, or call this entry function when calling loadlibrary () and freelibrary () functions.

 

The role of the dllmai function here is to save the handle passed to the DLL for later use.

2.2. the callback function cplapplet to be exported by the def Function

Long cplapplet (hwnd hwndcpl, uint MSG, lparam lparam1, lparam lparam2)

Hwndcpl: Control Panel window handle

MSG: Messages sent to the control panel Application

The control panel messages supported in wince are as follows:

Cpl_init:The first message is received when the message is loaded for the first time. After receiving the message, the control panel application immediately initializes the global variable, in particular, the memory allocation action is also executed here.

Cpl_getcount: The second received message, which is used to obtain the number of components in the control panel application, because. the CPL file may contain multiple Applet programs, such as cplmain. cpl contains more than a dozen applent programs, as shown in figure 2.

Cpl_newinquire: Query the information of the dialog box (dialog box) supported by the current control panel program. cpl contains multiple dialogs. lparam1 indicates the dialog box number. lparam2 is a pointer to the newcplinfo structure and describes information about a dialog box, as shown in figure 2, connpnl. CPL has 14 components. For example, the pen is a dialog box supported by Cpl. When we double-click the pen icon, the following information is output through the serial port:

Ctlpnl: cmdline = \ windows \ cplmain. CPL, 9

--- >>> Ctlpnl: CPL = '\ windows \ cplmain. cpl' icon = 9 tab = 0

Note: The "pen" is the 9th dialogs supported by cplmain. Cpl. When you double-click the "display resolution" icon in Figure 2, the following serial port information is output:

Ctlpnl: cmdline = \ windows \ hellocpl. CPL, 0

--- >>> Ctlpnl: CPL = '\ windows \ hellocpl. cpl' icon = 0 tab = 0

Because the added control panel application hellocpl. Cpl only supports one dialog box, the above 0 indicates 0th dialog boxes. The newcplinfo struct to which lparam2 points is defined as follows:

Typedef struct tagnewcplinfo {

DWORD dwsize;

DWORD dwflags;

DWORD dwhelpcontext;

Long ldata;

Hicon;

Tchar szname [32];

Tchar szinfo [64];

Tchar szhelpfile [128];

} Newcplinfo;

 

Dwsize: Structure information

Dwflags: Ignore

Dwhelpcontext: Ignore

Ldata: Data passed to the build-up program

Hicon: The handle of the icons displayed in the control panel, as shown in figure 2.

Szname: The name of the component displayed in the control panel, such as the pen"

Szinfo: Displays the description information in the control panel.

Szhelpfile: Ignore

 

Cpl_dbclk: When you double-click an application on the control panel interface, you will receive the message and execute the corresponding application in the message. If there are multiple dialogs, lparam1 indicates the dialog box number, and lparam2 indicates the data sent to the application.

Cpl_stop: When the control panel application is closed, this message is received to release resources. If there are multiple dialogs, lparam1 indicates the dialog box number, and lparam2 indicates the data sent to the application.

Cpl_exit: After the cpl_stop message is sent, the control panel receives the message when the application is released.

 

Lparam1: Message Parameter 1

Lparam2: Message Parameter 2

 

 

3. Add the control panel application to the wince Control Panel

 

3.1 create an application

Before creating an application, we must first have a system project of wince. On the basis of opening this project, we create an application sub-project, in file-> New-> subproject, select wce application. Here we select the Hello world application. The purpose of creating this application is called by the Control Panel application created later.

3.2 Create a CPL project for the Control Panel Application

Click file-> New-> subproject, select wce dynamic-Link Library, and the project name is hellocpl.

Figure 3

Click Next and select a DLL that exports some symbols on the auto-generated subproject files page.

Figure 4

Click Finish. After the first two parts, we can see:

Figure 5

 

3.3 modify dllmain and add the cplapplet Function

 

# Include "Cpl. H" // because the cplapplet function is added, this function processes the cpl_xxx message.

# Include "resource. H" // idi_hello_cpl, ids_hello_kandi, and ids_hello_sandi are defined here

 

# Define lengthof (exp) (sizeof (exp)/sizeof (* (exp ))))

 

Hmodule g_hmodule = NULL; // handle to the DLL.

 

Bool apientry dllmain (handle hmodule,

DWORD ul_reason_for_call,

Lpvoid lpreserved

)

{

Switch (ul_reason_for_call)

{

Case dll_process_attach:

{

G_hmodule = (hmodule) hmodule;

}

 

Case dll_thread_attach:

Case dll_thread_detach:

Case dll_process_detach:

Break;

}

Return true;

}

 

 

// =- =-=

// 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.

// Retailmsg (1, (text ("Kandi helloworld test 1111 \ r \ n ")));

Return 1;

 

Case cpl_getcount:

// The number of actions supported by this control

// Panel application.

// Retailmsg (1, (text ("Kandi helloworld test 2222 \ r \ n ")));

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.

{

Assert (0 = lparam1 );

Assert (lparam2 );

 

Newcplinfo * lpnewcplinfo = (newcplinfo *) lparam2;

// Release (text ("Kandi test 1111 \ r \ n ")));

// Retailmsg (1, (text ("Kandi helloworld test 3333 \ r \ n ")));

If (lpnewcplinfo)

{

Lpnewcplinfo-> dwsize = sizeof (newcplinfo );

Lpnewcplinfo-> dwflags = 0;

Lpnewcplinfo-> dwhelpcontext = 0;

Lpnewcplinfo-> ldata = idi_hello_cpl;

// Retailmsg (1, (text ("Kandi helloworld test 44444 \ r \ n ")));

// The large icon for this application. Do not free this

// Hicon; it is freed by the Control Panel infrastructure.

Lpnewcplinfo-> hicon = loadicon (g_hmodule,

Makeintresource (idi_hello_cpl ));

 

Loadstring (g_hmodule, ids_hello_kandi, lpnewcplinfo-> szname,

Lengthof (lpnewcplinfo-> szname ));

Loadstring (g_hmodule, ids_hello_sandi, lpnewcplinfo-> szinfo,

Lengthof (lpnewcplinfo-> szinfo ));

_ Tcscpy (lpnewcplinfo-> szhelpfile, _ T (""));

Return 0;

}

Return 1; // nonzero value means cplapplet failed.

}

 

 

Case cpl_dblclk:

{

// The user has double-clicked the icon for

// Dialog box in lparam1 (zero-based ).

// Retailmsg (1, (text ("Kandi helloworld test 5555 \ r \ n ")));

Process_information Pi = {0 };

If (CreateProcess (_ T ("\ Windows \ helloworld.exe"), null, false, 0, null, & PI ))

{

Closehandle (PI. hthread );

Closehandle (PI. hprocess );

Return 0;

}

Return 1; // cplapplet failed.

}

 

Case cpl_stop:

// Called once for each dialog box. Used for cleanup.

// Retailmsg (1, (text ("Kandi helloworld test 66666 \ r \ n ")));

Case cpl_exit:

// Called only once for the application. Used for cleanup.

// Retailmsg (1, (text ("Kandi helloworld test 77777 \ r \ n ")));

Default:

Return 0;

}

 

Return 1; // cplapplet failed.

} // Cplapple

 

3.4 add the icons and strings to be loaded when the cplapplet function processes cpl_newinquire.

Here, the icons and strings correspond to the definitions of ID: idi_hello_cpl, ids_hello_kandi, and ids_hello_sandi respectively. The steps to add them are as follows:

1) Add an RC resource file for the CPL Project

Right-click hellocpl-> source files in Figure 5 and select Add-> new item. For details, see:

Figure 6

Click Add and double-click hellocpl-> source files-> hellocpl. Rc. See

Figure 7

3.5 add ICO icons and strings to the RC resource file

Right-click hellocpl. RC in Figure 7 and select Add resource. The following dialog box is displayed.

Figure 8

I will not describe it.

3.6 modify hellocpl project configuration

1) modify the content of the hellocpl. bib file

Modules

Hellocpl. Cpl $ (_ flatreleasedir) \ hellocpl. Cpl NK

 

2) Right-click the hellocpl project, select Properities, select the general page, and on the custom variable

The variable name is CPL and the value is 1. The purpose is to force the hellocpl application to be generated with the extension. Cpl instead of DLL. Select the C/C ++ page and confirm that the value of additional macro definitions is $ (cdefines)-dhellocpl_exports. Set the DLL entry point to dllmain, because the entry function of hellocpl. CPL is dllmain. Add the path $ (_ projectroot)/cesysgen/oak/INC to the include directories item.

 

3) Add the following content to the hellocpl. Def file.

Library hellocpl

 

Exports

Cplapplet

The purpose is to interface the cplapplet everywhere. Adding or not adding the content will not be able to effectively load hellocpl. Cpl.

 

3.7 separately compile the helloworldproject and hellocplproject separately.

Hellocpl. CPL, then a new NK. Bin will be generated, and the NK. Bin will be burned to the wince device. Double-click the control panel and you will see:

Figure 9

Double-click the icon corresponding to hellocpl. Cpl. You can see:

Figure 10

The interface displayed by the helloworld.exe application is called by the cplapplet function of hellocpl. Cpl when processing double-click messages.

 

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.