#include #include "resource.h" class CWelcomeWindow : public CFrameWnd { public: CWelcomeWindow(); ~CWelcomeWindow(); afx_msg void OnExit(); afx_msg void SetGraphics(); private: CStatic *m_pGreeting; DECLARE_MESSAGE_MAP() }; // ------------------------------------------------------------------------------------- afx_msg void CWelcomeWindow::OnExit() { UINT answer; answer = MessageBox("Do you want to quit?", "Confirm Exit", MB_YESNO | MB_ICONQUESTION); if (answer == IDYES) SendMessage(WM_CLOSE); } // ------------------------------------------------------------------------------------- /* // FindMenuItem() will find a menu item string from the specified // popup menu and returns its position (0-based) in the specified // popup menu. It returns -1 if no such menu item string is found. int FindMenuItem(CMenu* Menu, LPCTSTR MenuString) { int count = Menu->GetMenuItemCount(); CString str; for (int i = 0; i < count; i++) { if (Menu->GetMenuString(i, str, MF_BYPOSITION) && (strcmp(str, MenuString) == 0)) return i; } return -1; } */ // ------------------------------------------------------------------------------------- afx_msg void CWelcomeWindow::SetGraphics() { // static UINT state = MF_UNCHECKED; // int pos; // CMenu* pMenu; // CMenu* pSubMenu; // pMenu = this->GetMenu(); // pos = FindMenuItem(pMenu, "Settings"); // if (pos == -1) // return; // pSubMenu = pMenu->GetSubMenu(pos); // pos = FindMenuItem(pSubMenu, "Graphics"); // if (pos == -1) // return; // state = pSubMenu->CheckMenuItem(pos, MF_BYPOSITION | state); CMenu* pMenu; pMenu = this->GetMenu(); UINT state; state = pMenu->GetMenuState(ID_SETTINGS_GRAPHICS, MF_BYCOMMAND); if (state == MF_CHECKED) state = MF_UNCHECKED; else state = MF_CHECKED; pMenu->CheckMenuItem(ID_SETTINGS_GRAPHICS, MF_BYCOMMAND | state); } // ------------------------------------------------------------------------------------- BEGIN_MESSAGE_MAP(CWelcomeWindow, CFrameWnd) ON_COMMAND(ID_CLOSE, OnExit) ON_COMMAND(ID_SETTINGS_GRAPHICS, SetGraphics) END_MESSAGE_MAP() // ------------------------------------------------------------------------------------- CWelcomeWindow::CWelcomeWindow() { this->Create(NULL, "Welcome", WS_OVERLAPPEDWINDOW, CRect(100,100,300,300), NULL, "MAIN_MENU"); m_pGreeting = new CStatic; m_pGreeting->Create("Welcome to Visual C++ with MFC!", WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER, CRect(40,50,160,100), this); } // ------------------------------------------------------------------------------------- CWelcomeWindow::~CWelcomeWindow() { delete m_pGreeting; } // ------------------------------------------------------------------------------------- class CWelcomeApp : public CWinApp { public: BOOL InitInstance() { m_pMainWnd = new CWelcomeWindow(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } }; CWelcomeApp welcomeApp;