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