armg
asked on
Dynamic Menu Options
In the following snippet of code I have created a new popup menu and added a couple menu items with AppendMenu(). The popup is then appended to the menu associated with the CFrame window of the program. The function is called from the OnCreate() message handler of the CView class of the
program:
int CSigmaView::OnCreate( LPCREATESTRUCT lpCreateStruct)
{
...
cCWReport.SetRptMenu(this- >GetParent ());
...
return 0;
}
When the program runs, the top-level menu option "Reports" is apparently created OK because it appears at the end of the menu bar for the frame window. When the new menu option is selected it becomes highlighted and the program appears to hang for a few seconds as though it is processing something but the popup menu never appears and no error is generated. I have used standard command ID's for the added menu items just for the sake of creating and testing the function.
void CSigmaReport::SetRptMenu(C Wnd *pWnd)
{
CMenu *pMenu;
CMenu cPopup;
cPopup.CreatePopupMenu();
cPopup.AppendMenu(MF_ENABL ED|MF_STRI NG, ID_FILE_OPEN, "&Bay Details");
cPopup.AppendMenu(MF_ENABL ED|MF_STRI NG, ID_FILE_OPEN, "&Vac Details");
pMenu = pWnd->GetMenu();
pMenu->AppendMenu(MF_POPUP |MF_STRING , (UINT)cPopup.GetSafeHmenu( ),
"&Reports");
pWnd->DrawMenuBar();
};
program:
int CSigmaView::OnCreate( LPCREATESTRUCT lpCreateStruct)
{
...
cCWReport.SetRptMenu(this-
...
return 0;
}
When the program runs, the top-level menu option "Reports" is apparently created OK because it appears at the end of the menu bar for the frame window. When the new menu option is selected it becomes highlighted and the program appears to hang for a few seconds as though it is processing something but the popup menu never appears and no error is generated. I have used standard command ID's for the added menu items just for the sake of creating and testing the function.
void CSigmaReport::SetRptMenu(C
{
CMenu *pMenu;
CMenu cPopup;
cPopup.CreatePopupMenu();
cPopup.AppendMenu(MF_ENABL
cPopup.AppendMenu(MF_ENABL
pMenu = pWnd->GetMenu();
pMenu->AppendMenu(MF_POPUP
"&Reports");
pWnd->DrawMenuBar();
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.