Changing OGRE Render Window title and icon

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Changing OGRE Render Window title and icon

Post by madmax » Wed Jan 25, 2006 9:52 pm

Hi! :D
For some time i was working on a problem of changing window title and icon. And this is what i've found out (some kind of unfinished tutorial):



------------------------------------------------------
1. Changing the window title. It's done in the Ogre::Root::initialise(bool autoCreateWindow, const String &windowTitle) method. When you initialise Ogre, you must change the windowTitle param, so you'll have your own title,

not the "OGRE Render Window".

2. Changing the window icon. The new window is being created in (if you choose Direct3D9) in D3D9RenderWindow (In OpenGL and Direct3D7, it's most likely in

the same files) - OgreD3D9RenderWindow.cpp (lines 274-277):

Code: Select all

 WNDCLASS wc = { 0, WndProc, 0, 0, hInst, 
    LoadIcon(NULL, IDI_WARNING), LoadCursor(NULL, IDC_ARROW), 
    (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "OgreD3D9Wnd" }; 
 RegisterClass(&wc); 
- As you see, the icon is created by HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName)

For now, i'm satisfied with the standard warning icon (yellow triangle with an exclamation mark inside :D) - it's done like this:

LoadIcon(NULL, IDI_WARNING)

------------------------------------------------------
Perhaps, to change the icon to non-standard we must include our .ico in D3D9RenderSystem project .rc file and name it somehow (e.g. ICO_USER) and then use

LoadIcon(NULL, ICO_USER)?..

I don't entirely understand all these handles and instances...
So, if anybody knows how, please tell me the way to use this method to import my own icon... :)
And also i'd like to know where i must store this icon - in .ico file, in RenderSystem_Direct3D9.dll or in my executable (it would be the best variant)?..

Thanx a lot. :D
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

User avatar
griminventions
Halfling
Posts: 52
Joined: Sat Oct 29, 2005 7:02 am
Contact:

Post by griminventions » Wed Jan 25, 2006 10:07 pm

That's a good question. I'd prefer to put the icon in an .ico file so it doesn't require a recompile to change from project to project.
0 x

User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Post by madmax » Mon Jan 30, 2006 4:58 pm

And so?.. :twisted:
Where's everybody?! Does anyone know how to make it?
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Post by xavier » Mon Jan 30, 2006 5:03 pm

This is a basic Windows API programming question, and is amply covered in any number of online and print resources.
0 x

User avatar
raicuandi
Gargoyle
Posts: 1092
Joined: Wed Nov 09, 2005 12:56 pm
Location: Adelaide, Australia
Contact:

Post by raicuandi » Mon Jan 30, 2006 5:13 pm

xavier wrote:This is a basic Windows API programming question, and is amply covered in any number of online and print resources.
What about Linux?
I personally think that the most hard part about creating an application is setting that damn icon. I just can't figure it out! Nomather if I'm using Windows, Qt, GTK, whatever! It seems imposible to me, and I assume that those that ever put an icon to an MS Windows application had to send the program to microsoft to have theyr icon put... :shock:

No offense or anything, but that's my personal oppinion. If you don't like it, ignore it. I've made many apps since I know myself, for both Windows and Linux, and all have one thing in common: the default OSs icon... :roll:
0 x

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Post by xavier » Mon Jan 30, 2006 5:15 pm

raicuandi wrote:
xavier wrote:This is a basic Windows API programming question, and is amply covered in any number of online and print resources.
What about Linux?
Then it's an X window manager programming question as well.

The point is, figuring out how to get your favorite window system to load/put an icon somewhere is nothing to do with Ogre.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Mon Jan 30, 2006 6:39 pm

On Windows you either call CreateIconFromResource/LoadIconFromResource or in the LoadIcon function, simply pass the define of the icon from your resource header.

I think. Look it up.

If on Linux: look it up. :wink:
0 x

pfo
Halfling
Posts: 68
Joined: Tue Jan 03, 2006 9:55 pm

Post by pfo » Mon Jan 30, 2006 6:40 pm

Also, I think you can get the HWND from Ogre::Root and use that with SetWindowText to change the window caption manually.
0 x

User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Post by madmax » Thu Feb 02, 2006 10:50 pm

THNX to all, i've only tried to find out some information about this, cause i'm in simmilar situation as raicuandi :) and so i thought that ogre, as a cross-platform library, has some useful wraps for these dusty API functions both for Win and Linux...
@jacmoe: thx, i'm on windows and i'll try these advices. :)
@pfo: thanks, i hasn't thought about dynamic title changing - i'll try this. Hm, i could make some kind of running line...
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

User avatar
morez
Kobold
Posts: 36
Joined: Mon Nov 14, 2005 11:40 am
Location: Verona, Italy

Post by morez » Fri Feb 03, 2006 12:43 pm

I've made many apps since I know myself, for both Windows and Linux, and all have one thing in common: the default OSs icon...
I try to search something like "change icon exe" with google.. have you ever try something like this ..?! ;)
0 x

User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: Princeton, New Jersey, USA
Contact:

Post by nikki » Fri Feb 03, 2006 12:57 pm

You can use Resource Hacker. I use it to change the Configuration Dialog, even though I have the source, because its easier. :)
0 x

User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Post by madmax » Fri Feb 03, 2006 3:03 pm

2nikki and morez:
I think raicuandi's talking about the icon in the window title, not the exe file icon...
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

User avatar
raicuandi
Gargoyle
Posts: 1092
Joined: Wed Nov 09, 2005 12:56 pm
Location: Adelaide, Australia
Contact:

Post by raicuandi » Fri Feb 03, 2006 3:28 pm

madmax wrote:2nikki and morez:
I think raicuandi's talking about the icon in the window title, not the exe file icon...
And I was thinking you were talking about that! Lol! :lol:
0 x

User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Post by madmax » Fri Feb 03, 2006 9:08 pm

And I was thinking you were talking about that! Lol! Laughing
Yeah, the topic is about it, if somebody didn't mentioned... :lol: :roll:
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

robx
Gnoblar
Posts: 21
Joined: Sat May 27, 2006 7:17 pm

Post by robx » Sun Jun 04, 2006 9:21 pm

madmax wrote:And so?.. :twisted:
Where's everybody?! Does anyone know how to make it?
Icon of exe:
1. Add your project xy.rc file and define ypur icon

Code: Select all

my_icon ICON "ares.ico"
2. Copy your icon in scripts directory.

3. Build and run.

Ogre Render Window icon:
1. open the ogrenew/rendersytems/ogl or dx9/scripts/RenderSystem_Direct3D9_stlp.cbp or RenderSystem_Direct3D9_vc8.vcproj

2. Add your project xy.rc file and define ypur icon

Code: Select all

my_icon ICON "ares.ico"
3. copy your icon in scripts directory.

4. open the OgreD3D9RenderWindow.cpp:
line 274:

Code: Select all

WNDCLASS wc = { 0, WndProc, 0, 0, hInst,
				LoadIcon(0, "my_icon"), LoadCursor(NULL, IDC_ARROW),
				(HBRUSH)GetStockObject(BLACK_BRUSH), 0, "OgreD3D9Wnd" };
			RegisterClass(&wc);
5. Build the project and copy the dll in your running folder.
0 x

User avatar
madmax
Halfling
Posts: 98
Joined: Wed Nov 09, 2005 6:20 pm
Location: Russia, St.Petersburg
Contact:

Post by madmax » Thu Jun 08, 2006 11:22 pm

thx
0 x
"It's a dangerous business going out your front door".
J. R R. Tolkien

---------
Sunny Arkanoid :wink:

DragonM
Gnoblar
Posts: 22
Joined: Mon Jul 21, 2008 4:35 am

Post by DragonM » Mon Jul 21, 2008 4:46 am

Old thread, but the answers range from snide to useless to cumbersome to bad practice. Here's how to do it:

Code: Select all

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
  root = Root::getSingletonPtr();
  RenderWindow *window = root->getAutoCreatedWindow();
  HWND hwnd;
  window->getCustomAttribute("WINDOW", &hwnd);
  HINSTANCE hinstance;
  hinstance = GetModuleHandle(NULL);
  HICON icon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_YOUR_ICON));
  SendMessage(hwnd, WM_SETICON, ICON_BIG, LPARAM(icon));
  SendMessage(hwnd, WM_SETICON, ICON_SMALL, LPARAM(icon));
#endif
This code assumes you used root->initialise(true); since you would likely have all the handles still if you'd gone some other route.
0 x

fibriZo
Gnoblar
Posts: 3
Joined: Fri Jun 14, 2013 9:25 am

Re: Changing OGRE Render Window title and icon

Post by fibriZo » Sat Jun 22, 2013 8:56 pm

At least one sensible answer! :mrgreen:

It seemed so strange to me the DirectX solution. :?

Thanks for your great and short answer, DragonM.
0 x

Post Reply