/////////////////////////////////////////////////////////////// // mfcwin.cpp - small windows demo program // // // // Creates a movable, resizable window with title and // // system menu, but no contents, this time with the // // Microsoft Foundation Classes (MFC) // // // // Jim Fawcett, 27 July 1998, modified 15 Sep 1998 // // Reference: Developing Professional Applications for // // Windows 95 and NT using MFC, Marshall Brain // // and Lance Lovett, Prentice Hall, 1997 // // Chap 1-5 for basics, Chap 11 for drawing and text out // /////////////////////////////////////////////////////////////// #include //----< class implementing window >---------------------------- class CBasicWin : public CFrameWnd { public: CBasicWin() { Create(NULL, "CSE691 - Basic MFC Window"); } afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnPaint(); DECLARE_MESSAGE_MAP() // note: no semicolon - this is a macro }; //----< message handler for left mouse button click >---------- void CBasicWin::OnLButtonDown(UINT nFlags, CPoint point) { MessageBox( "Left mouse button pressed", NULL, MB_OK); } //----< message handler painting client area of window >------- void CBasicWin::OnPaint() { CString msg1("CSE691 SW Modeling & Analysis"); CString msg2("Hello World from MFC"); CRect rect; GetClientRect(rect); CPaintDC dc(this); dc.DrawText(msg2,rect,DT_CENTER | DT_SINGLELINE | DT_VCENTER); dc.TextOut(30,30,msg1); dc.MoveTo(25,50); dc.LineTo(260,50); } //----< message map >------------------------------------------ BEGIN_MESSAGE_MAP(CBasicWin, CFrameWnd) ON_WM_LBUTTONDOWN() ON_WM_PAINT() END_MESSAGE_MAP() // //----< class with message loop >------------------------------ class CBasicApp : public CWinApp { public: virtual BOOL InitInstance(); }; //----< create window and diplay it >--------------------------- BOOL CBasicApp::InitInstance() { m_pMainWnd = new CBasicWin(); m_pMainWnd -> MoveWindow(100,100,400,300,TRUE); m_pMainWnd -> ShowWindow(m_nCmdShow); m_pMainWnd -> UpdateWindow(); return TRUE; } //----< global applications object >--------------------------- CBasicApp basicApp;