沒有使用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);
uj5u.com熱心網友回復:
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.uj5u.com熱心網友回復:
例子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("透明");
}
}
uj5u.com熱心網友回復:
我注釋掉了CloseHandle也是一樣的
uj5u.com熱心網友回復:
參考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 大小
uj5u.com熱心網友回復:
是不是 aero 主題 引起 ?uj5u.com熱心網友回復:
設定視窗區域會禁用視覺風格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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/51510.html
標籤:界面
上一篇:VC++6.0 和 2008 等版本,是可以MFC的,那么最新版本,用的是什么
下一篇:求助在一張235*1480cm的布上剪裁出30個長方形,盡可能少浪費布;(大的長方形可以由小的長方形組合而成(A+B=C))30個長方形如圖:
