window 调整大小时位图消失
Bitmap disappears when window is resized
我有一个简单的 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 是该特定标签页的句柄
当我打开选项卡时图像显示,但如果我调整 window 的大小,或者如果我最小化并重新打开 GUI,图像将会消失
我必须转到另一个选项卡并返回该选项卡才能取回图像
我在 WM_PAINT 消息中做错了什么吗?
您还必须对 WM_SIZE 消息做出反应。调整 window 的大小不会释放绘制消息。
在 WM_SIZE 只需拨打:
InvalidateRect(hwnd,&rect,TRUE);
UpdateWindow(hwnd);
rect 是具有当前 window 大小的矩形。 Invalidate 标记要重绘的矩形,UpdateWindow 确保它立即重绘。
我有一个简单的 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 是该特定标签页的句柄
当我打开选项卡时图像显示,但如果我调整 window 的大小,或者如果我最小化并重新打开 GUI,图像将会消失
我必须转到另一个选项卡并返回该选项卡才能取回图像
我在 WM_PAINT 消息中做错了什么吗?
您还必须对 WM_SIZE 消息做出反应。调整 window 的大小不会释放绘制消息。
在 WM_SIZE 只需拨打:
InvalidateRect(hwnd,&rect,TRUE);
UpdateWindow(hwnd);
rect 是具有当前 window 大小的矩形。 Invalidate 标记要重绘的矩形,UpdateWindow 确保它立即重绘。