VC创建圆角窗体

来源:互联网 发布:淘宝的淘气值是干嘛的 编辑:程序博客网 时间:2024/05/19 23:15

有时候根据具体需求,我们可能要改变窗口的形状。使用API函数SetWindowRgn可以改变一个窗体的可见范围。

使用API函数CreateRoundRectRgn()函数可以创建一个圆角矩形区域。


图片ID为:IDB_BACKBMP

BOOL CDemoDlg::OnInitDialog(){CDialog::OnInitDialog();// Set the icon for this dialog.  The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization herem_back.LoadBitmap(IDB_BACKBMP);CRgn rgn;rgn.CreateRoundRectRgn(3,3,700,650,20,20);SetWindowRgn(rgn,TRUE);return TRUE;  // return TRUE  unless you set the focus to a control}void CDemoDlg::OnPaint() {CPaintDC dc(this); // device context for paintingCDC picDC;picDC.CreateCompatibleDC (&dc);CBitmap *pOldBmp;pOldBmp = picDC.SelectObject (&m_back);BITMAP bm;m_back.GetBitmap(&bm);dc.BitBlt (0,0,bm.bmWidth ,bm.bmHeight,&picDC,0,0,SRCCOPY);dc.SelectObject(pOldBmp); }

void OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: 在此处添加消息处理程序代码 CRgn MyRgn; CRect rect; GetWindowRect(&rect); rect -= rect.TopLeft(); MyRgn.CreateRoundRectRgn(rect.left,rect.top, rect.right, rect.bottom, 3,3); SetWindowRgn(MyRgn,TRUE); } 



0 0