无论如何要创建一个绘制到位图(作为虚拟显示表面)而不是实际显示表面上的HWND吗?
看起来这样的事情会很有用,因为你可以用一个你无法用DC做的窗口,例如创建子窗口(可能包含控件)或通过GetDCEx获取DC。
答案 0 :(得分:0)
似乎我的问题的简单答案是否定的!
答案 1 :(得分:-1)
您必须处理WM_PAINT
并在那里绘制图像。
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC, memDc;
PAINTSTRUCT Ps;
HBITMAP bmpBackground;
BITMAP bm;
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_PAINT:
hDC = BeginPaint(hwnd, &Ps);
// Load the bitmap from the resource
bmpBackground = LoadBitmap(hInst, "your_background_image");
// Create a memory device compatible with the above DC variable
memDc = CreateCompatibleDC(hDC);
// Select the new bitmap
SelectObject(memDc, bmpBackground);
GetObject(bmpBackground, sizeof(bm), &bm);
// Copy the bits from the memory DC into the current dc
BitBlt(hDC, 10, 10,bm.bmWidth, bm.bmHeight, memDc, 0, 0, SRCCOPY);
// Restore the old bitmap
DeleteDC(memDc);
DeleteObject(bmpBackground);
EndPaint(hwnd, &Ps);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}