WCE下的控制面板程序(CPL)與PC上的CPL開(kāi)發(fā)有些許的不同,但總體上是一致的。這里總結(jié)一下在開(kāi)發(fā)CPL時(shí)的思路。
CPL文件實(shí)際上是一個(gè)DLL文件,DLL入口為CPlApplet,原型為:
LONG CPlApplet(HWND hwndCPl,UINT msg,LPARAM lParam1,LPARAM lParam2),
將開(kāi)發(fā)出來(lái)的CPL文件置于[Windows]目錄下(PC上為[Windows/system32]下),系統(tǒng)會(huì)自動(dòng)掃描并識(shí)別,然后將其在控制面板中顯示出來(lái)(WCE中是在[Settings->System]中顯示)。
系統(tǒng)會(huì)在特定的時(shí)候進(jìn)入CPlApplet,這些時(shí)刻可以通過(guò)CPlApplet函數(shù)參數(shù)msg來(lái)解讀,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是個(gè)很重要的消息,它表示用戶(hù)雙擊(或按了確認(rèn)按鈕)了控制面板中的該程序的圖標(biāo)。因此該消息處理中可以進(jìn)行主窗口的啟動(dòng)動(dòng)作,如果窗口已經(jīng)啟動(dòng),可以將窗口提前顯示。
該消息返回0表示成功處理。 CPL_EXIT消息會(huì)在CPL_STOP消息發(fā)送之后發(fā)送。可以在該消息處理中做一些清理工作。
該消息返回0表示成功處理。 CPL_GETCOUNT消息MSDN上解釋是retrieve the number of dialog boxes supported by the application,實(shí)際測(cè)試該消息的使用功能是返回?cái)?shù)目會(huì)影響在控制面板數(shù)出現(xiàn)的圖標(biāo)數(shù)量,如果返回2,控制面板中會(huì)出現(xiàn)兩個(gè)CPL的圖標(biāo)。
CPL_IDNAME消息使用到兩個(gè)另外的參數(shù)LPARAM lParam1和LPARAM lParam2,lParam1這里傳入CPL的全局惟一ID號(hào),lParam2需要在處理中指向一個(gè)字符串,該字符串將用來(lái)表示CPL的ID NAME,該名稱(chēng)可以與控制面板中的CPL顯示名不同。
該消息返回0表示成功處理。 CPL_INIT消息會(huì)在控制面板載入CPL后立即被觸發(fā),可以進(jìn)行一些全局內(nèi)存開(kāi)辟的動(dòng)作。
該消息返回1表示成功處理。 CPL_NEWINQUIRE消息用來(lái)得到CPL必要的信息。lParam1傳入CPL的全局惟一ID號(hào),lParam2指向
NEWCPLINFO結(jié)構(gòu)體,開(kāi)發(fā)者需要對(duì)該結(jié)構(gòu)體的內(nèi)容進(jìn)行填充。MSDN中對(duì)該消息有如下的解釋?zhuān)?br>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消息會(huì)在用戶(hù)關(guān)閉了CPL主窗口時(shí)被調(diào)用,
該消息返回0表示成功處理。 從上述消息介紹中可以看出,返回值很重要。如果返回值不正確,可能發(fā)生意想不到的后果。
PS: 與之類(lèi)似的,WCE下的Service程序開(kāi)發(fā),XXX_系列接口函數(shù)的返回值也很重要,需要重視。