为什么使用SetWindowRgn函数后窗口样式变化很大?

赤勇玄心行天道 2019-03-25 10:33:05
没有使用SetWindowRgn函数时:


已经使用SetWindowRgn函数后:


可以看出来窗口样式变化很大,边框变得特别粗,样式也变成了经典windows样式,关键是我还发现窗口的大小有变大了一点点,这是为什么呢?有什么办法可以避免呢?

代码如下:

hWnd2 = CreateWindowExW(0, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, nullptr, nullptr, hInstance, nullptr);

hRgn = CreateRoundRectRgn(0, 0, 500, 500, 50, 50);
SetWindowRgn(hWnd2, hRgn, FALSE );
CloseHandle(hRgn);

ShowWindow(hWnd2, nCmdShow);
UpdateWindow(hWnd2);
...全文
344 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2019-04-07
  • 打赏
  • 举报
回复
设置窗口区域会禁用视觉风格 https://docs.microsoft.com/zh-cn/windows/desktop/Controls/cookbook-overview#ignore_top_level 可以用UpdateLayeredWindow做局部透明。参考https://docs.microsoft.com/en-us/previous-versions/ms997507(v=msdn.10)
schlafenhamster 2019-03-26
  • 打赏
  • 举报
回复
是不是 aero 主题 引起 ?
schlafenhamster 2019-03-25
  • 打赏
  • 举报
回复
参考
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
int R=50;// 2R=100
HRGN hRgn = CreateRoundRectRgn(0, 0, 460, 200, R, R);
MoveWindow(CRect(100, 100, 460+2*R, 200+2*R),TRUE);// 窗口大 2R !!!
SetWindowRgn(hRgn,TRUE);//
// CDialog::OnOK();
}
注意 窗口 大小 与 rgn 大小
  • 打赏
  • 举报
回复
引用 1 楼 schlafenhamster 的回复:
After a successful call to SetWindowRgn, the operating system owns the region specified by the region handle hRgn. The operating system does not make a copy of the region, so do not make any further function calls with this region handle, and do not close this region handle.

我注释掉了CloseHandle也是一样的
schlafenhamster 2019-03-25
  • 打赏
  • 举报
回复
例子
void CTransDlgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
static BOOL sw=FALSE;
if(!sw)
{
sw=TRUE;
CRect rcWin;
GetWindowRect(&rcWin);
//
CRect rcClt;
GetClientRect(&rcClt);
// rcClt.DeflateRect(20,20);
ClientToScreen(rcClt);
rcClt.OffsetRect(-rcWin.left,-rcWin.top);
//
int offX=rcClt.left;
int offY=rcClt.top;
rcWin.OffsetRect(-rcWin.left,-rcWin.top);
//
CRgn tmp;
tmp.CreateRectRgnIndirect(&rcClt);
// client - ctrls
RgnSubtractCtrls(tmp,offX,offY);
// finally
CRgn rgn;
rgn.CreateRectRgnIndirect(&rcWin);
rgn.CombineRgn(&rgn,&tmp,RGN_DIFF);
DeleteObject(tmp);
//
SetWindowRgn(rgn,TRUE);
m_Trans.SetWindowText("不透明");
}
else
{
sw=FALSE;
SetWindowRgn(0,TRUE);
m_Trans.SetWindowText("透明");
}
}
schlafenhamster 2019-03-25
  • 打赏
  • 举报
回复
After a successful call to SetWindowRgn, the operating system owns the region specified by the region handle hRgn. The operating system does not make a copy of the region, so do not make any further function calls with this region handle, and do not close this region handle.

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧