Page 1 of 1
GUI window closed?
Posted: Fri Jan 20, 2006 6:25 pm
by Mike
I have a GUI window and I want to detect when it is being closed with the X button. I can't find any event for this. I tried checking if the window is visible but it seems it is always visible even when it is closed

.
Posted: Fri Jan 20, 2006 6:45 pm
by AlexL
This thread here might helps you abit -
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=10962 - Also might try searching around abits so you don't have to worry abouts possibly getting flamed.
Posted: Fri Jan 20, 2006 8:11 pm
by nomad
Here's what I did to get the close message - this involves a few small additions to the engine source code

, I've marked these (5 lines) with //ADD
in CGUIWindow.cpp:
Code: Select all
bool CGUIWindow::OnEvent(SEvent event)
{
/*
Some small inclusions from CGUIMessageBox.cpp, so an event is
generated when the close button is pressed
*/
SEvent outevent; //ADD
outevent.EventType = EET_GUI_EVENT; //ADD
outevent.GUIEvent.Caller = this; //ADD
switch(event.EventType)
{
case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{
Dragging = false;
return true;
}
else
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
if (event.GUIEvent.Caller == CloseButton)
{
outevent.GUIEvent.EventType = EGET_MESSAGEBOX_CANCEL; //ADD
Parent->OnEvent(outevent); //ADD
remove();
return true;
}
}
break;
So your event handler should now get a EGET_MESSAGEBOX_CANCEL message, i.e.
Code: Select all
if ((event.EventType == EET_GUI_EVENT) && (event.GUIEvent.EventType == EGET_MESSAGEBOX_CANCEL)) {
//do something
}
I don't know if there's an easier way, but this seems to work fine for me.
Posted: Sat Jan 21, 2006 6:44 pm
by Mike
OK thanks. I searched the forums but I hoped there is nicer way to do this.