哭求:自己写了个case

jyzdtn 2010-03-05 05:27:41
RT
...全文
78 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jyzdtn 2010-03-05
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <todaycmn.h>
#include "resource.h"

#define PLUG_HEIGHT 20
#define MAX_ITEMS 1
// global variables define

HICON g_hIcon = NULL;
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
HWND g_hWndParent = NULL;
BOOL g_bSelected = FALSE;
//int g_nSelectedItem = 0;

HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *ptli, HWND hwndParent);
LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam, LPARAM lParam) ;

// forward function declarations
static INT InitilizeClasses();

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:

g_hInst = (HINSTANCE)hModule;

//load the icon
g_hIcon = (HICON)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_DISPLAYICON));

//initilize the application class, and set the global window handle
UnregisterClass(_T("无线城市"), g_hInst);
InitilizeClasses();
g_hWnd = NULL;

break;

case DLL_PROCESS_DETACH:
// The DLL is being unloaded by a given process. Do any
// per-process clean up here, such as undoing what was done in
// DLL_PROCESS_ATTACH. The return value is ignored.

DestroyIcon(g_hIcon);

UnregisterClass(_T("无线城市"), g_hInst);
g_hInst = NULL;
break;
}

return TRUE;
}

VOID PaintAll(HWND hWnd, HDC hdc)
{
TODAYDRAWWATERMARKINFO dwi;
dwi.hwnd = hWnd;
dwi.hdc = hdc;
COLORREF bkcr;
RECT rect;

//画当前条目系统背景
::GetClientRect(hWnd, &(dwi.rc));
::GetClientRect(hWnd, &rect);
::SendMessage(g_hWndParent, TODAYM_DRAWWATERMARK, 0, (LPARAM)&dwi);//系统背景

if(g_bSelected) //当前条目为选中状态,设置高亮
{
//获取高亮背景色
bkcr = SendMessage(g_hWndParent,TODAYM_GETCOLOR,(WPARAM)TODAYCOLOR_HIGHLIGHT,NULL);
//设置背景为高亮色
HBRUSH hbrush = CreateSolidBrush(bkcr);
FillRect(hdc,&rect,hbrush);
DeleteObject(hbrush);

//设置文本高亮
SetTextColor(hdc, SendMessage(g_hWndParent, TODAYM_GETCOLOR, TODAYCOLOR_HIGHLIGHTEDTEXT,0));
}
else //当前条目为非选中状态
{
SetTextColor(hdc, SendMessage(g_hWndParent, TODAYM_GETCOLOR, TODAYCOLOR_TEXT,0));
}

//设备透明背景
SetBkMode(hdc,TRANSPARENT);

RECT rc(dwi.rc);
rc.left += 2;
rc.top += 2;

// first draw icon
DrawIcon(hdc, rc.left, rc.top, g_hIcon);

// second draw text
rc.top -= 2;
rc.left += 26;
DrawText(hdc, _T("无线城市"), -1, &rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uimessage, WPARAM wParam, LPARAM lParam)
{
char debText[128] = {0};
wchar_t debTextTemp[128] = {0};

switch (uimessage)
{
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
{
TODAYLISTITEM *ptli = (TODAYLISTITEM *)wParam;

if (NULL == ptli)
break;

if (0 == ptli->cyp)
{
ptli->cyp = PLUG_HEIGHT;
return TRUE;
}
}
break;

case WM_CREATE:
break;

case WM_LBUTTONUP:
{
g_bSelected = TRUE;
//g_nSelectedItem = 1;
PostMessage(GetParent(hWnd), TODAYM_TOOKSELECTION, (WPARAM)hWnd, 0);

// 1 判断是否在 有效区域,2 查询注册表, 得到程序路径, 3 启动程序
RECT rect;
POINT point;

//MessageBox(NULL, _T("WM_LBUTTONUP DllMain"), _T("DllMain"), MB_OK);

point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
::GetClientRect(hWnd, &rect);
if(PtInRect(&rect, point))
{
HKEY hOpenKey;
long lResult = 0;
DWORD iValueType = 0;
DWORD iLen = 0;
PROCESS_INFORMATION procInfo;

TCHAR szPath[MAX_PATH] = {'\0'};
LPCTSTR keyName = _T("Software\\Microsoft\\Today\\Items\\\"无线城市\""); //此注册表存放你应用程序的执行路径
LPCTSTR csAppPath = _T("AppPath");

//MessageBox(hWnd, _T("1"), _T("提示"), MB_OK);

lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 0, &hOpenKey);

ASSERT(lResult == ERROR_SUCCESS);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(hWnd, _T("读注册表失败"), _T("提示"), MB_OK);
break;
}

//MessageBox(hWnd, keyName, _T("提示"), MB_OK);

iLen = MAX_PATH * sizeof(TCHAR);
lResult = ::RegQueryValueEx(hOpenKey, csAppPath, 0, &iValueType, (BYTE*)szPath, &iLen);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(hWnd, _T("读注册表失败"), _T("提示"), MB_OK);
::RegCloseKey(hOpenKey);
break;
}

//MessageBox(hWnd, csAppPath, _T("提示"), MB_OK);
//MessageBox(hWnd, szPath, _T("提示"), MB_OK);

::RegCloseKey(hOpenKey);

BOOL bSuc = ::CreateProcess(szPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &procInfo);
if(bSuc)
{
::CloseHandle(procInfo.hThread);
::CloseHandle(procInfo.hProcess);
}
else
{
//MessageBox(hWnd, _T("启动程序失败"), _T("提示"), MB_OK);
}
}
}
break;

case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
PaintAll(hWnd, hdc);
EndPaint(hWnd, &ps);
}
break;

case WM_ERASEBKGND:
return TRUE;

case WM_TODAYCUSTOM_RECEIVEDSELECTION:
{
g_bSelected = TRUE;
//g_nSelectedItem = 1;
}
return TRUE;

case WM_TODAYCUSTOM_USERNAVIGATION:
//InvalidateRect(hWnd, NULL, FALSE);

//if (wParam == VK_UP)
// g_nSelectedItem--;
//if (wParam == VK_DOWN)
// g_nSelectedItem++;
//if (g_nSelectedItem < 0 || g_nSelectedItem >= MAX_ITEMS)
//{
// return FALSE; // go to the next plug-in
//}
//else
//{
// return FALSE; // stay in this plug-in
//}

break;

case WM_TODAYCUSTOM_ACTION:
// 1 判断是否在 有效区域,2 查询注册表, 得到程序路径, 3 启动程序
RECT rect;
POINT point;

//MessageBox(NULL, _T("WM_LBUTTONUP DllMain"), _T("DllMain"), MB_OK);

point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
::GetClientRect(hWnd, &rect);
if(PtInRect(&rect, point))
{
HKEY hOpenKey;
long lResult = 0;
DWORD iValueType = 0;
DWORD iLen = 0;
PROCESS_INFORMATION procInfo;

TCHAR szPath[MAX_PATH] = {'\0'};
LPCTSTR keyName = _T("Software\\Microsoft\\Today\\Items\\\"无线城市\""); //此注册表存放你应用程序的执行路径
LPCTSTR csAppPath = _T("AppPath");

//MessageBox(hWnd, _T("1"), _T("提示"), MB_OK);

lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 0, &hOpenKey);

ASSERT(lResult == ERROR_SUCCESS);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(hWnd, _T("读注册表失败"), _T("提示"), MB_OK);
break;
}

//MessageBox(hWnd, keyName, _T("提示"), MB_OK);

iLen = MAX_PATH * sizeof(TCHAR);
lResult = ::RegQueryValueEx(hOpenKey, csAppPath, 0, &iValueType, (BYTE*)szPath, &iLen);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(hWnd, _T("读注册表失败"), _T("提示"), MB_OK);
::RegCloseKey(hOpenKey);
break;
}

//MessageBox(hWnd, csAppPath, _T("提示"), MB_OK);
//MessageBox(hWnd, szPath, _T("提示"), MB_OK);

::RegCloseKey(hOpenKey);

BOOL bSuc = ::CreateProcess(szPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &procInfo);
if(bSuc)
{
::CloseHandle(procInfo.hThread);
::CloseHandle(procInfo.hProcess);
}
else
{
//MessageBox(hWnd, _T("启动程序失败"), _T("提示"), MB_OK);
}
}
break;
case WM_TODAYCUSTOM_LOSTSELECTION:
g_bSelected = FALSE;
break;
#if 0
default:

memset(debText,0,128);
memset(debTextTemp,0,128*sizeof(wchar_t));

sprintf(debText,"uimessage,wParam,lParam:%d,%d,%d\r\n",uimessage,wParam,lParam);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,debText,-1,debTextTemp,128/2);

//MessageBox(hWnd, debTextTemp, _T("提示"), MB_OK);
#endif
}
return DefWindowProc (hWnd, uimessage, wParam, lParam) ;
}

// export function

HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *ptli,HWND hwndParent)
{

if (ptli->fEnabled==0)
return NULL; //Return NULL if we are not enabled.
//g_hInst = ptli->hinstDLL;
//load the icon
//g_hIcon = (HICON)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1));

g_hWnd = CreateWindow(TEXT("无线城市"), TEXT("无线城市"), WS_VISIBLE | WS_CHILD,
0, 0, ::GetSystemMetrics(SM_CXSCREEN), PLUG_HEIGHT, hwndParent, NULL, g_hInst, NULL);

g_hWndParent = hwndParent;

// attach our winproc to the newly created window
SetWindowLong(g_hWnd, GWL_WNDPROC, (LONG) WndProc);

//display the window
ShowWindow (g_hWnd, SW_SHOWNORMAL);
UpdateWindow (g_hWnd) ;

return g_hWnd;
}

/*************************************************************************/
/* Create and register our window class for the today item */
/*************************************************************************/
INT InitilizeClasses()
{
WNDCLASS wc;
memset(&wc, 0, sizeof(wc));

wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.hInstance = g_hInst;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wc.lpszClassName = _T("无线城市");

//register our window
if(!RegisterClass(&wc))
{
return 0 ;
}
return 1;
}
jyzdtn 2010-03-05
  • 打赏
  • 举报
回复
引用 3 楼 musiclee 的回复:
估计你非法操作了吧!!!

#include "stdafx.h"
#include "Setup.h"

//WCHAR cFileDir[256] = {0};
#define MAX_PATH 256

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
//MessageBox(NULL, _T("setup dll DllMain"), _T("DllMain"), MB_OK);
return TRUE;
}

SETUP_API codeINSTALL_INIT
Install_Init(
HWND hwndParent,
BOOL fFirstCall, // is this the first time this function is being called?
BOOL fPreviouslyInstalled,
LPCTSTR pszInstallDir
)
{
HWND hWnd = FindWindow(NULL,_T("FCity.exe"));

//MessageBox(NULL, _T("setup dll Install_Init"), _T("Install_Init"), MB_OK);

if ( hWnd )
{
DestroyWindow( hWnd );
}

LPCWSTR path=L"\\Windows\\“开始”菜单\\日历.lnk";
DeleteFile(path);

return codeINSTALL_INIT_CONTINUE;
}


SETUP_API codeINSTALL_EXIT Install_Exit ( HWND hwndParent,
LPCTSTR pszInstallDir,
WORD cFailedDirs,
WORD cFailedFiles,
WORD cFailedRegKeys,
WORD cFailedRegVals,
WORD cFailedShortcuts)
{
TCHAR szPath[MAX_PATH] = {'\0'};
LPCTSTR csAppName = _T("FCity.exe");//程序名
LPCTSTR csAppPath = _T("AppPath");
TCHAR szAppPath[MAX_PATH] = {0};
LPCTSTR keyName = _T("Software\\Microsoft\\Today\\Items\\\"无线城市\"");
LPCTSTR csTodaykey = _T("Software\\Microsoft\\Today\\Items\\\"无线城市\"");
long lResult = 0;
HKEY hOpenKey = NULL;
DWORD dwOpenStyle = 0;
LPCTSTR csPlugName = _T("TodayAPPDll.dll");
DWORD iTemp = 0;
TCHAR szLinkPath[MAX_PATH] = {0};

//MessageBox(NULL, _T("setup dll Install_Exit"), _T("Install_Exit"), MB_OK);

if(cFailedDirs || cFailedFiles || cFailedRegKeys
|| cFailedRegVals || cFailedShortcuts)
goto Failed;

//MessageBox(NULL, _T("setup dll Install_Exit1"), _T("Install_Exit"), MB_OK);

//获取主程序安装路径
_tcscpy(szPath, pszInstallDir);
_tcscat(szPath, _T("\\"));
_tcscat(szPath, csAppName);

//设置主程序快捷方式的执行路径
_tcscpy(szAppPath, _T("\""));
_tcscat(szAppPath, szPath);
_tcscat(szAppPath, _T("\""));

//MessageBox(NULL, _T("setup dll Install_Exit2"), _T("Install_Exit"), MB_OK);

//将主程序安装路径写入注册表
lResult = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, _T(""), REG_OPTION_NON_VOLATILE,
0,NULL,&hOpenKey, &dwOpenStyle);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(NULL, _T("RegCreateKeyEx ERROR"), _T("Install_Exit"), MB_OK);
goto Success;
}

//MessageBox(NULL, _T("setup dll Install_Exit3"), _T("Install_Exit"), MB_OK);

::RegSetValueEx(hOpenKey, csAppPath, 0, REG_SZ, (BYTE*)&szPath, sizeof(TCHAR) * _tcslen(szPath));
::RegCloseKey(hOpenKey);

//MessageBox(NULL, _T("setup dll Install_Exit4"), _T("Install_Exit"), MB_OK);

memset(szPath, 0x00, sizeof(TCHAR) * MAX_PATH);
_tcscpy(szPath, pszInstallDir);
_tcscat(szPath, _T("\\"));
_tcscat(szPath, csPlugName);
CopyFile(szPath, _T("\\Windows\\TodayAPPDll.dll"), TRUE);
//MessageBox(NULL, szPath, _T("Install_Exit"), MB_OK);
//MessageBox(NULL, _T("setup dll Install_Exit5"), _T("Install_Exit"), MB_OK);

// 安装 “今日插件”
hOpenKey = NULL;
lResult = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, csTodaykey, 0, _T(""), REG_OPTION_NON_VOLATILE,
0, NULL, &hOpenKey, &dwOpenStyle);
if(lResult != ERROR_SUCCESS)
{
//MessageBox(NULL, _T("RegCreateKeyEx1 ERROR"), _T("Install_Exit"), MB_OK);
goto Success;//如果读写注册表失败, 放弃安装 “今日插件”
}

//MessageBox(NULL, _T("setup dll Install_Exit6"), _T("Install_Exit"), MB_OK);

// 注册插件
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));
iTemp = 2;
::RegSetValueEx(hOpenKey, _T("Selectability"), 0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
iTemp = 9;
::RegSetValueEx(hOpenKey, _T("Order"), 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\\TodayAPPDll.dll"), sizeof(TCHAR) * _tcslen(szPath));

//MessageBox(NULL, _T("setup dll Install_Exit7"), _T("Install_Exit"), MB_OK);

// 发送系统消息
SendMessage(HWND_BROADCAST, WM_WININICHANGE, (WPARAM)0xF2, 0);
::RegCloseKey(hOpenKey);

//MessageBox(NULL, _T("setup dll Install_Exit8"), _T("Install_Exit"), MB_OK);

//创建程序快捷方式
if(SHGetSpecialFolderPath(NULL, szLinkPath, CSIDL_STARTUP,FALSE))
{
_tcscat(szLinkPath, _T("\\"));
_tcscat(szLinkPath, _T("无线城市.lnk"));

//MessageBox(NULL, szLinkPath, _T("提示"), MB_OK);

if(SHCreateShortcut(szLinkPath, szAppPath) == FALSE)
{
//MessageBox(NULL, _T("安装快捷方式失败"), _T("提示"), MB_OK);
}
}
else
{
//MessageBox(NULL, _T("获取系统文件路径失败"), _T("提示"), MB_OK);
}

Success:
//MessageBox(NULL, _T("Success"), _T("Success"), MB_OK);
return codeINSTALL_EXIT_DONE;

Failed:
//MessageBox(NULL, _T("Failed"), _T("Failed"), MB_OK);
return codeINSTALL_EXIT_UNINSTALL;
}

SETUP_API codeUNINSTALL_INIT Uninstall_Init( HWND hwndParent, LPCTSTR pszInstallDir )
{
HWND hWnd = FindWindow(NULL,_T("FCity.exe"));

//MessageBox(NULL, _T("setup dll Uninstall_Init"), _T("Uninstall_Init"), MB_OK);

if(hWnd)
{
DestroyWindow( hWnd );
return codeUNINSTALL_INIT_CONTINUE;
}

int iReply = IDYES;
HKEY hOpenKey = NULL;
long lResult = 0;
DWORD dwOpenStyle = 0;

LPCTSTR csTodaykey = _T("Software\\Microsoft\\Today\\Items");

//如果你愿意, 你可以加警告信息
/*
iReply = MessageBox(hwndparent,
_T("确定卸载程序?"),
_T("警告"),
MB_YESNO | MB_ICONQUESTION);

if (IDNO == iReply)
{
return codeUNINSTALL_INIT_CANCEL;
}
*/

lResult = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, csTodaykey, 0, _T(""), 0,0,NULL,&hOpenKey, &dwOpenStyle);
if(lResult == ERROR_SUCCESS)
{
lResult = ::RegDeleteKey(hOpenKey, _T("\"无线城市\""));
::SendMessage(HWND_BROADCAST, WM_WININICHANGE, (WPARAM)0xF2, 0);
::Sleep(1500); // 等待系统释放插件dll
::RegCloseKey(hOpenKey);
::DeleteFile(_T("\\Windows\\TodayAPPDll.dll"));
}

//return value
return codeUNINSTALL_INIT_CONTINUE;
}

SETUP_API codeUNINSTALL_EXIT
Uninstall_Exit( HWND hwndParent)
{
//MessageBox(NULL, _T("setup dll Uninstall_Exit"), _T("Uninstall_Exit"), MB_OK);
// 删除快捷方式
TCHAR szFile[MAX_PATH] = {0};
TCHAR szPath[MAX_PATH] = {0};
TCHAR szFindFile[MAX_PATH] = {0};
WIN32_FIND_DATA findData;
HANDLE fileHandle;
if(SHGetSpecialFolderPath(NULL, szFindFile, CSIDL_STARTUP, FALSE))
{
_tcscpy(szPath, szFindFile);
_tcscat(szFindFile, _T("\\无线城市*.lnk"));
}
else
return codeUNINSTALL_EXIT_DONE;

fileHandle = ::FindFirstFile(szFindFile, &findData);
if (fileHandle == INVALID_HANDLE_VALUE)
{

}
else
{
do
{
memset(szFile, 0x00, sizeof(TCHAR) * MAX_PATH);
_stprintf(szFile,_T("%s\\%s"), szPath, findData.cFileName);
::DeleteFile(szFile);
}while (FindNextFile(fileHandle, &findData) != 0);
FindClose(fileHandle);
}

return codeUNINSTALL_EXIT_DONE;
}
musiclee 2010-03-05
  • 打赏
  • 举报
回复
估计你非法操作了吧!!!
dubiousway 2010-03-05
  • 打赏
  • 举报
回复
具体错误还能详细些吗?
joey_zoy 2010-03-05
  • 打赏
  • 举报
回复
贴点具体的代码啊。。。啥都没有,怎么分析

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧