VC 利用SetWindowRgn实现程序窗口的圆角多角矩形
2012-07-26 15:26
411 查看
下面是实现程序窗口圆角多角矩形的三种方法,但效果都比较差。只是简单的将边角裁
剪,从边框和标题栏上都可以看出来。不过可以通过这三个函数来学习下
SetWindowRgn()及创建一个HRGN的不同方法。
方法1
方法2
方法3
再对SetWindowRgn()进行下说明
1. The coordinates of a window's window region are relative to the upper-left corner of the window, not the client area of the window.
窗口的RGN的坐标体系不是屏幕坐标,而是以窗口的左上角开始的。
2. After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy ofthe region. Thus, you should not make any further
function calls withthis region handle. In particular, do not delete this region handle. Thesystem deletes the region handle when it no longer needed.
设置SetWindowRgn()后,不用再管HRGN句柄了,系统会接管它。
调用方法
win32程序可以在WM_CREATET和WM_INITDIALOG消息处理中调用。
MFC程序可以OnInitDialog()中调用。
如:SetWindowEllispeFrame1(hwnd, 50, 50)
或SetWindowEllispeFrame1(this->GetSafeHwnd(), 50, 50);
剪,从边框和标题栏上都可以看出来。不过可以通过这三个函数来学习下
SetWindowRgn()及创建一个HRGN的不同方法。
方法1
void SetWindowEllispeFrame1(HWND hwnd, int nWidthEllipse, int nHeightEllipse) { HRGN hRgn; RECT rect; GetWindowRect(hwnd, &rect); hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, nWidthEllipse, nHeightEllipse); SetWindowRgn(hwnd, hRgn, TRUE); }
方法2
void SetWindowEllispeFrame2(HWND hwnd, int nWidthEllipse, int nHeightEllipse) { HRGN hRgn; RECT rect; HDC hdc, hdcMem; hdc = GetDC(hwnd); hdcMem = CreateCompatibleDC(hdc); ReleaseDC(hwnd, hdc); GetWindowRect(hwnd, &rect); // 画一个圆角矩形。 BeginPath(hdcMem); RoundRect(hdcMem, 0, 0, rect.right - rect.left, rect.bottom - rect.top, nWidthEllipse, nHeightEllipse); EndPath(hdcMem); hRgn = PathToRegion(hdcMem); // 最后把路径转换为区域。 SetWindowRgn(hwnd, hRgn, TRUE); }
方法3
void SetWindowEllispeFrame3(HWND hwnd, int nWidthEllipse, int nHeightEllipse) { HRGN hRgn; RECT rect; int nHeight,nWidth; GetWindowRect(hwnd, &rect); nHeight = rect.bottom - rect.top; // 计算高度 nWidth = rect.right - rect.left; // 计算宽度 POINT point[8] = { {0, nHeightEllipse}, // left-left-top {nWidthEllipse, 0}, // left-top-left {nWidth - nWidthEllipse, 0}, {nWidth, nHeightEllipse}, // right-top {nWidth, nHeight - nHeightEllipse}, // right-bottom-right {nWidth - nWidthEllipse, nHeight}, // right-bottom-bottom {nWidthEllipse, nHeight}, // left-bottom {0, nHeight - nHeightEllipse} }; hRgn = CreatePolygonRgn(point, 8, WINDING); SetWindowRgn(hwnd,hRgn,TRUE); }
再对SetWindowRgn()进行下说明
1. The coordinates of a window's window region are relative to the upper-left corner of the window, not the client area of the window.
窗口的RGN的坐标体系不是屏幕坐标,而是以窗口的左上角开始的。
2. After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy ofthe region. Thus, you should not make any further
function calls withthis region handle. In particular, do not delete this region handle. Thesystem deletes the region handle when it no longer needed.
设置SetWindowRgn()后,不用再管HRGN句柄了,系统会接管它。
调用方法
win32程序可以在WM_CREATET和WM_INITDIALOG消息处理中调用。
MFC程序可以OnInitDialog()中调用。
如:SetWindowEllispeFrame1(hwnd, 50, 50)
或SetWindowEllispeFrame1(this->GetSafeHwnd(), 50, 50);
相关文章推荐
- VC 利用SetWindowRgn实现程序窗口的圆角多角矩形
- VC 利用SetWindowRgn实现程序窗口的圆角多角矩形 .
- VC 利用SetWindowRgn实现程序窗口的圆角多角矩形 .
- vc循序渐进实现仿QQ界面(一):圆角矩形与双缓冲贴图窗口
- VC实现圆角矩形窗口
- 利用VC++编程实现程序自动启动
- 利用VC++编程实现程序自动启动(转)
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- 利用VC++编程实现程序自动启动
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- 在VC中实现全屏窗口程序
- 关于MFC实现圆角矩形窗口
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- VC 制作系统托盘程序实现将窗口最小化到系统托
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息