哭求:我代码里的/case WM_SIZE:到底有什么问题,程序运行貌似正常,但提示一个shell32.exe错
[复制链接]
哭求:我代码里的/case WM_SIZE:到底有什么问题,程序运行貌似正常,但提示一个shell32.exe错
case WM_SIZE:
//MoveWindow(g_hWnd, 40, 40, 100, 100, TRUE);
完整代码
#include "stdafx.h"
#include
#include
#include
#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 = 2*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;
//case WM_SIZE:
//MoveWindow(g_hWnd, 40, 40, 100, 100, TRUE);
#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);
// MoveWindow(g_hWnd, 40, 40, 100, 100, TRUE);
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;
}