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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Tray Icon Menu Command handling in MFC

Tray Icon Menu Command handling in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelpquestion
7 Posts 3 Posters 1 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.
  • P Offline
    P Offline
    pritamkd
    wrote on last edited by
    #1

    I have a MFC App with a Tray Icon. On Right clicking the Tray Icon i get a small 'Exit' menu and then on clicking on that i need to exit the App, but thats not happening, and the second time i click there's an assertion. On the handler for the Exit button, i call DestroyWindow(); Also i am overloading the WM_WINDOWPOSCHANGED as said in this article. http://www.codeproject.com/dialog/dlgboxtricks.asp Any help here????? Pritam

    L D 3 Replies Last reply
    0
    • P pritamkd

      I have a MFC App with a Tray Icon. On Right clicking the Tray Icon i get a small 'Exit' menu and then on clicking on that i need to exit the App, but thats not happening, and the second time i click there's an assertion. On the handler for the Exit button, i call DestroyWindow(); Also i am overloading the WM_WINDOWPOSCHANGED as said in this article. http://www.codeproject.com/dialog/dlgboxtricks.asp Any help here????? Pritam

      L Offline
      L Offline
      Laffis
      wrote on last edited by
      #2

      Try AfxPostQuitMessage(0) before you call DestroyWindow. You may even not need to call the latter.

      1 Reply Last reply
      0
      • P pritamkd

        I have a MFC App with a Tray Icon. On Right clicking the Tray Icon i get a small 'Exit' menu and then on clicking on that i need to exit the App, but thats not happening, and the second time i click there's an assertion. On the handler for the Exit button, i call DestroyWindow(); Also i am overloading the WM_WINDOWPOSCHANGED as said in this article. http://www.codeproject.com/dialog/dlgboxtricks.asp Any help here????? Pritam

        L Offline
        L Offline
        Laffis
        wrote on last edited by
        #3

        Try AfxPostQuitMessage(0) before you call DestroyWindow. You may even not need to call the latter. And I recommend you to call CDialog::onClose/OnOK instead of DestroyWindow (if u debug into it, you see the framework does more work just destrywindow). If you use SDI/MDI, try to use the mainframe to intercept the exit message, and after u tidy up things, call the baseclass onclose().

        1 Reply Last reply
        0
        • P pritamkd

          I have a MFC App with a Tray Icon. On Right clicking the Tray Icon i get a small 'Exit' menu and then on clicking on that i need to exit the App, but thats not happening, and the second time i click there's an assertion. On the handler for the Exit button, i call DestroyWindow(); Also i am overloading the WM_WINDOWPOSCHANGED as said in this article. http://www.codeproject.com/dialog/dlgboxtricks.asp Any help here????? Pritam

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          What is the ID of the Exit menu option? Do you have a handler in place for that ID? If so, what are you doing in that handler function?


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          P 1 Reply Last reply
          0
          • D David Crow

            What is the ID of the Exit menu option? Do you have a handler in place for that ID? If so, what are you doing in that handler function?


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            P Offline
            P Offline
            pritamkd
            wrote on last edited by
            #5

            I tried AfxPostQuitMessage(0) but didn't work. Basically, i have put a WM_COMMAND handler function where i check if the ID is TRAY_EXIT (thats the id of the Exit Menu option) and try to call AfxPostQuitMessage() there. But nothing happens. I ran DebugView to capture win32 and ran the app. But DebugView says: >>routing command id 0x8003 sent to app >>IGNORING command id 0x8003 sent to Cdialog Dialog (0x8003 is the TRAY_EXIT number) Is there a better way to handle creating a menu and providing exit option and then handling it?????? Looks like i am missing something here............ Pritam

            D P 2 Replies Last reply
            0
            • P pritamkd

              I tried AfxPostQuitMessage(0) but didn't work. Basically, i have put a WM_COMMAND handler function where i check if the ID is TRAY_EXIT (thats the id of the Exit Menu option) and try to call AfxPostQuitMessage() there. But nothing happens. I ran DebugView to capture win32 and ran the app. But DebugView says: >>routing command id 0x8003 sent to app >>IGNORING command id 0x8003 sent to Cdialog Dialog (0x8003 is the TRAY_EXIT number) Is there a better way to handle creating a menu and providing exit option and then handling it?????? Looks like i am missing something here............ Pritam

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              pritamkd wrote: I tried AfxPostQuitMessage(0) but didn't work. If you are simply wanting to exit your application, just send it a WM_CLOSE message. If it is a dialog-based application, call EndDialog().


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              1 Reply Last reply
              0
              • P pritamkd

                I tried AfxPostQuitMessage(0) but didn't work. Basically, i have put a WM_COMMAND handler function where i check if the ID is TRAY_EXIT (thats the id of the Exit Menu option) and try to call AfxPostQuitMessage() there. But nothing happens. I ran DebugView to capture win32 and ran the app. But DebugView says: >>routing command id 0x8003 sent to app >>IGNORING command id 0x8003 sent to Cdialog Dialog (0x8003 is the TRAY_EXIT number) Is there a better way to handle creating a menu and providing exit option and then handling it?????? Looks like i am missing something here............ Pritam

                P Offline
                P Offline
                pritamkd
                wrote on last edited by
                #7

                Hey Folks!, i got the idea! i didn't have a proper handler in place for the TRAY_EXIT message. My bad!!! :( Anyway , thanks a lot for your help!!!! :) Pritam

                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