Page 1 of 1

Finding out what type a window has?

Posted: Sun Dec 21, 2008 22:11
by matches81
Hello!
First post here. I've tried searching for an answer, but didn't fine one.
I've been using CEGUI for a bit now with Ogre3D. So far, it works pretty well.

Now I wanted to add a simple thing: Scrolling the mouse wheel should move the scroll bar of comboboxes' drop down lists, if the mouse is hovering over them. I can get the window the mouse is hovering over by calling CEGUI::System::getWindowContainingMouse(), which works fine.
However, I seem unable to check whether the Window* I get actually is a Combobox*, ComboDropList* or an Editbox*.
Using dynamic_cast doesn't work and ends with an exception.
Calling getType() on the Window* I receive works, however I don't know what to compare that String against.

So... yeah... would be nice if someone could point me in the right direction.

Posted: Mon Dec 22, 2008 06:09
by songge3604
On my opinion, you can use setUserString("type", "atypename")

and use getUserString("type") to know what type it is.

Posted: Mon Dec 22, 2008 08:18
by scriptkid
^^ It can even be done easier :)

you can use Window::testClassName which accepts a class name from the cegui namespace.

For example to test for combobox, use:

Code: Select all

if (win->testClassName("Combobox"))
{
}


These classnames are case sensitive!

HTH.

Posted: Mon Dec 22, 2008 11:15
by songge3604
You slove my problem also, hoho~


Thank you!

Posted: Mon Dec 22, 2008 11:56
by dmail
Using dynamic_cast doesn't work and ends with an exception.

Out of curiosity what exception is thrown? The window class has a vtable and a dynamic cast should work fine, in fact a dynamic cast does not throw so something funny maybe going on here.

Posted: Tue Dec 23, 2008 16:22
by matches81
The exception thrown said something about the type not being an _rtti type. I'll just check it again before I give scriptkid's solution a try.

edit:
Okay, just tried the dynamic_cast again, here's the exception:
Unhandled exception at 0x7c812aeb in TankGameW32.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x0012f1b4..

This occurs at "CEGUI::Combobox* cbb = dynamic_cast<CEGUI::Combobox*>(wnd);"

Posted: Tue Dec 23, 2008 17:42
by dmail
matches81 wrote:The exception thrown said something about the type not being an _rtti type. I'll just check it again before I give scriptkid's solution a try.

edit:
Okay, just tried the dynamic_cast again, here's the exception:
Unhandled exception at 0x7c812aeb in TankGameW32.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x0012f1b4..

This occurs at "CEGUI::Combobox* cbb = dynamic_cast<CEGUI::Combobox*>(wnd);"

Thanks for the info, could you answer a few more questions please.
Which version of Visual Studio?
Which service pack?
Do you have RTTI enabled?
Did you also get a linker warning

I will assume visual studio 2005 and no service pack until you can confirm otherwise, this is a bug which was fixed with sp1.

Posted: Tue Dec 23, 2008 17:46
by matches81
dmail wrote:Thanks for the info, could you answer a few more questions please.
Which version of Visual Studio?
Which service pack?
Do you have RTTI enabled?

Sure. VS2005 with SP1 (Version 8.0.50727.762 (SP.050727-7600)), Windows XP SP3.
how do I enable RTTI?


Btw: Scriptkid's solution worked flawlessly, thanks for the help.

Posted: Tue Dec 23, 2008 17:50
by dmail
Project Properites -> c/c++ -> Language -> Enable RTTI

The problem was that pre sp1 RTTI was enabled whether you asked for it or not, in SP1 it does the correct thing. So if it is not enabled you will get an error.

Posted: Wed Dec 24, 2008 09:12
by matches81
dmail wrote:Project Properites -> c/c++ -> Language -> Enable RTTI

The problem was that pre sp1 RTTI was enabled whether you asked for it or not, in SP1 it does the correct thing. So if it is not enabled you will get an error.

Well, it seems RTTI is already enabled for the project.
Also, the project currently compiles and links fine without any warnings.