WCE下的控制面板程序(CPL)与PC上的CPL开发有些许的不同,但总体上是一致的。这里总结一下在开发CPL时的思路。
CPL文件实际上是一个DLL文件,DLL入口为CPlApplet,原型为:
LONG CPlApplet(HWND hwndCPl,UINT msg,LPARAM lParam1,LPARAM lParam2),
将开发出来的CPL文件置于[Windows]目录下(PC上为[Windows/system32]下),系统会自动扫描并识别,然后将其在控制面板中显示出来(WCE中是在[Settings->System]中显示)。
系统会在特定的时候进入CPlApplet,这些时刻可以通过CPlApplet函数参数msg来解读,WCE下的MSG有一下几种:
Message
|
Description
|
CPL_DBLCLK
|
Sent to the CPlApplet function when a user taps the icon of a Control Panel application (CPL) supported by the function.
|
CPL_EXIT
|
Sent to the CPlApplet function before the system releases the DLL that contains the function.
|
CPL_GETCOUNT
|
Sent to the CPlApplet function to retrieve the number of Control Panel applications (CPLs) supported by the function.
|
CPL_IDNAME
|
Sent to the CPlApplet function to retrieve a Control Panel application's unique ID name string.
|
CPL_INIT
|
Sent to the CPlApplet function to prompt it to perform initialization for all Control Panel applications (CPLs) that it supports.
|
CPL_NEWINQUIRE
|
Sent to the CPlApplet function to request information about a Control Panel application (CPL) that it supports.
|
CPL_STOP
|
Sent to the CPlApplet function for each Control Panel application (CPL)it implements to prompt it to close down that CPL.
|
CPL_DBLCLK是个很重要的消息,它表示用户双击(或按了确认按钮)了控制面板中的该程序的图标。因此该消息处理中可以进行主窗口的启动动作,如果窗口已经启动,可以将窗口提前显示。
该消息返回0表示成功处理。 CPL_EXIT消息会在CPL_STOP消息发送之后发送。可以在该消息处理中做一些清理工作。
该消息返回0表示成功处理。 CPL_GETCOUNT消息MSDN上解释是retrieve the number of dialog boxes supported by the application,实际测试该消息的使用功能是返回数目会影响在控制面板数出现的图标数量,如果返回2,控制面板中会出现两个CPL的图标。
CPL_IDNAME消息使用到两个另外的参数LPARAM lParam1和LPARAM lParam2,lParam1这里传入CPL的全局惟一ID号,lParam2需要在处理中指向一个字符串,该字符串将用来表示CPL的ID NAME,该名称可以与控制面板中的CPL显示名不同。
该消息返回0表示成功处理。 CPL_INIT消息会在控制面板载入CPL后立即被触发,可以进行一些全局内存开辟的动作。
该消息返回1表示成功处理。 CPL_NEWINQUIRE消息用来得到CPL必要的信息。lParam1传入CPL的全局惟一ID号,lParam2指向
NEWCPLINFO结构体,开发者需要对该结构体的内容进行填充。MSDN中对该消息有如下的解释:
The Control Panel sends the CPL_NEWINQUIRE message once for each dialog box supported by the application. The Control Panel also sends a CPL_INQUIRE message for each dialog box. These messages are sent immediately after the CPL_GETCOUNT message. However, the system does not guarantee the order in which the CPL_INQUIRE and CPL_NEWINQUIRE messages are sent.
The CPL_NEWINQUIRE message was introduced in Windows version 3.1 as a replacement for CPL_INQUIRE. However, CPL_INQUIRE is the preferred message for Microsoft Windows 95 and Microsoft Windows NT® version 4.0. This is because CPL_NEWINQUIRE returns information in a form that the system cannot cache. Consequently, applications that process CPL_NEWINQUIRE must be loaded each time the Control Panel needs the information, resulting in a significant reduction in performance.
该消息返回0表示成功处理。 CPL_STOP消息会在用户关闭了CPL主窗口时被调用,
该消息返回0表示成功处理。 从上述消息介绍中可以看出,返回值很重要。如果返回值不正确,可能发生意想不到的后果。
PS: 与之类似的,WCE下的Service程序开发,XXX_系列接口函数的返回值也很重要,需要重视。