Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Menu Control Popup using TrackPopupMenuEx

Menu Control Popup using TrackPopupMenuEx

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dehseth
    wrote on last edited by
    #1

    Hello dudes, I am writing an application which places itself to systray when minmized. When user right clicks to icon, I pop-up a menu and my problem starts here. :doh: I want to close pop up window when it loses focus, I also wanna catch events from menu. :-O This is how I open menu:

    POINT xy;
    GetCursorPos(&xy);

    HMENU menu = LoadMenu(this->appInstance, MAKEINTRESOURCE(350));
    BOOL b = TrackPopupMenuEx(GetSubMenu(menu, 0),
    TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RETURNCMD,
    xy.x, xy.y, this->getHWND(), NULL);

    So how I am supposed to MAP events from menu, i am using MFC? :confused: Thank you all... :)

    P 1 Reply Last reply
    0
    • D dehseth

      Hello dudes, I am writing an application which places itself to systray when minmized. When user right clicks to icon, I pop-up a menu and my problem starts here. :doh: I want to close pop up window when it loses focus, I also wanna catch events from menu. :-O This is how I open menu:

      POINT xy;
      GetCursorPos(&xy);

      HMENU menu = LoadMenu(this->appInstance, MAKEINTRESOURCE(350));
      BOOL b = TrackPopupMenuEx(GetSubMenu(menu, 0),
      TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RETURNCMD,
      xy.x, xy.y, this->getHWND(), NULL);

      So how I am supposed to MAP events from menu, i am using MFC? :confused: Thank you all... :)

      P Offline
      P Offline
      Prasann Mayekar
      wrote on last edited by
      #2

      for the first problem: just call setforegroundwindow() before trackpopupmenu(). secondly if u r usig mfc, u can have message map entry for every command and if not then u trap the command in the wndproc(). enjoy Pras

      D 1 Reply Last reply
      0
      • P Prasann Mayekar

        for the first problem: just call setforegroundwindow() before trackpopupmenu(). secondly if u r usig mfc, u can have message map entry for every command and if not then u trap the command in the wndproc(). enjoy Pras

        D Offline
        D Offline
        dehseth
        wrote on last edited by
        #3

        Ok I know that but cannot find how to do it? I create my menu from a resource with id 350. And here is my message map:

        BEGIN_MESSAGE_MAP(CMyWnd, CDialog)
        ON_WM_CLOSE()
        ON_WM_SIZE()
        ON_WM_TIMER()
        ON_BN_CLICKED(152, ...)
        ON_BN_CLICKED(156, ...)
        ON_BN_CLICKED(171, ...)
        ON_BN_CLICKED(172, ...)
        ON_BN_CLICKED(173, ...)
        ON_BN_CLICKED(174, ...)
        ON_BN_CLICKED(175, ...)
        ON_BN_CLICKED(176, ...)
        ON_BN_CLICKED(177, ...)
        ON_MESSAGE(WM_USER_SHELLICON, ...)
        //What should I write here to get menu messages? :confused:
        END_MESSAGE_MAP()

        Thanks....

        M 1 Reply Last reply
        0
        • D dehseth

          Ok I know that but cannot find how to do it? I create my menu from a resource with id 350. And here is my message map:

          BEGIN_MESSAGE_MAP(CMyWnd, CDialog)
          ON_WM_CLOSE()
          ON_WM_SIZE()
          ON_WM_TIMER()
          ON_BN_CLICKED(152, ...)
          ON_BN_CLICKED(156, ...)
          ON_BN_CLICKED(171, ...)
          ON_BN_CLICKED(172, ...)
          ON_BN_CLICKED(173, ...)
          ON_BN_CLICKED(174, ...)
          ON_BN_CLICKED(175, ...)
          ON_BN_CLICKED(176, ...)
          ON_BN_CLICKED(177, ...)
          ON_MESSAGE(WM_USER_SHELLICON, ...)
          //What should I write here to get menu messages? :confused:
          END_MESSAGE_MAP()

          Thanks....

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          dehseth wrote:

          What should I write here to get menu messages?

          Typically ON_COMMAND and ON_UPDATE_COMMAND_UI are used for menus. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          D 1 Reply Last reply
          0
          • M Mark Salsbery

            dehseth wrote:

            What should I write here to get menu messages?

            Typically ON_COMMAND and ON_UPDATE_COMMAND_UI are used for menus. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            D Offline
            D Offline
            dehseth
            wrote on last edited by
            #5

            Yeah I have read a lil bit but I couldnt make it work... I have tried a map

            ON_MESSAGE(WM_COMMAND, Menu_Message)

            also

            ON_MESSAGE(WM_MENUCOMMAND, Menu_Message)

            but still didnt worked! :doh: This is my function which I hope to handle messages:

            LRESULT CMemorizerWnd::Menu_Message(WPARAM wp, LPARAM lp)

            well in debug mode it never enters to my function. So I am still looking for a solution for this... :~

            M 1 Reply Last reply
            0
            • D dehseth

              Yeah I have read a lil bit but I couldnt make it work... I have tried a map

              ON_MESSAGE(WM_COMMAND, Menu_Message)

              also

              ON_MESSAGE(WM_MENUCOMMAND, Menu_Message)

              but still didnt worked! :doh: This is my function which I hope to handle messages:

              LRESULT CMemorizerWnd::Menu_Message(WPARAM wp, LPARAM lp)

              well in debug mode it never enters to my function. So I am still looking for a solution for this... :~

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Maybe remove the TPM_RETURNCMD flag from the TrackPopupMenu() call and use ON_COMMAND instead of ON_MESSAGE in the message map. Also, you won't get the command message until TrackPopupMenu() returns. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups