This lesson is mainly about the message map and some of the functions of painting, structure, message map so that we do not have to tube WindowProc function calls, as long as the class inside the addition of messages can be a certain response to the operation. Make MFC simple.
These functions of painting are more, then you can refer this video
Here are some of the message mapping functions in DrawView.cpp, adding the member variables in the CDrawView declaration (. h file) To manually add the variable (video can be added directly in the Class View), and then the constructor to assign the value.
1 voidCdrawview::onlbuttondown (UINT nflags, CPoint point)2 {3 //TODO: Add Message Handler code and/or call default values here4 //MessageBox ("View clicked");5M_ptorigin = M_ptold =Point ;6 //m_ptorigin = point;7M_bdraw =TRUE;8 Cview::onlbuttondown (nflags, point);9 }Ten One voidCdrawview::onlbuttonup (UINT nflags, CPoint point) A { - //TODO: Add Message Handler code and/or call default values here - /*HDC hdc; the hdc =:: GetDC (m_hwnd); - Movetoex (hdc, m_ptorigin.x, M_PTORIGIN.Y, NULL); - LineTo (hdc, Point.x, POINT.Y); - :: ReleaseDC (M_hwnd, HDC);*/ + /*CDC *PDC = GetDC (); - Pdc->moveto (m_ptorigin); + Pdc->lineto (point); A ReleaseDC (PDC);*/ at //CCLIENTDC DC (this); - /*cclientdc DC (GetParent ()); - DC. MoveTo (m_ptorigin); - DC. LineTo (point);*/ - - /*CWINDOWDC DC (this); in CWINDOWDC DC (GetParent ()); - CWINDOWDC DC (GetDesktopWindow ()); to DC. MoveTo (m_ptorigin); + DC. LineTo (point);*/ - the /*CPen Pen (ps_dash, 1, RGB (0, 255, 0)); * CCLIENTDC DC (this); $ CPen *poldpen = DC. SelectObject (&pen);Panax Notoginseng DC. MoveTo (m_ptorigin); - DC. LineTo (point); the DC. SelectObject (Poldpen);*/ + A /*CBrush Brush (RGB (255, 0, 0)); the CCLIENTDC DC (this); + DC. FillRect (CRect (M_ptorigin, point), &brush);*/ - $ /*CBitmap bitmap; $ bitmap. Loadbitmapa (IDB_BITMAP1); - CBrush Brush (&bitmap);*/ - the /*CCLIENTDC DC (this); - //DC. FillRect (CRect (M_ptorigin, point), &brush);Wuyi CBrush *pbrush = Cbrush::fromhandle ((hbrush) Getstockobject (Null_brush)); the CBrush *poldbrush = DC. SelectObject (Pbrush); - DC. Rectangle (CRect (M_ptorigin, point)); Wu DC. SelectObject (Poldbrush);*/ - AboutM_bdraw =FALSE; $ - Cview::onlbuttonup (nflags, point); - } - A voidCdrawview::onmousemove (UINT nflags, CPoint point) + { the //TODO: Add Message Handler code and/or call default values here - $CCLIENTDC DC ( This); theCPen Pen (Ps_solid,1, RGB (255,0,0)); theCPen *poldpen = DC. SelectObject (&pen); the if(M_bdraw = =TRUE) the { - //DC. SetROP2 (R2_mergenotpen); in DC. SetROP2 (r2_black); the DC. MoveTo (m_ptorigin); the //DC. LineTo (point); About DC. LineTo (m_ptold); the //DC. MoveTo (m_ptorigin); the DC. MoveTo (m_ptold); the DC. LineTo (point); + //m_ptorigin = point; -M_ptold =Point ; the }Bayi DC. SelectObject (Poldpen); the Cview::onmousemove (nflags, point); the}View Code
MFC: Xinxin Sun Tutorial 4 notes