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. How to check if popup a Modal Window?

How to check if popup a Modal Window?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 4 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.
  • Y Offline
    Y Offline
    yu jian
    wrote on last edited by
    #1

    I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu. But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.

    _ P L 3 Replies Last reply
    0
    • Y yu jian

      I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu. But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      I would suggest setting an application wide flag whenever a modal dialog is displayed. The flag could be set in the WM_INITDIALOG handler. When the modal dialog is closed, the flag can be reset. These actions could be repeated for all modal dialogs in the application. The same flag can then be checked from the tray.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      Y 1 Reply Last reply
      0
      • _ _Superman_

        I would suggest setting an application wide flag whenever a modal dialog is displayed. The flag could be set in the WM_INITDIALOG handler. When the modal dialog is closed, the flag can be reset. These actions could be repeated for all modal dialogs in the application. The same flag can then be checked from the tray.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        Y Offline
        Y Offline
        yu jian
        wrote on last edited by
        #3

        Hi Superman, Perhaps this will meet the recursion problem. And this project only use the C++ not MFC, so if there anyways to use the GetTopWindow or GetLastActivePopup to judge if there is a modal window showing?

        1 Reply Last reply
        0
        • Y yu jian

          I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu. But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.

          P Offline
          P Offline
          pasztorpisti
          wrote on last edited by
          #4

          Normally from the taskbar close menus you should send only WM_CLOSE to the main window and you should handle the program exit and "exit possible" flag from the WM_CLOSE handler of your main window. I would extend Superman's solution by using a counter instead of a bool, everytime a modal dialog opens increase the counter and everytime a modal dialog closes decrease the counter. If you have a lot of modal dialogs then you could automatize this by inheriting your dialog classes from a common class and you could implement this feature only once for all dialogs in the base class. So it is OK to close the main window only if your dialog counter is zero. Optionally you can grey out the close buttons/menuitems when the counter is nozero. EDIT: Here is an alternative solution that MAY WORK, I haven't tried it: Usually when at least one modal dialog is active all other windows/dialogs in the background are disabled (with EnableWindow()[^]). So if the main window is disabled we can suspect that it is disabled because of a modal window (unless you are disabling it manually that I doubt). In this case you could use the IsWindowEnabled()[^] function on the main window to detect whether it is enabled or disabled. So all you have to do is cancelling the main window close (from your WM_CLOSE handler) if the main window is disabled (plus all you should do from your context menu close command is sending a WM_CLOSE to the main window so your WM_CLOSE handler will handle the main window close command regardless of the source of the command). CWnd also has an IsWindowEnabled()[^] method besides the winapi IsWindowEnabled().

          1 Reply Last reply
          0
          • Y yu jian

            I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu. But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Hi, All you need to do is call the GetLastActivePopup function[^]. Best Wishes, -David Delaune

            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