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. CMenu close notification

CMenu close notification

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
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.
  • A Offline
    A Offline
    Abyss
    wrote on last edited by
    #1

    I created a context menu and displayed it using TrackPopupMenu. I do not use TPM_RETURNCMD. My application window receives the result of user selection. It works fine if I select/click some menu item - the window receives message for the given menu item. However if I cancel the context menu (hit Esc or click somewhere else) I do not receive any message. Is there any mechanism to catch context menu cancel event? Another question, how to determine if a context menu (CMenu) is active and displayed? Thanks, Abyss

    N 1 Reply Last reply
    0
    • A Abyss

      I created a context menu and displayed it using TrackPopupMenu. I do not use TPM_RETURNCMD. My application window receives the result of user selection. It works fine if I select/click some menu item - the window receives message for the given menu item. However if I cancel the context menu (hit Esc or click somewhere else) I do not receive any message. Is there any mechanism to catch context menu cancel event? Another question, how to determine if a context menu (CMenu) is active and displayed? Thanks, Abyss

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      TrackPopupMenu will return 0 if user cancels the menu.

      Abyss wrote:

      Another question, how to determine if a context menu (CMenu) is active and displayed?

      If you call the TrackPopupMenu, the thread is blocked at that statement as long as the menu is displayed. So from where you want to know the state of menu?

      nave [OpenedFileFinder]

      A N 2 Replies Last reply
      0
      • N Naveen

        TrackPopupMenu will return 0 if user cancels the menu.

        Abyss wrote:

        Another question, how to determine if a context menu (CMenu) is active and displayed?

        If you call the TrackPopupMenu, the thread is blocked at that statement as long as the menu is displayed. So from where you want to know the state of menu?

        nave [OpenedFileFinder]

        A Offline
        A Offline
        Abyss
        wrote on last edited by
        #3

        If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value. However I do not use the TPM_RETURNCMD flag which cause that the TrackPopupMenu creates the context menu and immediately exits. The menu is still active and sending messages to the window. That is why I can't check the return flag because it just say that the menu has been created. Abyss

        N 1 Reply Last reply
        0
        • A Abyss

          If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value. However I do not use the TPM_RETURNCMD flag which cause that the TrackPopupMenu creates the context menu and immediately exits. The menu is still active and sending messages to the window. That is why I can't check the return flag because it just say that the menu has been created. Abyss

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          Abyss wrote:

          If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value

          I dont think so. please try putting a messagebox in the next line after the TrackPopupMenu() and see whether it is coming or not.

          nave [OpenedFileFinder]

          A 1 Reply Last reply
          0
          • N Naveen

            Abyss wrote:

            If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value

            I dont think so. please try putting a messagebox in the next line after the TrackPopupMenu() and see whether it is coming or not.

            nave [OpenedFileFinder]

            A Offline
            A Offline
            Abyss
            wrote on last edited by
            #5

            Uff, you are right. I put a breakpoint right after the TrackPopupMenu call and it returned only after the menu was closed. Meanwhile the WinAPI send notification to the window. I do not understand why I did not try this?! :-) Many thanks, Abyss

            1 Reply Last reply
            0
            • N Naveen

              TrackPopupMenu will return 0 if user cancels the menu.

              Abyss wrote:

              Another question, how to determine if a context menu (CMenu) is active and displayed?

              If you call the TrackPopupMenu, the thread is blocked at that statement as long as the menu is displayed. So from where you want to know the state of menu?

              nave [OpenedFileFinder]

              N Offline
              N Offline
              Nishad S
              wrote on last edited by
              #6

              Naveen wrote:

              TrackPopupMenu will return 0 if user cancels the menu.

              Only if the TPM_RETURNCMD is specified. If not it will return the success or failure status. See the MSDN documentaion. If you specify TPM_RETURNCMD in the fuFlags parameter, the return value is the menu-item identifier of the item that the user selected. If the user cancels the menu without making a selection, or if an error occurs, then the return value is 0. If you do not specify TPM_RETURNCMD in the fuFlags parameter, the return value is nonzero if the function succeeds and 0 if it fails. To get extended error information, call GetLastError.

              - NS - [ODBaseBtn]

              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