目前共有4篇帖子。 內容轉換:不轉換▼
 
點擊 回復
160 3
WM_DRAWITEM双缓冲示例
一派護法 十九級
1樓 發表于:2016-2-6 10:27
case WM_DRAWITEM:
        {
            LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
            if (lpDis->CtlID == IDC_STATIC1)
            {
                HDC hdcMem = CreateCompatibleDC(lpDis->hDC);
                HBITMAP hbmp = CreateCompatibleBitmap(lpDis->hDC, lpDis->rcItem.right - lpDis->rcItem.left, lpDis->rcItem.bottom - lpDis->rcItem.top);
                SelectObject(hdcMem, hbmp);
                HPEN hpen = CreatePen(PS_SOLID, 1, COL_848400);
                SelectObject(hdcMem, hpen);
                MoveToEx(hdcMem, 10, 10, NULL);
                LineTo(hdcMem, 120, 120);
                BitBlt(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.top, lpDis->rcItem.right - lpDis->rcItem.left, lpDis->rcItem.bottom - lpDis->rcItem.top, hdcMem, 0, 0, SRCCOPY);
                DeleteDC(hdcMem);
                DeleteObject(hbmp);
                DeleteObject(hpen);
            }
        }
        break;
    }
一派護法 十九級
2樓 發表于:2016-2-6 18:03
创建了compatible DC后一定要创建一个compatible bitmap并选定,否则这个hdc由于没有对应目标设备而无法输出绘制的图形。
一派護法 十九級
3樓 發表于:2016-2-6 18:05
此外,默认创建的bitmap中所有像素都是黑色,因为此时内存中全是0。
一派護法 十九級
4樓 發表于:2016-2-6 20:47
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        ShowCursor(TRUE);
        break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            switch (wmId)
            {
            case IDCANCEL:
            case IDOK:
                ShowCursor(FALSE);
                EndDialog(hDlg, wmId);
                break;
            }
        }
        break;
    case WM_DRAWITEM:
        {
            LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
            if (lpDis->CtlID == IDC_STATIC1)
            {
                HDC hdcMem = CreateCompatibleDC(lpDis->hDC);
                HBITMAP hbmp = CreateCompatibleBitmap(lpDis->hDC, lpDis->rcItem.right - lpDis->rcItem.left, lpDis->rcItem.bottom - lpDis->rcItem.top);
                SelectObject(hdcMem, hbmp);
                HPEN hpen = CreatePen(PS_SOLID, 1, COL_848400);
                SelectObject(hdcMem, hpen);
                MoveToEx(hdcMem, 10, 10, NULL);
                LineTo(hdcMem, 120, 120);
                BitBlt(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.top, lpDis->rcItem.right - lpDis->rcItem.left, lpDis->rcItem.bottom - lpDis->rcItem.top, hdcMem, 0, 0, SRCCOPY);
                DeleteDC(hdcMem);
                DeleteObject(hbmp);
                DeleteObject(hpen);
            }
        }
        break;
    }
    return FALSE;
}

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:160 回複數:3
評論數: ?
作者: 巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2016-2-6 20:47
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。