CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Popup Menu

  1. #1
    Guest

    Popup Menu

    Hi all
    In Dialog Box or View whenever I press Right Button of the Mouse, how to flash a Popup Menu?
    Thanks in advance.........


  2. #2
    Join Date
    Jul 1999
    Location
    India
    Posts
    51

    Re: Popup Menu

    Trap the WM_RBUTTONDOWN window message. When that is done, in the function, create the CMenu and flash it. This is also known as shortcut menus.


    Cheers!
    DP

    [email protected]

  3. #3
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Popup Menu

    Create a menu resource called for example IDM_MYMENU, with the required menu options in it.

    In the OnRButtonDown(), use the following code :


    OnRBUttonDown()
    {
    CMenu my_menu ;
    CMenu *sub_menu ;
    CPoint point ; // mouse position
    CRect area ;

    this->GetWindowRect(&area) ; // valid area to dismiss menu
    my_menu.LoadMenu(IDM_MYMENU) ; // loads the menu resource
    sub_menu = my_menu.GetSubMenu(0) ; // needed to get he acyual items you want to display
    GetCursorPos(&point) ;
    sub_enu->TrackPopupMenu(TPM_CENTERALIGN | TPM_LEFTBUTTON, point.x, point.y, this, area) ;
    }



    Then you just need to map the relevant ON_COMMAND codes for your menu items...

    I have done most of this from memory, so there may be an odd bug-ette in there....

    HTH


    Roger Allen
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  4. #4
    Join Date
    Apr 1999
    Posts
    3

    Re: Popup Menu

    I would recommand you to handle WM_CONTEXTMENU instead of WM_RBUTTONDOWN.


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