MFC实现窗体透明

MFC创建透明窗体

1、设置窗体属性为LayeredWindow,并设置窗体为无边框窗体。

//设置窗体为LayeredWindow

LONG para = GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE);

para |= WS_EX_LAYERED;

SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, para);

 

2、设置窗体透明色

//设置窗体透明色为RGB(255,0,0)

SetLayeredWindowAttributes(RGB(255, 0, 0), 255, LWA_COLORKEY);

3、在OnPaint事件中绘制窗体背景,背景色为透明色

CPaintDC dc(this);

RECT rect;

GetClientRect(&rect);

dc.FillSolidRect(&rect, RGB(255, 0, 0));



备注:如果不设置为无边框窗体,将只实现显示透明,不能实现透明操作。

猜你喜欢

转载自blog.csdn.net/Zhangchen9091/article/details/51292527
今日推荐