首页 新闻 会员 周边

【求助】WinMo今日插件的贴图问题

0
悬赏园豆:20 [已解决问题] 解决于 2012-09-02 00:02

在WM_LBUTTONDOWN后,进入了贴图环节,但是贴图失败,是不是太快了,还是怎么样注意下?

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

extern "C" _declspec(dllexport) HWND    APIENTRY    InitializeCustomItem(TODAYLISTITEM, HWND);
extern "C" _declspec(dllexport)    DWORD    APIENTRY    CustomOptionsDlgProc();
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "HelloWorldTodayPlug.h"

HINSTANCE    g_hInst;
HWND        g_hWndParent;

#define IMAGE_BK L"\\TodayLauncher\\bkg.bmp"

#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:
        {
            TODAYDRAWWATERMARKINFO tbi;
            tbi.hwnd    = hWnd;
            tbi.hdc        = (HDC)wParam;
            GetClientRect(hWnd, &tbi.rc);
            SendMessage(GetParent(hWnd), TODAYM_DRAWWATERMARK, 0, (LPARAM)&tbi);
            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);
            return 0;
        }
        break;

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

            FocusSel = 0;

            PAINTSTRUCT pts;
            HDC dc    = BeginPaint(hWnd, &pts);
            SetBkMode(dc, TRANSPARENT);
            DrawUI(dc, FocusSel);
            EndPaint(hWnd, &pts);
            
            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;
            }

            PAINTSTRUCT pts;
            HDC dc    = BeginPaint(hWnd, &pts);
            SetBkMode(dc, TRANSPARENT);
            DrawUI(dc, FocusSel);
            EndPaint(hWnd, &pts);

            return TRUE;
        }

    default:
        return    DefWindowProc( 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 );
}

HWND    APIENTRY    InitializeCustomItem(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);
    
    return hWnd;
}


DWORD    APIENTRY    CustomOptionsDlgProc()
{
    return 0;
}

//if(!CreateProcess(szCmdExe,szCmdLine,NULL,NULL,FALSE,0,NULL,NULL,NULL,&pi))   
//{   
//    MessageBox(NULL, TEXT("开启百合失败"), TEXT("系统提示"), MB_OK);             
//} 

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 = SHLoadImageFile(IMAGE_BK);
    HDC mdc;
    mdc = CreateCompatibleDC(NULL);
    SelectObject(mdc, hBitmap);
    BitBlt(MemDC, 0, 0, Length*5, Length, mdc, 0, 0, SRCCOPY);
    DeleteObject(hBitmap);
    DeleteDC(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
    {
        MessageBox(NULL, _T("555"), _T("555"), MB_OKCANCEL);
        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(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);
}
望云风的主页 望云风 | 初学一级 | 园豆:186
提问于:2012-08-31 23:32
< >
分享
最佳答案
0

看到了InvalidateRect原來WM_PAINT是這樣用的,呵呵,懂了,現在問題解決了。

在按鍵消息加上這個就行了。

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

 

case WM_ERASEBKGND:
{
DrawUI((HDC)wParam, FocusSel);
return TRUE;
}
break;

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

DrawUI(dc, FocusSel);

EndPaint(hWnd, &pt);

return 0;
}
break;

哈哈

望云风 | 初学一级 |园豆:186 | 2012-09-01 11:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册