C++ WinAPI Conflict between SetLayeredWindowAttributes and BitBlt

廉价感情. 提交于 2020-01-17 12:37:30

问题


I have created a custom window using DWM. I painted the caption by using PaintCustomCaption() ,which is an example from MSDN. It worked properly until I added SetLayeredWindowAttributes().

Window before adding

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

After adding

I tried changing RGB values but it was still black except RGB(0,0,0).

I wonder if BitBlt() works properly.

Edited:

The reason I added SetLayeredWindowAttributes is to solve this problem

Do you have other ways to paint the caption?

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;
}

回答1:


If you keep the window border, you don't need to paint the caption yourself unless you want to add something to your caption.

That is, handle WM_NCCALCSIZE and WM_NCHITTEST normally.




回答2:


First, use RGB(200,201,202) as the transparency key instead of RGB(0,0,1).

You may try other values but it is the best one so far I have tested.

Then, add this after HBITMAP hbmOld=(HBITMAP)SelectObject(hdcPaint,hbm); in PaintCustomCaption():

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


来源:https://stackoverflow.com/questions/32564457/c-winapi-conflict-between-setlayeredwindowattributes-and-bitblt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!