The realization method of VC Creating Fillet Dialog _c language

Source: Internet
Author: User

This article describes the VC to create rounded corners dialog implementation method. Share to everyone for your reference, specific as follows:

We sometimes need rounded corners of the dialog box, to achieve this effect, generally include two-step work, the first step: the original dialog box to cut the right angle, the second step: for the dialog box to draw a rounded corner or a dialog box to paste a rounded corner of the picture.

The first step: we implement in the OnCreate function, the amount of code is not much.

int ctestdialog::oncreate (lpcreatestruct lpcreatestruct)
{
    if (cdialog::oncreate (lpcreatestruct) = = 1)
      return-1;
    Hrgn Hrgn;
    RECT RECT
    :: GetWindowRect (hwnd, &rect);
    Hrgn = createroundrectrgn (0, 0, Rect.right-rect.left + 1, rect.bottom-rect.top + 1, 5,5);
    :: SetWindowRgn (hwnd, HRG n, TRUE);


If the dialog box also supports resize, then you need to copy the above code in the OnSize function.

Step two: Because the redrawing of the fillet part belongs to the non-client area of the dialog box, we need to respond to the wm_ncpaint message, implement the function of the fillet picture in the message response function, or draw the rounded corner line.

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 windowwidth = Rcwindow.width ();
  int windowheight = Rcwindow.height ();
  HDC HMEMDC =:: CreateCompatibleDC (DC.M_HDC);
  Hbitmap hbmp =:: CreateCompatibleBitmap (DC.M_HDC, WindowWidth, windowheight);
  :: SelectObject (HMEMDC, hbmp);
  Graphics Graphics (HMEMDC); Graphics.
  Clear (Color (255, 255, 255, 255)); Graphics.
  Setsmoothingmode (smoothingmodehighquality);
  TODO: Use GDI + 's DrawImage function to paste fillet pictures, or use the RoundRect function to draw rounded corners for dialog boxes #if 0/* Use DrawImage to draw fillet picture * * ImageAttributes IA; Ia.
  Setwrapmode (WRAPMODETILEFLIPXY); Graphic.
  DrawImage (Pimg_ltframe,..........);
  #endif #if 0/* Use RoundRect to draw fillet 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, windowwidth, WindowHeight, HMEMDC, 0, 0, srccopy);
  ::D Eletedc (HMEMDC);
::D eleteobject (hbmp);

 }

In order to achieve the desired effect, you may also respond to wm_ncactive and wm_notify two messages, and implement the same functions as onncpaint functions in these two message response functions.

There is also an important message wm_nccalcsize, in this message response function, is to recalculate the size of the dialog box's non client area, the Lpnccalcsize_params type parameter in this function LPNCSP lpncsp->rgrc[0] The size of the client area is set and the height of the client area increases when the height of the customer area decreases, because the total height of the dialog box is fixed. After creating a rounded rectangle, the client area area may appear large or small, and you need to respond to the message and adjust the size of the non-customer area in this message response function.

I hope this article describes the VC program to help.

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.