Page 1 of 2

addMessageBox() question

Posted: Fri Dec 04, 2009 9:16 am
by h++
I found the addMessageBox() funtion is not blocked;

Codes like:
...
env->addMessageBox(L"MessageBox Test",L"Hello
IRR",true,EMBF_OK|EMBF_CANCEL);

int i;
i = i + 1;

...

When I call the addMessageBox funtion, it exit soon!
Can I running the "i = i + 1" until the messagebox closed?

Posted: Fri Dec 04, 2009 9:47 am
by Sylence
You will be informed about the message box being closed in the event receiver

Posted: Fri Dec 04, 2009 11:37 am
by Eigen
If addMessageBox() were blocking, your whole program would halt because it's all in one thread.

Posted: Fri Dec 04, 2009 12:15 pm
by h++
Sylence wrote:You will be informed about the message box being closed in the event receiver
But how can I send the event to main program!
I found the addmessagebox() doesn`t return the button value of OK/CANCEL!

Posted: Fri Dec 04, 2009 12:22 pm
by randomMesh
h++ wrote:But how can I send the event to main program!
Sylence wrote:You will be informed about the message box being closed in the event receiver
Just check for the EGET_MESSAGEBOX_OK and/or EGET_MESSAGEBOX_CANCEL event.
h++ wrote:I found the addmessagebox() doesn`t return the button value of OK/CANCEL!
Correct. It returns an IGUIWindow.

Posted: Fri Dec 04, 2009 4:25 pm
by CuteAlien
There is actually a way to get real blocking modal Messageboxes like you have them for example in MFC, but it's a little tricky.
Basically you have to code the same trick which MFC does use: You have to write your mainloop in such a way that it's called within a function which started the MessageBox. And that loop only quits once the MessageBox has been closed.

Posted: Sat Dec 05, 2009 12:43 am
by h++
CuteAlien wrote:There is actually a way to get real blocking modal Messageboxes like you have them for example in MFC, but it's a little tricky.
Basically you have to code the same trick which MFC does use: You have to write your mainloop in such a way that it's called within a function which started the MessageBox. And that loop only quits once the MessageBox has been closed.
It is mean that I will write a class: it public to cguiwindow or others!then translate the button even?

Posted: Sat Dec 05, 2009 1:22 am
by CuteAlien
The way I did it was to have a RunModal function in my main application class as that class was the one doing the gameloop. RunModal had the dialog which should be run modal as parameter and in the loop it checked if the dialog was still visible (although checking for messagebox-events might also work in your case, I just needed more general functionality).

It might be a little tricky, so you should usually try to avoid doing that and in most cases you don't actually need it. Prefer working with the events and non-blocking.

Posted: Sat Dec 05, 2009 4:05 am
by h++
CuteAlien wrote:The way I did it was to have a RunModal function in my main application class as that class was the one doing the gameloop. RunModal had the dialog which should be run modal as parameter and in the loop it checked if the dialog was still visible (although checking for messagebox-events might also work in your case, I just needed more general functionality).

It might be a little tricky, so you should usually try to avoid doing that and in most cases you don't actually need it. Prefer working with the events and non-blocking.
Yet!
I am creating a class with mainloop, and it doesn`t work like what I think!
It just likes what you say!I don`t know how to deal with avoid user to operate the main windows!
Can somebody tell me?

Posted: Sat Dec 05, 2009 6:28 am
by CuteAlien
When you have a modal messgebox the user shouldn't be able to operate the mainwindow at the same time.
If that is what you meant...

Posted: Sun Dec 06, 2009 11:20 am
by h++
CuteAlien wrote:When you have a modal messgebox the user shouldn't be able to operate the mainwindow at the same time.
If that is what you meant...
Oh!
I just want to do like MFC!
But I don`t know how to avoid user to operate the mainwindow when the messagebox window is showed!
And now! when the messagebow window is showed! I found I also can operate the mainwindow!

Posted: Sun Dec 06, 2009 12:08 pm
by Sylence
addMeesageBox() has a "modal" parameter. Set it to true and the user can't interact with the gui except closing the message box.

Posted: Mon Dec 07, 2009 12:43 am
by h++
Sylence wrote:addMeesageBox() has a "modal" parameter. Set it to true and the user can't interact with the gui except closing the message box.
But I found it isn`t block!

when the messagebox is showed! The next code also can run!
Now! I just want the next code will be runed until the messagebox was closed by user!And now I creat a class which isn`t avoid user to operate the mainwindow when the messagebox showed!

So,what shell I do!

Posted: Mon Dec 07, 2009 1:15 am
by randomMesh
h++ wrote:I just want the next code will be runed until the messagebox was closed by user!
C++ knows the concept of classes and methods, so there's no need to 'stop' the execution of your code. Just call the code after your eventreceiver got the close event.

1. Create an EventReceiver which checks if the user closed the box
2. addTheBox
3. In your event receiver, when the close event arrives, call the other code

Easy, hu?

Posted: Mon Dec 07, 2009 1:33 am
by h++
randomMesh wrote:
h++ wrote:I just want the next code will be runed until the messagebox was closed by user!
C++ knows the concept of classes and methods, so there's no need to 'stop' the execution of your code. Just call the code after your eventreceiver got the close event.

1. Create an EventReceiver which checks if the user closed the box
2. addTheBox
3. In your event receiver, when the close event arrives, call the other code

Easy, hu?
But when you obtain two or more messagebox but one just showed each time! And how to separate the event from the messagebox?