Window Icon

What it says on the tin: a place to discuss proposed new features.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

SpaceDude wrote:
jacmoe wrote:You know, all it takes is six lines of code
Yeah, that's what Hollowtip has been saying all along :oops:
We are programmers, right?

We go out of harms way to save us from writing six lines of code. :)

I will add it to the Ogre AppWizard.. :P

And thanks Hollowtip for the tip!
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Here's how I do it in my version of the example framework:
Top of OgreApplication.cpp wrote: #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../scripts/res/resource.h"
#endif
Then later on:

Code: Select all

bool OgreOpcodeExample::configure(void)
{
	// Show the configuration dialog and initialise the system
	// You can skip this and use root.restoreConfig() to load configuration
	// settings if you were sure there are valid ones saved in ogre.cfg
	if(mRoot->restoreConfig() || mRoot->showConfigDialog())
	{
		// If returned true, user clicked OK so initialise
		// Here we choose to let the system create a default rendering window by passing 'true'
		mWindow = mRoot->initialise(true);

		// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		HWND hwnd;
		mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
		LONG iconID   = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1) );
		SetClassLong( hwnd, GCL_HICON, iconID );
#endif

		return true;
	}
	else
	{
		return false;
	}
}
Works like it should! :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
axon
Halfling
Posts: 41
Joined: Sun Jul 11, 2004 3:28 am
Location: Adelaide, Australia
x 1
Contact:

Post by axon »

jacmoe wrote:if(mRoot->restoreConfig() || mRoot->showConfigDialog())
Neat! :)

I'd been simply replacing 'showConfigDialog()' with 'restoreConfig()' which will have trouble when the system changes (e.g. a different graphics card is installed) or when deployed to a different system.

With jacmoe's code lazy evaluation means that the dialog is shown only when needed.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

App Icon

Post by liamrudel »

jacmoe wrote:Here's how I do it in my version of the example framework:
Top of OgreApplication.cpp wrote: #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../scripts/res/resource.h"
#endif
Then later on:

Code: Select all

bool OgreOpcodeExample::configure(void)
{
	// Show the configuration dialog and initialise the system
	// You can skip this and use root.restoreConfig() to load configuration
	// settings if you were sure there are valid ones saved in ogre.cfg
	if(mRoot->restoreConfig() || mRoot->showConfigDialog())
	{
		// If returned true, user clicked OK so initialise
		// Here we choose to let the system create a default rendering window by passing 'true'
		mWindow = mRoot->initialise(true);

		// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		HWND hwnd;
		mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
		LONG iconID   = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1) );
		SetClassLong( hwnd, GCL_HICON, iconID );
#endif

		return true;
	}
	else
	{
		return false;
	}
}
Works like it should! :)
Thanks, this was very helpful although to get it working in my app I did have to change this line:

Code: Select all

LONG iconID   = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1) );
to

Code: Select all

LONG iconID   = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
Thanks again :D
The secret of creativity..... is knowing how to hide your sources!
TMT
Halfling
Posts: 59
Joined: Thu Aug 23, 2007 8:09 pm

Re: Window Icon

Post by TMT »

While I think it is a perefectly fine solution to change the icon outside Ogre, I do have one thing I wish would be changed: making Ogre-created windows default to your application's main icon instead of that ugly plain ancient window icon. It's a very simple change to Ogre:

Code: Select all

			WNDCLASS wc = { 0, WindowEventUtilities::_WndProc, 0, 0, hInst,
				0, LoadCursor(NULL, IDC_ARROW),
				(HBRUSH)GetStockObject(BLACK_BRUSH), 0, "OgreD3D9Wnd" };
Just do no LoadIcon() at all.
Post Reply