PPC Today界面的开发总结(一):PPC Today插件的调试
关于PPC Today界面的调试,起初我将安装包安装后重启,后来发现完全可以不必这样,在SDK的WIN32的例子中有个Setupdll的程序,这个程序中的codeINSTALL_EXIT Install_Exit函数中除了注册PPC Today界面以外,关键的是SendMessage(HWND_BROADCAST, WM_WININICHANGE, (WPARAM)0xF2, 0),有了这一句我们立即就可以看到程序的效果。我们可以把安装完后要执行动作放到这个函数下(包括程序的启动),下面是这个函数的示例代码:
codeINSTALL_EXIT Install_Exit(HWND hwndparent,
LPCTSTR pszinstalldir,
WORD cfaileddirs,
WORD cfailedfiles,
WORD cfailedregkeys,
WORD cfailedregvals,
WORD cfailedshortcuts)
{
HKEY hOpenKey = NULL;
long lResult = 0;
DWORD dwOpenStyle = 0;
DWORD iValueType = 0;
DWORD iLen = 0;
DWORD iTemp = 0;
TCHAR szPath[MAX_PATH] = {'\0'};
TCHAR szLinkPath[MAX_PATH] = {0};
TCHAR szAppPath[MAX_PATH] = {0};
LPCTSTR keyName = _T("Software\\CabSample");
LPCTSTR csAppPath = _T("AppPath");
LPCTSTR csTodaykey = _T("Software\\Microsoft\\Today\\Items\\\"打包示例\"");
LPCTSTR csPlugName = _T("MyToday.dll"); // 你的插件名
LPCTSTR csAppName = _T("CabSample.exe"); // 你的程序名
if(cfaileddirs || cfailedfiles || cfailedregkeys
|| cfailedregvals || cfailedshortcuts)
goto Failed;
//获取主程序安装路径
_tcscpy(szPath, pszinstalldir);
_tcscat(szPath, _T("\\"));
_tcscat(szPath, csAppName);
//设置主程序快捷方式的执行路径
_tcscpy(szAppPath, _T("\""));
_tcscat(szAppPath, szPath);
_tcscat(szAppPath, _T("\""));
// 将主程序安装路径写入注册表
lResult = ::RegCreateKeyEx(HKEY_CURRENT_USER, keyName, 0, _T(""), REG_OPTION_NON_VOLATILE,
0,NULL,&hOpenKey, &dwOpenStyle);
if(lResult != ERROR_SUCCESS)
goto Success;
::RegSetValueEx(hOpenKey, csAppPath, 0, REG_SZ, (BYTE*)&szPath, sizeof(TCHAR) * _tcslen(szPath));
::RegCloseKey(hOpenKey);
memset(szPath, 0x00, sizeof(TCHAR) * MAX_PATH);
_tcscpy(szPath, pszinstalldir);
_tcscat(szPath, _T("\\"));
_tcscat(szPath, csPlugName);
::CopyFile(szPath, _T("\\Windows\\MyToday.dll"), FALSE);
// 安装 “今日插件”
hOpenKey = NULL;
lResult = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, csTodaykey, 0, _T(""), REG_OPTION_NON_VOLATILE,
0, NULL, &hOpenKey, &dwOpenStyle);
if(lResult != ERROR_SUCCESS)
goto Success; //如果读写注册表失败, 放弃安装 “今日插件”
// 注册插件
iTemp = 0;
::RegSetValueEx(hOpenKey, _T("Flags"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
::RegSetValueEx(hOpenKey, _T("Options"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
iTemp = 1;
::RegSetValueEx(hOpenKey, _T("Enabled"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
::RegSetValueEx(hOpenKey, _T("Order"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
::RegSetValueEx(hOpenKey, _T("Selectability"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
iTemp = 4;
::RegSetValueEx(hOpenKey, _T("Type"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
::RegSetValueEx(hOpenKey, _T("DLL"), 0, REG_SZ, (BYTE*)_T("\\Windows\\MyToday.dll"), sizeof(TCHAR) * _tcslen(szPath));
// 发送系统消息
::SendMessage(HWND_BROADCAST, WM_WININICHANGE, (WPARAM)0xF2, 0);
::RegCloseKey(hOpenKey);
//创建快捷方式
if(SHGetSpecialFolderPath(NULL, szLinkPath, CSIDL_PROGRAMS,FALSE))
{
_tcscat(szLinkPath, _T("\\"));
_tcscat(szLinkPath, _T("打包示例.lnk"));
if(SHCreateShortcut(szLinkPath, szAppPath) == FALSE)
{
MessageBox(NULL, _T("安装快捷方式失败"), _T("提示"), MB_OK);
}
}
else
MessageBox(NULL, _T("获取系统文件路径失败"), _T("提示"), MB_OK);
//return value
Success:
return codeINSTALL_EXIT_DONE;
Failed:
return codeINSTALL_EXIT_UNINSTALL;
}
然后在Setupdll程序生成的安装包中把你的今日插件放进来,然后在PPC上运行Setupdll安装包就可以了,关于注册表的值,请看下表:
Value Name and Type | Description |
---|---|
DWORD: Type | Custom Items must have Type = 4 |
DWORD: Enabled | 0 or 1; 1 causes Today panel to show your component; nevertheless, the user can control it via the Today applet in the Control Panel |
DWORD: Options | if equals 1, the "Options" button in the Today applet will be enabled |
SZ: DLL | Pull path to your component |
DWORD : Selectability | New feature in Win Mobile 2003 SE; allows receiving additional notifications Values are used as follows:
|