2 創(chuàng)建Hello World應(yīng)用工程
打開(kāi)wince OS Designe工程,點(diǎn)擊文件(F) -> 新建(N)-> Subproject添加子工程,工程類型設(shè)置為WCE Application,Subproject name命名為Helloworld
點(diǎn)擊下一步(N),選擇A typical “Hello world” application,然后點(diǎn)擊完成(F)。
3 創(chuàng)建HelloCPL控制面板應(yīng)用工程
點(diǎn)擊文件(F) -> 新建(N)-> Subproject添加子工程,工程類型設(shè)置為WCE Dynamic-Link Library,工程名為HelloCPL。
然后點(diǎn)擊下一步(N),在Auto-generated subproject files頁(yè)面中選擇A Dll that exports some symbols。
這是工程面板中看起來(lái)如下:
雙擊HelloCPL工程中Source files下的HelloCPL.cpp,將其中的內(nèi)容替換如下:
//
// HelloCPL.cpp : Defines the entry point for the DLL
//
#include "stdafx.h" // Auto-generated by wizard.
#include "HelloCPL.h" // Auto-generated by wizard.
#include "resource.h" // Auto-generated at compile time
#include <tchar.h> // General text functions.
#include "cpl.h" // Control Panel support.
#define DEBUG
// Returns the number of characters in an expression.
#define lengthof(exp) ((sizeof((exp)))/sizeof((*(exp))))
HMODULE g_hModule = NULL; // Handle to the DLL.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Main entry point for the Control Panel DLL.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
extern "C" 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" HelloCPL_API 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, as
// 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;
if (lpNewCplInfo)
{
lpNewCplInfo->dwSize = sizeof(NEWCPLINFO);
lpNewCplInfo->dwFlags = 0;
lpNewCplInfo->dwHelpContext = 0;
lpNewCplInfo->lData = IDI_HELLOWORLD;
// 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_HELLOWORLD));
LoadString(g_hModule, IDS_APP_TITLE, lpNewCplInfo->szName,
lengthof(lpNewCplInfo->szName));
LoadString(g_hModule, IDS_HELLO, lpNewCplInfo->szInfo,
lengthof(lpNewCplInfo->szInfo));
// LoadString(g_hModule, IDC_HelloWorld, 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 the
// dialog box in lParam1 (zero-based).
PROCESS_INFORMATION pi = {0};
if (CreateProcess(_T("\\Windows\\HelloWorld.exe"), NULL, NULL,
NULL, FALSE, 0, NULL, NULL, 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.
case CPL_EXIT:
// Called only once for the application. Used for cleanup.
default:
return 0;
}
return 1; // CPlApplet failed.
} // CPlApplet
&nbs, p; 本工程用到1個(gè)圖標(biāo)資源文件IDI_HELLOWORLD,2個(gè)字符串資源IDS_APP_TITLE和IDS_HELLO。
4 向控制面板添加資源文件
A、右鍵點(diǎn)擊HelloCPL -> Source Files,選擇Add -> New Item,見(jiàn)下圖:
點(diǎn)擊Add后,雙擊HelloCPL->source files->HelloCPL.rc,見(jiàn)下圖
B、右鍵點(diǎn)擊上圖中的HelloCPL.rc,選擇Add Resource,彈出下面的對(duì)話框,添加ICON
并修改Icon的ID為IDI_HELLOWORLD.
C、重復(fù)步驟B,添加String Table,并修改String Table中的內(nèi)容如下:
5編譯控制面板應(yīng)用程序
A、右鍵點(diǎn)擊HelloCPL工程,選擇屬性,彈出如下窗口
B、選擇General標(biāo)簽頁(yè),在Custom Variable欄點(diǎn)擊 按鈕打開(kāi)Custom Variable對(duì)話框。
C、點(diǎn)擊NEW打開(kāi)Environment Variable窗口,Variable Name輸入CPL,Variable Value輸入1。點(diǎn)擊OK關(guān)閉Environment Variable,再點(diǎn)擊OK關(guān)閉Custom Variables。這樣做的目的是強(qiáng)制工程輸出.cpl文件,而不是.dll文件。
D、點(diǎn)擊C/C++標(biāo)簽頁(yè),在Include Directories添加$(_PROJECTROOT)\cesysgen\oak\inc。
確認(rèn)Additional MacroDefinitions設(shè)置為$ (CDEFINES) -DHelloCPL_EXPORTS 。
修改 DLL Entry Point為Dllmain。
點(diǎn)擊OK關(guān)閉屬性設(shè)置對(duì)話框。
E、修改HelloCPL.bib,替換為如下內(nèi)容 MODULES HelloCPL.cpl $(_FLATRELEASEDIR)\HelloCPL.cpl NK
F、右鍵點(diǎn)擊HelloCPL,然后Build即可生成對(duì)應(yīng)的內(nèi)核,燒錄到系統(tǒng)啟動(dòng)后即可在控制面板中看到Hello Control Panel的圖標(biāo),雙擊后即可運(yùn)行Helloworld.exe
|