MFC Graphic Processing and mfc Graphic rendering programming Experiment

Source: Internet
Author: User

MFC Graphic Processing and mfc Graphic rendering programming Experiment

Introduction to the MFC drawing function

Create a Dialog based MFC project. Open the Dialog main interface under the Resource view.

Add the Picture control. Add the CStatic control variable m_pic to the control.

 

Create a function paint () for plotting in the defined Picture control;

The function is defined as follows. One Parameter type is CDC and the other is CRect.

void project_name::paint(CDC *pDC, CRect &rect) { }

Function call method:

CRect rect; m_pic.GetClientRect(&rect);paint(m_pic.GetDC(),rect);

Specific content of the paint function:

Void project_name: paint (CDC * pCD, CRect & rect) {// draw a rectangle or an ellipse:
// The parameters of the Rectangle and the elliptic are similar to Ellipse (x1, y1, x2, y2), Rectangle (x1, y1, x2, y2)
// (X1, y1) indicates the coordinates in the upper left corner of the area to be drawn, and (x2, y2) indicates the coordinates in the upper right corner.
CBrush Brush; // create a paint Brush; CBrush * PreBrush; // create an old paint Brush pointer to remove it // Method 1: Brush. createSolidBrush (RGB (, 0); // sets the paint Brush color and attributes PreBrush = pDC-> SelectObject (& Brush ); // select to use this image brush pDC-> Rectangle (CRect); // use this image brush to draw a Rectangle pDC-> SelectObject (PreBrush ); // discard the paint Brush being used and use the previous Brush. deleteObject (); Method 2: Brush. createSolidBrush (RGB (255, 100,100); pDC-> BeginPath (); pDC-> Ellipse (,); pDC-> EndPath (); pDC-> SelectObject (& Brush); pDC-> FillPath (); // after painting, draw a line after Dyeing: CPen Pen; CPen PrePen; Pen. createPen (PS_SOLID, 1, RGB (0,255, 0); // create a paint brush PrePen = pDC-> SelectObject (& Pen); pDC-> MoveTo (x0, y0 ); // move the paint brush to the specified coordinate pDC-> LineTo (x1, y1); // draw from the current coordinate to the specified coordinate pDC-> SelectObject (& Pen); // destroy the Pen. delectObject ();
// If the paint brush or paint brush is not destroyed, adding the paint brush or paint brush again will be mixed together}

 

Clear the content drawn by the control:

GetDlgItem(m_pic)->ShowWindow(FALSE); GetDlgItem(m_pic)->ShowWindow(TRUE); 

 

Relevant knowledge is still to be supplemented ....

Related Article

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.