/* HelloMFC.cpp First example Windows / NT for CS 585 Mike Barnes 10/27/98 */ # include # include "HelloMFC.h" // set value for button resource # define IDC_BUTTON 100 CHelloMFC_App helloApp; // create an application framework // Must redefine InitInstance to initialize application BOOL CHelloMFC_App :: InitInstance () { m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } // message map for event routing BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd) ON_WM_CREATE () ON_BN_CLICKED (IDC_BUTTON, OnButton) END_MESSAGE_MAP () // constructor for MainWindow CMainWindow :: CMainWindow() { CRect rect = new CRect(0,0,200, 123); // Window Style WS_OVERLAPPEDWINDOW overlaps others, // has a minimize and maximize button, border, and system menu Create (NULL, "Hello MFC", WS_OVERLAPPEDWINDOW, rect); } // message handlers // MainWindow exists now create child controls int CMainWindow :: OnCreate(LPCREATESTRUCT lpcs) { CRect rect; GetClientRect(&rect); // get size of MainWindow // create pushbutton as a control member m_ctlButtonW.Create("Hello MFC", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rect, this, IDC_BUTTON); return 0; } // handle button press events void CMainWindow :: OnButton() { static int toggle = 0; toggle++; // uncomment the next line to see MessageBox afx use // MessageBox ("Button was pressed"); if (toggle % 2) m_ctlButtonW.SetWindowText("press me again !"); else m_ctlButtonW.SetWindowText("Hello CS585"); }