我有一個簡單的圖形用戶界面,當我在某個選項卡上時應該顯示圖像。我有選項卡進程內的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_PAINT的開頭添加了一個斷點,並通過消息代碼。它看起來像所有的變量正在被初始化和正確使用。 我注意到當我重新打開GUI時,它只會對WM_PAINT進行一次調用......但是當我切換標籤時,它會對WM_PAINT進行兩次調用。消息是否應該發送兩次? – Heather
有時會發生這種情況,因爲父標籤窗口和子窗口重疊。嘗試將標記'WS_CLIPCHILDREN'添加到父標籤控件。或者在標籤頁上試試'WS_CLIPSIBLINGS'。 – rodrigo