我有一个简单的GUI,当我在某个选项卡上时应该显示图像。我在选项卡过程中有WM_PAINT消息,如下所示
case WM_PAINT:
{
PAINTSTRUCT psLOGO;
RECT rcLOGO;
HDC hdcLOGO;
//Prepares for painting window
hdcLOGO = BeginPaint(hwndMonitor, &psLOGO);
//Retrieves the coordinates of the windows client area
GetClientRect(hwndMonitor, &rcLOGO);
//creates a copy of the memory device context
HDC hdcDoubleLOGO = CreateCompatibleDC(hdcLOGO);
HBITMAP Logo = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); //Get a bitmap of the picture to be updated
HBITMAP bmOldLOGO = (HBITMAP)SelectObject(hdcDoubleLOGO, Logo); //Get a handle to the image being replaced
BitBlt(hdcLOGO, 0, 0, rcLOGO.right, rcLOGO.bottom, hdcDoubleLOGO, 0, 0, SRCCOPY); //Bit block transfer of the bitmap color data
SelectObject(hdcDoubleLOGO, bmOldLOGO);
DeleteDC(hdcDoubleLOGO);
EndPaint(hwndMonitor, &psLOGO);
DeleteObject(Logo);
break;
}
hwndMonitor是该特定选项卡页面的句柄
当我打开选项卡时显示该图像,但是如果我调整窗口大小,或者最小化并重新打开GUI,该图像将消失。
我必须转到另一个选项卡,然后再回到该选项卡,以获取图像
我在WM_PAINT消息中做错了吗?
最佳答案
您还必须对WM_SIZE消息做出反应。调整窗口大小不会释放绘制消息。
在WM_SIZE上,只需调用:
InvalidateRect(hwnd,&rect,TRUE);
UpdateWindow(hwnd);
rect是具有当前窗口大小的矩形。 Invalidate标记矩形以进行重新绘制,UpdateWindow确保立即重新绘制矩形。
关于c - 调整窗口大小时,位图消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29684150/