2 创建Hello World应用工程
打开wince OS Designe工程,点击文件(F) -> 新建(N)-> Subproject添加子工程,工程类型设置为WCE Application,Subproject name命名为Helloworld
点击下一步(N),选择A typical “Hello world” application,然后点击完成(F)。
3 创建HelloCPL控制面板应用工程
点击文件(F) -> 新建(N)-> Subproject添加子工程,工程类型设置为WCE Dynamic-Link Library,工程名为HelloCPL。
然后点击下一步(N),在Auto-generated subproject files页面中选择A Dll that exports some symbols。
这是工程面板中看起来如下:
双击HelloCPL工程中Source files下的HelloCPL.cpp,将其中的内容替换如下:
//
// 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个图标资源文件IDI_HELLOWORLD,2个字符串资源IDS_APP_TITLE和IDS_HELLO。
4 向控制面板添加资源文件
A、右键点击HelloCPL -> Source Files,选择Add -> New Item,见下图:
点击Add后,双击HelloCPL->source files->HelloCPL.rc,见下图
B、右键点击上图中的HelloCPL.rc,选择Add Resource,弹出下面的对话框,添加ICON
并修改Icon的ID为IDI_HELLOWORLD.
C、重复步骤B,添加String Table,并修改String Table中的内容如下:
5编译控制面板应用程序
A、右键点击HelloCPL工程,选择属性,弹出如下窗口
B、选择General标签页,在Custom Variable栏点击 按钮打开Custom Variable对话框。
C、点击NEW打开Environment Variable窗口,Variable Name输入CPL,Variable Value输入1。点击OK关闭Environment Variable,再点击OK关闭Custom Variables。这样做的目的是强制工程输出.cpl文件,而不是.dll文件。
D、点击C/C++标签页,在Include Directories添加$(_PROJECTROOT)\cesysgen\oak\inc。
确认Additional MacroDefinitions设置为$ (CDEFINES) -DHelloCPL_EXPORTS 。
修改 DLL Entry Point为Dllmain。
点击OK关闭属性设置对话框。
E、修改HelloCPL.bib,替换为如下内容 MODULES HelloCPL.cpl $(_FLATRELEASEDIR)\HelloCPL.cpl NK
F、右键点击HelloCPL,然后Build即可生成对应的内核,烧录到系统启动后即可在控制面板中看到Hello Control Panel的图标,双击后即可运行Helloworld.exe
|