Table of Contents        Previous topic       Next topic       

Using the Custom AppWizard or Project Template->Tutorial - Creating an Extension with the AppWizard->Finalising Support for your Dialog Box->Closing and Reopening your Dialog Box->Handling the Menu Message

We need to create a function that will open the dialog box in response to the menu command.  This involved handling the Windows message generated when the menu item is selected.  However, Class Wizard takes care of setting up the message handler when you carry out the following.

Open file ExtensionState.cpp and right mouse click on the document.  Select ID_VIEWMESSAGEBOX as the Object ID and select COMMAND in the messages list. Click on Add Function to create function OnViewmessagebox.  Click on Edit Code to edit this function and add the lines in bold:

void CExtensionState::OnViewmessagebox()
 // TODO: Add your command handler code here
 if (g_pMessageDlg == NULL)
   g_pMessageDlg = new CMessageDlg();

We need to add our menu item to the Virtual Workshops View menu. We will also add a seperator so that our menu item stands apart from the rest.  To do this, edit function AddViewMenuItems() adding the bold lines:

void CExtensionState::AddViewMenuItems(CMenu* pMenu)
 // add view menu items here using a form such as:
 // UINT nFlags = m_pWatchDog == NULL ? MF_STRING : MF_STRING | MF_GRAYED;
 // VERIFY(pMenu->AppendMenu(nFlags, ID_WATCHDOG, "&WatchDog"));
 UINT nFlags = g_pMessageDlg == NULL ? MF_STRING : MF_STRING | MF_GRAYED;
 VERIFY(pMenu->AppendMenu(nFlags, ID_VIEWMESSAGEBOX, "&View Message Box"));