addMessageBox() question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

addMessageBox() question

Post 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?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

You will be informed about the message box being closed in the event receiver
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

If addMessageBox() were blocking, your whole program would halt because it's all in one thread.
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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.
"Whoops..."
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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?
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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?
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post 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.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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?
"Whoops..."
h++
Posts: 12
Joined: Fri Dec 04, 2009 9:13 am

Post 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?
Post Reply