Create a rounded corner Dialog

Source: Internet
Author: User

Sometimes we need a dialog box with rounded corners to achieve this effect, which generally involves two steps. Step 1: crop the right angle of the original dialog box, Step 2: draws a rounded corner for the dialog box or adds a rounded corner image to the dialog box.

Step 1: implement it in the oncreate function,CodeNot many.

IntCtestdialog: oncreate (maid ){If(Cdialog: oncreate (lpcreatestruct) =-1)Return-1; Hrgn; rect;: getwindowrect (hwnd,&Rect); hrgn= Createroundrectrgn (0,0, Rect. Right-rect. Left +1, Rect. Bottom-rect. Top +1,5,5);: Setjavaswrgn (hwnd, hrgn, true );}

 

If the dialog box supports resize, copy the code in the onsize function.

Step 2: Because the redrawing of the rounded corner part belongs to the non-customer area of the dialog box, we need to respond to the wm_ncpaint message. In the message response function, we can paste the rounded corner image or draw a circle.

 Void ctestdialog: onncpaint () {cwindowdc DC (  This  ); Crect rcwindow; crect rcclient;  This -> Getclientrect (rcclient );  This -> Clienttoscreen (rcclient );  This -> Getwindowrect (rcwindow); cpoint point = Rcwindow. topleft (); rcclient. offsetrect ( - Point); rcwindow. offsetrect ( - Point );  Int Required wwidth = Rcwindow. Width ();  Int Windowheight = Rcwindow. Height (); HDC hmemdc = : Createcompatibledc (DC. m_hdc); hbitmap hbmp = : Createcompatiblebitmap (DC. m_hdc, windowwidth, windowheight);: SelectObject (hmemdc, hbmp); graphics (hmemdc); graphics. Clear (color (  255 , 255 ,255 , 255  ); Graphics. setsmoothingmode (smoothingmodehighquality );  //  Todo: Use the drawimage function of GDI + to paste the rounded corner image, or use the roundrect function to draw the circle cursor for the dialog box.  # If 0/* use drawimage to draw a rounded corner image */ Imageattributes IA; IA. setwrapmode (wrapmodetileflipxy );
Graphic. drawimage (pimg_ltframe ,..........); # Endif
# If 0/* use roundrect to draw the rounded corner line */ Roundrect (hmemdc, rcwindow. Left, rcwindow. Top, rcwindow. Right, RC. Bottom, 5 , 5 ); # Endif DC. intersectcliprect (rcwindow); DC. excludecliprect (rcclient );
: Bitblt (DC. m_hdc, 0 , 0 , Expires wwidth, expires wheight, hmemdc, 0 , 0 , Srccopy);: deletedc (hmemdc );
: Deleteobject (hbmp );}

To achieve the desired effect, you may also need to respond to the two messages wm_ncactive and wm_notify. The two message response functions implement the same functions as the onncpaint function.

there is also an important message wm_nccalcsize. In this message response function, the size of the non-customer zone in the dialog box is recalculated, in this function, the lpncsp-> rgrc [0] of the lpnccalcsize_params type parameter lpncsp sets the size of the customer zone. The height of the customer zone is reduced by an hour, and the height of the non-customer zone is increased, because the total height of the dialog box is fixed. After the rounded rectangle is created, the customer area may be large or small. In this case, you need to respond to the message and adjust the size of the non-customer area in the message response function.

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.