Answered by:
Modal over modal?

Question
-
Hi. I'm opening a form like a "popup" as in an alarm clock.
The problem is: I don't know if a modal form is open at this moment, and the popup form needs to be a modal (I think but not sure), so I have a potential (and not so potential) crash.
How can I avoid it?
Thanks.
Saturday, November 19, 2011 11:59 PM
Answers
-
Hi DrGerry,
Typically, a modal form cannot be displayed when another modal form is being displayed by the same process. However, we can open a modeless window as a modal window from its parent window with using below three APIs: (be aware modeless window is modal to its parent window only)
- EnableWindow function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms646291(v=vs.85).aspx
- SetForegroundWindow function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx
- GetWindowLong function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584(v=vs.85).aspx
For instance, you have Main form opened with .ShowDialog, with using these three APIs, you can open the alarm form as a modeless window.
Please check this sample code for details. It is writen for WPF, but is adapt for Winform as well. http://code.msdn.microsoft.com/Modeless-Window-in-WPF-492cb24f
Have a nice day,
Kee Poppy [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by DrGerry Monday, November 21, 2011 3:05 PM
Monday, November 21, 2011 9:11 AMModerator
All replies
-
Lets say we have two forms:
- MainForm - the app form
- AlertForm - to popup timer window.
Add global variables (or static variables):
<em>Public Alert as AlertForm</em>
When the alarm rings, do this:
If Not Alert.Visible Then Alert.ShowDialog()<br/><br/>Else<br/><br/>''' Alerter arleady showing<br/><br/>End If
- Proposed as answer by Jacob Brown Monday, November 21, 2011 2:26 PM
Sunday, November 20, 2011 3:08 PM -
Thanks. I'll try it later and I'll tell you the results.Sunday, November 20, 2011 7:10 PM
-
Hi. I don't read correctly you post. And surely I don't explain myself.
I don't need to know if the alarm for is open. What I need to do is open the alarm form over another modal form.
Thanks.
Sunday, November 20, 2011 8:43 PM -
Hi DrGerry,
Typically, a modal form cannot be displayed when another modal form is being displayed by the same process. However, we can open a modeless window as a modal window from its parent window with using below three APIs: (be aware modeless window is modal to its parent window only)
- EnableWindow function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms646291(v=vs.85).aspx
- SetForegroundWindow function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx
- GetWindowLong function - http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584(v=vs.85).aspx
For instance, you have Main form opened with .ShowDialog, with using these three APIs, you can open the alarm form as a modeless window.
Please check this sample code for details. It is writen for WPF, but is adapt for Winform as well. http://code.msdn.microsoft.com/Modeless-Window-in-WPF-492cb24f
Have a nice day,
Kee Poppy [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by DrGerry Monday, November 21, 2011 3:05 PM
Monday, November 21, 2011 9:11 AMModerator -
Thanks.Monday, November 21, 2011 3:05 PM