2015-09-14 55 views
-1

我使用DWM創建了一個自定義窗口。我使用PaintCustomCaption()來繪製標題,這是MSDN的一個例子。它工作正常,直到我加入SetLayeredWindowAttributes()。加入SetLayeredWindowAttributes和BitBlt之間的C++ WinAPI衝突

SetLayeredWindowAttributes(hWnd,RGB(0,0,1),0,LWA_COLORKEY); 

enter image description here

加入

enter image description here

前後

窗口,我試着改變RGB值,但它仍然是黑色的,除了RGB(0,0,0)。

不知道BitBlt()是否正常工作。

編輯:

我加入SetLayeredWindowAttributes的原因是爲了解決這個問題

enter image description here

你有其他的方法來畫的標題嗎?

case WM_ACTIVATE: { 
    DwmExtendFrameIntoClientArea(hWnd,&m); // m={-1,-1,-1,-1}; 
    break; 
} 
case WM_INITDIALOG: { 
    SetWindowPos(hWnd,NULL,0,0,500,500,SWP_NOMOVE|SWP_FRAMECHANGED); 
    SetWindowLongPtr(hWnd,GWL_STYLE,WS_VISIBLE|WS_OVERLAPPEDWINDOW); 
    SetWindowLongPtr(hWnd,GWL_EXSTYLE,WS_EX_LAYERED); 
    SetLayeredWindowAttributes(hWnd,RGB(0,0,1),0,LWA_COLORKEY); 
    RedrawWindow(hWnd,NULL,NULL,RDW_INVALIDATE|RDW_ERASE); 
    return true; 
} 
case WM_PAINT: { 
    hdc=BeginPaint(hWnd,&paintstruct); 
    PaintCustomCaption(hWnd,hdc) 
    EndPaint(hWnd,&paintstruct); 
    break; 
} 
+0

是的,'BitBlt'「正常工作」。你的代碼中有一個錯誤。 –

+0

是否有任何可能的原因導致錯誤? –

+0

你是否考慮過這個備註:'請注意,一旦SetLayeredWindowAttributes被調用了一個分層窗口,後續的UpdateLayeredWindow調用將會失敗,直到分層樣式位被清除並再次設置。 – KuramaYoko

回答

0

首先,使用RGB(200,201,202)作爲透明度鍵而不是RGB(0,0,1)。

您可以嘗試其他值,但它是目前爲止我測試過的最好的一個。

然後,HBITMAP hbmOld=(HBITMAP)SelectObject(hdcPaint,hbm);PaintCustomCaption()補充一點:如果你保持窗口邊框

FillRect(hdcPaint,&rcClient,CreateSolidBrush(RGB(200,201,202))); 
+0

我一直在尋找解決方案很長一段時間,我終於找到了! –

1

,除非你想的東西添加到您的標題,你不需要自己畫的標題。

也就是說,正常處理WM_NCCALCSIZEWM_NCHITTEST