 |
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; }
|