Page 1 of 1

Suggestion: allow using custom icon for window

Posted: Mon Nov 17, 2008 5:37 pm
by comicsteam
I am developing a game using Irrlicht.
I want to use my custom icon and display it on the window's top left corner.
It is possible to do so if i named my icon as "irrlicht.ico".
However, if I want to embed my icon inside the exe file, there's no way for me to use it in Irrlicht.
Could we modify the source code a little bit in this way:

for struct SIrrlichtCreationParameters, add const char* windowIcon (default is "irrlicht.ico")

for createDevice()

Code: Select all

IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(video::E_DRIVER_TYPE driverType,
		const core::dimension2d<s32>& windowSize,
		u32 bits, bool fullscreen,
		bool stencilbuffer, bool vsync, IEventReceiver* res,
		const char* windowIcon) /***added***/
{
	SIrrlichtCreationParameters p;
	p.DriverType = driverType;
	p.WindowSize = windowSize;
	p.Bits = bits;
	p.Fullscreen = fullscreen;
	p.Stencilbuffer = stencilbuffer;
	p.Vsync = vsync;
	p.EventReceiver = res;
	p.windowIcon = windowIcon; /***added***/

	return createDeviceEx(p);
}
for CIrrDeviceWin32 constructor

Code: Select all

CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), HWnd(0), ChangedToFullScreen(false),
	IsNonNTWindows(false), Resized(false),
	ExternalWindow(false), Win32CursorControl(0)
{
	......
	......

	// if there is an icon, load it
	wcex.hIcon = (HICON)LoadImage(hInstance, CreationParams.windowIcon /***modified***/, IMAGE_ICON, 0,0, LR_LOADFROMFILE);
	......
	......
}
So that i can use the following code to create a window with my icon

Code: Select all

_device = createDevice(
		video::EDT_DIRECT3D9,
		core::dimension2d<s32>(800, 600),
		32,
		false,
		false,
		false,
		0,
		MAKEINTRESOURCEA(IDI_ICON1) //IDI_ICON1 is the icon embedded in the exe file
		);

Posted: Mon Nov 17, 2008 8:41 pm
by JP
You can do this within MSVC08 for sure.... and previous versions i think... and DevC++ can do it as well so mostly i think it's an IDE problem rather than something for irrlicht.

Posted: Mon Nov 17, 2008 10:48 pm
by hybrid
I'll move this to the bug forum (as it's a better place for feature requests of this kind as well). Maybe you can also submit a feature request to the Irrlicht tracker at our SourceForge page?
https://sourceforge.net/tracker2/?atid= ... unc=browse

Posted: Mon Nov 17, 2008 10:55 pm
by drewbacca
It would be nice to have a cleaner way to set the icon. In the meantime, someone posted some code on this forum that I know will work in at least VS8 to set the window icon.

Code: Select all

	HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
	HICON hSmallIcon = (HICON) LoadImage ( hInstance, MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
	irr::video::SExposedVideoData exposedData = driver->getExposedVideoData();
	HWND hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
	SendMessage ( hWnd, WM_SETICON, ICON_SMALL, (long)hSmallIcon );
where IDI_ICON2 was the image in my resource file.

Posted: Wed Nov 19, 2008 6:29 am
by FuzzYspo0N
no , just use the tools you are using properly.
The problem with your idea is that that is windows only, so its useless on a cross platform engine.

I understand the code exists on every platform...but then again so do resource files. Building with an icon is pancakes (seeing as we work in project nots from the command line) it isnt really a matter.

Posted: Wed Nov 19, 2008 8:54 am
by dlangdev
I thought you just copy over the icon file with __your__ icon? you should be able to display a different image.