Hello MFC Small Note

Source: Internet
Author: User

In the Hello window example, add: 1. When the left mouse button is pressed, a line is drawn from the upper left of the window to the right; 2. When the mouse Zuo, draw a line from the lower left of the window to the right.

//Hello.h
1 classCMyApp: PublicCWinApp2 {3 Public:4 VirtualBOOL InitInstance ();5 };6 7 classCMainWindow: PublicCFrameWnd8 {9 Public:Ten CMainWindow (); Oneafx_msgvoidOnLButtonDown (UINT nflags, CPoint point); A - protected: -afx_msgvoidOnPaint (); theafx_msgvoidOnLButtonUp (UINT nflags, CPoint point); - Declare_message_map () -};
//hello.cpp
1#include <afxwin.h>2#include"Hello.h"3 4 CMyApp myApp;5 6 /////////////////////////////////////////////////////////////////////////7 //CMyApp member functions8 9 BOOL cmyapp::initinstance ()Ten { Onem_pMainWnd =NewCMainWindow; A //M_pmainwnd->showwindow (m_ncmdshow); -M_pmainwnd->ShowWindow (SW_SHOWNORMAL); -M_pmainwnd->UpdateWindow (); the returnTRUE; - } - - ///////////////////////////////////////////////////////////////////////// + //CMainWindow message map and member functions - + Begin_message_map (CMainWindow, CFrameWnd) A On_wm_paint () at On_wm_lbuttondown () - On_wm_lbuttonup () - End_message_map () - - Cmainwindow::cmainwindow () - { inCreate (NULL, _t ("The Hello application"), Ws_overlappedwindow,crect (0,0,720, the)); - } to + voidCmainwindow::onpaint () - { theCRect Rect ( -, -, -, -); *GetClientRect (&rect); $ Panax NotoginsengCPAINTDC DC ( This); - thedc. DrawText (_t ("Hello, MFC"), -1, &Rect, +Dt_singleline | Dt_center |dt_vcenter); A } the + voidCmainwindow::onlbuttondown (UINT nflags, CPoint point) - { $ CRect rect; $GetClientRect (&rect); - -CCLIENTDC DC ( This); the DC. MoveTo (Rect.left, rect.top); - DC. LineTo (Rect.right, rect.bottom);Wuyi the /*DC. MoveTo (Rect.left, rect.bottom); - DC. LineTo (Rect.right, rect.top);*/ Wu } - About voidCmainwindow::onlbuttonup (UINT nflags, CPoint point) $ { - CRect rect; -GetClientRect (&rect); - ACCLIENTDC DC ( This); + DC. MoveTo (Rect.left, rect.bottom); the DC. LineTo (Rect.right, rect.top); -}

Originally can only show the Hello MFC window, after the extension, the newly added two diagonal lines are not displayed anyway, and then think of the need for message mapping, as if the message map to the corresponding message processing function, although the principle is not very clear, but add up can show the effect.

Hello MFC Small Note

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.