SetWindowRgn 函数的参数解释如下:
hWnd
[in] Handle to the window whose window region is to be set.
窗口的句柄
hRgn
[in] Handle to a region. The function sets the window region of the window to this region.
If hRgn is NULL, the function sets the window region to NULL.
指向的区域.函数起作用后将把窗体变成这个区域的形状.
如果这个参数是空值,窗体区域也会被设置成空值,也就是什么也看不到.
bRedraw
[in] Specifies whether the system redraws the window after setting the window region. If bRedraw is TRUE, the system does so; otherwise, it does not.
Typically, you set bRedraw to TRUE if the window is visible.
这个参数是用于设置 当函数起作用后,窗体是不是该重绘一次. true 则重绘,false 则相反.
如果你的窗体是可见的,通常建议设置为 true.
BOOL C不规则矩形Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
CRect rect;
GetDlgItem(IDC_BTN_RGN)->GetWindowRect(&rect);
//GetClientRect(&rect);
m_rgn.CreateRoundRectRgn(rect.left,rect.top,rect.right,rect.bottom,
50,50);
SetWindowRgn(m_rgn,TRUE);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
实现个简单地圆角矩形:
对话框的其他部分并没有显示出来。至于原因,我之前就说过了