CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 1999
    Location
    TVM, Kerala, India
    Posts
    210

    Question Displaying main menu as a popup menu???

    Dear All,

    I have a main menu in SDI application.. IDR_MAINFRAME.. Which contain File, Edit, View and Help menu. I want to display this main menu by right clicking on the mouse. When I used following code, It is displaying small bar on left side. I couldnt see File, Edit etc menu...

    void CMenuView::OnContextMenu(CWnd* pWnd, CPoint point)
    {
    // TODO: Add your message handler code here
    CMenu* menu_bar = AfxGetMainWnd()->GetMenu();

    file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x,
    point.y, this);

    }


    How can I display the main menu as such as a popup menu??

    Thanks in advance,
    Kareem.
    mail : abkareem@yahoo.com

  2. #2
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Displaying main menu as a popup menu???

    If you want to display the main menu as a popup menu follow these steps:
    1. Create a temporary popup menu (menuPopup)
    2. Append all popup submenus from the main menu to this menu
    3. Call TrackPopupMenu.
    4. Don't forget to remove the submenus from the temporary popup menu, otherwise the menuPopup destructor will destroy the submenus and your program will crash when you try to access the main menu again.
    Code:
    CMenu* pMainMenu = AfxGetMainWnd()->GetMenu();
    CMenu menuPopup;
    if(menuPopup.CreatePopupMenu())
    {
    	int nSubMenus = pMainMenu->GetMenuItemCount();
    	for(int i=0;i<nSubMenus;i++)
    	{
    		CString s;
    		pMainMenu->GetMenuString(i,s,MF_BYPOSITION);
    		menuPopup.AppendMenu(MF_POPUP,(UINT)pMainMenu->GetSubMenu(i)->GetSafeHmenu(),s);
    	}
    	menuPopup.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
    	for(i=0;i<nSubMenus;i++)
    		menuPopup.RemoveMenu(0,MF_BYPOSITION);
    }
    Last edited by amarcode; November 9th, 2004 at 09:03 AM.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  3. #3
    Join Date
    Sep 1999
    Location
    TVM, Kerala, India
    Posts
    210

    Thumbs up Re: Displaying main menu as a popup menu???

    Thank you very much. It is working !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured