C ++ WinAPI SetLayeredWindowAttributes和BitBlt之间的冲突 [英] C++ WinAPI Conflict between SetLayeredWindowAttributes and BitBlt

查看:607
本文介绍了C ++ WinAPI SetLayeredWindowAttributes和BitBlt之间的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DWM创建了一个自定义窗口。我使用



添加完毕后





您有其他方法绘制标题吗?

  case WM_ACTIVATE:{
DwmExtendFrameIntoClientArea(hWnd,& m); // m = { - 1,-1,-1,-1};
break;
}
case WM_INITDIALOG:{
SetWindowPos(hWnd,NULL,0,0500,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;
}


解决方案

)作为透明度键而不是RGB(0,0,1)。



您可以尝试其他值,但它是迄今为止我测试过的最好的。 p>

然后,将 HBITMAP hbmOld =(HBITMAP)SelectObject(hdcPaint,hbm); PaintCustomCaption()

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


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

解决方案

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

这篇关于C ++ WinAPI SetLayeredWindowAttributes和BitBlt之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆