Jump to content
  • Advertisement
Sign in to follow this  
AvengerDr

[.net] Simulating modal dialogo behavior

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, as you surely know, when you call MessageBox.Show, the code execution is "blocked", so that if it is used in a if statement, the code branches are not executed until the user presses one of the buttons. Since I'm developing a DirectX UI library, I was wondering how to simulate that kind of behavior. Is too complex to achieve? Right now i pass a delegate that states what the user wants to do with the result once it is obtained, along with the other parameters in the dialog box's "show" method. Do you think this is a viable alternative? Any other ideas?

Share this post


Link to post
Share on other sites
Advertisement
If you are using DirectX then you should have some sort of render loop. So in your render loop you should be checking for user input. If the user moves the mouse, or presses a mouse button or key on the keyboard you should be calling an event that is sent to your UI Manager, then it will pass on the message to an array of buttons and controls you have displayed. In Microsoft's example they just send the WinProc messages to the UI Manager, but you can always split it up into regular MouseDown, MouseMove etc. events

So a MessageBox would just be another control, that contains other controls, like a panel or window, a label and buttons. Again in your render loop you are constantly sending messages to your UI Manager which checks if the user clicks on a button. If the OK button is clicked you call your delegate and handle the event.

Share this post


Link to post
Share on other sites
Yes that is what I'm doing right now. If the UI manager detects that a modal window is displayed it only sends the input events to the dialog window's child controls, and activates the delegate code when a button is pressed. I was asking for another thing: in C# if you have this code:


if (MessageBox.Show(text, buttons and other paramters) == DialogResult.Ok)
{
do something;
}
else
{
do something else;
}


When the dialog is displayed and until the user presses a button, if you hit pause in the compiler, you'll see that the execution is stopped at the if line. I was asking if it would be too much trouble to simulate that kind of behavior. Because right now my Show method has to return void because as soon as I instantiate the window, it continues execution. If I write something like the following, after having instantiated the dialog :


while (dialogResult != DialogResult.None)
continue;
return;


it obviously stalls execution because I assume that kind of behavior in windows.forms is obtained by threading. So my question is, is it worth the trouble to replicate that kind of behaviour, or do you think that "simply" passing the delegate (that details what you want to do when the dialog is closed and you've got a resutl) as a parameter to the show command is a viable alternative?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!