Home > Software engineering >  Why use SetWindowRgn function after the window style changed?
Why use SetWindowRgn function after the window style changed?

Time:09-19

Don't use SetWindowRgn function:


After already use SetWindowRgn function:


Can see out the window style has changed a lot, border becomes particularly coarse, style also becomes a classical Windows style, the key is I also found that the size of the window changes a little bit, is this why? Is there any way to avoid it?

The code is as follows:
 
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);
The CloseHandle (hRgn);

ShowWindow (hWnd2, nCmdShow);
UpdateWindow (hWnd2);

CodePudding user response:

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.

CodePudding user response:

Example
Void CTransDlgDlg: : OnButton1 ()
{
//TODO: Add your the control notification handler code here
The static BOOL sw=FALSE;
if(! Sw)
{
Sw=TRUE;
CRect rcWin;
GetWindowRect (& amp; RcWin);
//
CRect rcClt;
GetClientRect (& amp; RcClt);
//rcClt. DeflateRect (20, 20);
The 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 (& amp; RcClt);
//client - CTRLS
RgnSubtractCtrls (TMP, offX offY);
//finally
CRgn RGN.
RGN. CreateRectRgnIndirect (& amp; RcWin);
Rgn.Com bineRgn (& amp; RGN, & amp; TMP, RGN_DIFF);
DeleteObject (TMP);
//
SetWindowRgn (RGN, TRUE);
M_Trans. SetWindowText (" opaque ");
}
The else
{
Sw=FALSE;
SetWindowRgn (0, TRUE);
M_Trans. SetWindowText (" transparent ");
}
}

CodePudding user response:

reference 1st floor schlafenhamster response:
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.

I commented out the CloseHandle is the same

CodePudding user response:

Refer to
Void CAboutDlg: : OnOK ()
{
//TODO: Add extra validation here
Int R=50;//2 r=100
HRGN HRGN=CreateRoundRectRgn (0, 0, 460, 200, R, R);
MoveWindow (CRect (100, 100, 460 + 2 * R, 200 + 2 * R), TRUE);// window 2 r!!!!!!
SetWindowRgn (hRgn, TRUE);//
//CDialog: : OnOK ();
}
Note that the window size and RGN size

CodePudding user response:

Aero theme caused?

CodePudding user response:

Settings window area will disable visual style
https://docs.microsoft.com/zh-cn/windows/desktop/Controls/cookbook-overview#ignore_top_level

Can do partial transparency in UpdateLayeredWindow, reference https://docs.microsoft.com/en-us/previous-versions/ms997507 (v=MSDN. 10)
  • Related