gpt4 book ai didi

c++ - 将位图加载到窗口

转载 作者:太空宇宙 更新时间:2023-11-04 02:43:37 27 4
gpt4 key购买 nike

我想在我的应用程序中将位图加载到窗口,我将使用 GDI 将位图绘制到窗口。我是否应该在处理 WM_PAINT 消息时也绘制位图,以便位图保留在窗口上?

最佳答案

是的,你应该像这样在 WM_PAINTWM_ERASEBKGND 处理程序中绘制你的位图:

        switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &Ps);

// Load the bitmap from the resource
bmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_MY_COOL_PIC));
// Create a memory device compatible with the above DC variable
MemDC = CreateCompatibleDC(hDC);
// Select the new bitmap
HBITMAP hOldBmp = SelectObject(MemDC, bmp);

// Copy the bits from the memory DC into the current dc
BitBlt(hDC, 10, 10, 450, 400, MemDC, 0, 0, SRCCOPY);

// Restore the old bitmap
SelectObject(MemDC, hOldBmp);
DeleteObject(bmp);

DeleteDC(MemDC);
EndPaint(hWnd, &Ps);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}

关于c++ - 将位图加载到窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29471759/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com