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 ....