读书人

存有正常放找不到原因

发布时间: 2013-01-05 15:20:39 作者: rapoo

【求助】存有正常放,找不到原因
是一WinMo今日快速插件。
有五,目前只能。
入后存用24,50次后存用32,不知道哪有放乾。


// HelloWorldTodayPlug.cpp : 定义 DLL 应用程序的入口点。
//

extern "C" _declspec(dllexport) HWNDAPIENTRYInitializeCustomItem(TODAYLISTITEM, HWND);
extern "C" _declspec(dllexport)DWORDAPIENTRYCustomOptionsDlgProc();
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "HelloWorldTodayPlug.h"

HINSTANCEg_hInst;
HWNDg_hWndParent;

#define IMAGE_1 L"\\TodayLauncher\\1.bmp"
#define IMAGE_2 L"\\TodayLauncher\\2.bmp"
#define IMAGE_3 L"\\TodayLauncher\\3.bmp"
#define IMAGE_4 L"\\TodayLauncher\\4.bmp"
#define IMAGE_5 L"\\TodayLauncher\\5.bmp"

#define IMAGE_AT1 L"\\TodayLauncher\\~1.bmp"
#define IMAGE_AT2 L"\\TodayLauncher\\~2.bmp"
#define IMAGE_AT3 L"\\TodayLauncher\\~3.bmp"
#define IMAGE_AT4 L"\\TodayLauncher\\~4.bmp"
#define IMAGE_AT5 L"\\TodayLauncher\\~5.bmp"

int FocusSel;
void DrawUI(HDC hDC, int type);
void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr);

int Length;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
FocusSel = 0;
Length = GetSystemMetrics(SM_CXSCREEN) / 5;
}
break;
case WM_ERASEBKGND:
{
DrawUI((HDC)wParam, FocusSel);
return TRUE;
}
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
if (!((TODAYLISTITEM*)wParam)->cyp)
{
((TODAYLISTITEM*)wParam)->cyp = GetSystemMetrics(SM_CXSCREEN)/5;
return TRUE;
}

break;

case WM_TODAYCUSTOM_CLEARCACHE:
{
}
break;

case WM_PAINT:
{
PAINTSTRUCT pt;
HDC dc= BeginPaint(hWnd, &pt);
SetBkMode(dc, TRANSPARENT);

DrawUI(dc, FocusSel);

EndPaint(hWnd, &pt);
ReleaseDC(hWnd, dc);

return 0;
}
break;

case WM_LBUTTONUP:
{
POINT pt;
pt.x = LOWORD(lParam);

FocusSel = 0;
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);

if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*4)
{
//MessageBox(NULL, _T("5"), _T("Ready"), MB_OK);
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*3)
{
//MessageBox(NULL, _T("4"), _T("Ready"), MB_OK);
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*2)
{
//MessageBox(NULL, _T("3"), _T("Ready"), MB_OK);
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*1)
{
//MessageBox(NULL, _T("2"), _T("Ready"), MB_OK);


}
else
{
//MessageBox(NULL, _T("1"), _T("Ready"), MB_OK);
}

return TRUE;
}

case WM_LBUTTONDOWN:
{
POINT pt;
pt.x = LOWORD(lParam);

if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*4)
{
FocusSel = 5;
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*3)
{
FocusSel = 4;
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*2)
{
FocusSel = 3;
}
else if (pt.x > GetSystemMetrics(SM_CXSCREEN)/5*1)
{
FocusSel = 2;
}
else
{
FocusSel = 1;
}

InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);

return TRUE;
}

default:
returnDefWindowProc( hWnd, msg, wParam, lParam );
}
return 0;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc = { 0L,
MsgProc,
0L,
0L,
hInstance,
NULL,
NULL,
NULL,
NULL,
TEXT("TodayLauncherPlug")
};
return RegisterClass( &wc );
}

HWNDAPIENTRYInitializeCustomItem(TODAYLISTITEM *ptli, HWND hWndParent)
{
if (!ptli->fEnabled)
{
MessageBox(0, TEXT("DISABLED!"), NULL, 0);
return NULL;
}
g_hInst= ptli->hinstDLL;
g_hWndParent= hWndParent;
MyRegisterClass(g_hInst);

HWND hWnd = CreateWindow(TEXT("TodayLauncherPlug"),
TEXT("TodayLauncherWindow"),
WS_VISIBLE | WS_CHILD,
0,
0,
GetSystemMetrics (SM_CXSCREEN),
GetSystemMetrics (SM_CXSCREEN)/5,
hWndParent,
NULL,
g_hInst,
NULL);
if (!hWnd)
MessageBox(0, TEXT("MyRegisterClass Fail!"), NULL, 0);

ShowWindow (hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

return hWnd;
}


DWORDAPIENTRYCustomOptionsDlgProc()
{
return 0;
}

//if(!CreateProcess(szCmdExe,szCmdLine,NULL,NULL,FALSE,0,NULL,NULL,NULL,&pi))
//{
//
//}

void DrawUI(HDC hDC, int type)
{
HDC MemDC = NULL;
HBITMAP MemBitmap = NULL;
MemDC = CreateCompatibleDC(NULL);
MemBitmap = CreateCompatibleBitmap(hDC, Length*5, Length);

HBITMAP hOldBitMap = (HBITMAP)SelectObject(MemDC, MemBitmap);
FillSolidRect(MemDC, 0, 0, Length*5, Length, RGB(0, 255, 0));

//
HBITMAP hBitmap;
HDC mdc;

if (type != 1)
{
hBitmap = SHLoadImageFile(IMAGE_1);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, 0, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);


DeleteDC(mdc);
}
else
{
hBitmap = SHLoadImageFile(IMAGE_AT1);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, 0, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}

if (type != 2)
{
hBitmap = SHLoadImageFile(IMAGE_2);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}
else
{
hBitmap = SHLoadImageFile(IMAGE_AT2);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}

if (type != 3)
{
hBitmap = SHLoadImageFile(IMAGE_3);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*2, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}
else
{
hBitmap = SHLoadImageFile(IMAGE_AT3);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*2, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}

if (type != 4)
{
hBitmap = SHLoadImageFile(IMAGE_4);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*3, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}
else
{
hBitmap = SHLoadImageFile(IMAGE_AT4);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*3, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}

if (type != 5)
{
hBitmap = SHLoadImageFile(IMAGE_5);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*4, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}
else
{
hBitmap = SHLoadImageFile(IMAGE_AT5);
mdc = CreateCompatibleDC(NULL);
SelectObject(mdc, hBitmap);
BitBlt(MemDC, Length*4, 0, Length, Length, mdc, 0, 0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(mdc);
}

BitBlt(hDC, 0, 0, Length*5, Length, MemDC, 0, 0, SRCCOPY);

//清理
DeleteObject(hOldBitMap);
DeleteObject(MemBitmap);
DeleteDC(MemDC);
}

void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
{
RECT rct;
rct.left = x;
rct.top = y;
rct.right = x + cx;
rct.bottom = y + cy;

SetBkColor(hDC, clr);
ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rct, NULL, 0, NULL);
}



[解决办法]
很典型的错误,就如楼上所说,应该将SelectObject(mdc, hBitmap)的返回值重新选入,才能完成删除。



[解决办法]

引用:
很典型的错误,就如楼上所说,应该将SelectObject(mdc, hBitmap)的返回值重新选入,才能完成删除。


应该是这个原因

读书人网 >WinCE

热点推荐