VC uses setjavaswrgn to realize the rounded corner and multi-angle rectangle of the program window

Source: Internet
Author: User
The following are three methods for implementing the multi-angle rectangle of the program window rounded corner, but the effect is relatively poor. Simply cutting corners

Cut, you can see from the border and the title bar. However, you can use these three functions to learn

Setjavaswrgn () and create an hrgn.

Method 1

void SetWindowEllipseFrame1(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);}

Method 2

Void setwindowellipseframe2 (hwnd, int nwidthellipse, int partition) {hrgn; rect; 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); // draw a rounded rectangle. Endpath (hdcmem); hrgn = pathtoregion (hdcmem); // Finally, convert the path to a region. Setjavaswrgn (hwnd, hrgn, true );}

Method 3

Void setwindowellipseframe3 (hwnd, int nwidthellipse, int nheightellipse) {hrgn; rect; int nheight, nwidth; getwindowrect (hwnd, & rect); nheight = rect. bottom-rect. top; // calculate the nwidth = rect. right-rect. left; // calculate the width of point [8] = {0, nheightellipse}, // 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 {nwidthellipse, nheight}, // left-bottom {0, nheight-nheightellipse }}; hrgn = createpolygonrgn (point, 8, winding); set1_wrgn (hwnd, hrgn, true );}

Next, describe setjavaswrgn ().

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.

The RGN Coordinate System of the window is not the screen coordinate, but starts from the upper left corner of the window.

2. after a successful call to setmediawrgn, the system owns the region specified by the region handle hrgn. the system does not make a copy ofthe region. thus, you shoshould not make any further function CILS withthis region handle. in particle, do not delete this region handle. thesystem deletes the region handle when it no longer needed.

After setdomainwrgn () is set successfully, the system will take over the hrgn handle.

 

Call method Win32 can be called in wm_createt and wm_initdialog message processing. The MFC program can be called in oninitdialog. For example:

Setwindowellispeframe1 (hwnd, 50, 50)

Or setwindowellispeframe1 (this-> getsafehwnd (), 50, 50 );

 

I would like to express my thanks for your reference to the code on the Internet.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.