Change Window/Taskbar Icon using hardcoded one?

BlitzMax Forums/BlitzMax Beginners Area/Change Window/Taskbar Icon using hardcoded one?

Grisu(Posted 2005) [#1]
Hi!

Has someone managed to make bmx1.14 use the original icon from an exe file and set this one as window / taskbar icon.

I don't want an extra icon in the game dir. Just that the game automatically reads out the icon from itself and uses it.

*hopes his English is understandable*


taxlerendiosk(Posted 2005) [#2]
This works:
Strict

?Win32

Import "-lshell32"

Extern "Win32"
	Function LoadIcon:Int(hWnd:Int, file$z, index:Int) = "ExtractIconA@12"
	Function SetClassLong:Int(hWnd:Int, nIndex:Int, dwNewLong:Int) = "SetClassLongA@12"
End Extern

?

Function Win32_SetIcon(Window:TGadget, IconID = 0)
?Win32
	Local hWnd:Int = QueryGadget(Window, 1)
	Local icon:Int = LoadIcon(hWnd,AppFile,IconID)
	SetClassLong(hWnd,-14,icon)
?
End Function

Not sure how MaxIDE does it, though.


Yan(Posted 2005) [#3]
No need for all that. Just convert your icon to an object file (do a forum search for 'windres') and simply import it into your app.

[edit]
More info here...
http://www.blitzbasic.com/Community/posts.php?topic=53338#596434
[/edit]


taxlerendiosk(Posted 2005) [#4]
Bah. :) Well... if you want to change your icon at run-time for some reason, this could help, I suppose...


Grisu(Posted 2005) [#5]
Thanks to this piece of code, I can convert an icon file to an "O" file, which I simply can import.



Now the exe has the icon as default.
BUT how to I make the app to use this icon in windowed mode (left corner) - NO BMX GUI APP?

Thanks for the help!


taxlerendiosk(Posted 2005) [#6]
I think the icon has to be a special index rather than 1. Can't remember which one exactly though. Look at MaxIDE with ResHack.


Grisu(Posted 2005) [#7]
yepp definately.

The blitzide has 2 sets of icons included.
Though I don't know what I have to do in order to create them.


Yan(Posted 2005) [#8]
All the info you require is in the thread I linked to...

Strict

If AppArgs.length < 2 Then
	Print "Invalid argument count"
	Print "Usage:ObjectMaker [icon path]"
	Print "Number of arguments = " + AppArgs.length
	End
EndIf

Local iconfilename:String = (AppArgs[1].Replace("\", "/")).Replace("~q", "")

If FileType(iconfilename) <> 1 Then
	Print iconfilename + " does not exists or is not a file"
	End
End If

Local rcfilename:String = StripAll(iconfilename) + ".rc"
Print "Creating RC File:" + rcfilename

If CreateFile(rcfilename) Then
	Print "File Created"
	Local f:TStream = OpenFile(rcfilename)
	f.WriteLine("101 ICON ~q" + iconfilename + "~q")
	CloseFile f
End If

Print "Executing Windres to create Object file"
Local objfilename:String = StripExt(rcfilename) + ".o"
Local command:String = "windres -i ~q" + rcfilename + "~q -o ~q" + objfilename + "~q"

Print command

If system_(command)=0 Then
	Print "Created " + objfilename
	Print "Add "
	Print "Import ~q" + objfilename + "~q" 
	Print "to your BMX project to link in icon"
End If



Grisu(Posted 2005) [#9]
As you can see I already use the source (see my post above), the problem is, the icon does not show up in the left corner of the graphics window!?!


Yan(Posted 2005) [#10]
.


Yan(Posted 2005) [#11]
Use this icon file with the object maker compiled from the code I posted above (as I've changed it slightly) and it should work!

[edit]
My apologies, it only appears to work with MaxGUI windows
[/edit]


Grisu(Posted 2005) [#12]
Nothing to appologise for!
I'm glad for every bit of help!

It's just frustrating bmx does not offer such things by default. :/


Yan(Posted 2005) [#13]
Okay, I've sussed it!

In 'BRL.dxgraphics.mod/d3d7graphics.bmx' @ line 49
(Thanks to 'Ed From Mars' for this one)


In 'BRL.GLGraphics/glgraphics.win32.c' @ line 144


All should be working now after a build mods.


Grisu(Posted 2005) [#14]
Now I get even worse results...

The icon only shows up "in" the executable

Before it also showed up as taskicon.
So I see a blank icon for that and in the window corner.

/edit: Crazy, when I compile stuff in debug mode I get the missing icon (taskbar), when using normal mode, it shows up there as it should... X)

Another approach, as I also own bmx gui.
Is there an easy way to set up an empty gui window (centered).
I just want my app to run in fullscreen and windowed mode.


Yan(Posted 2005) [#15]
Hmm...Just humour me for a second. ;o)

Try importing this object file.

You might also want to try this little app (~109KB) to check it works okay.


Grisu(Posted 2005) [#16]
It "seems" to work now, after I deleted BMX completely! and cleared out the temp bmx-folder of my project.

Phew... another day fixing bugs of bmx... :/

Hopefully they will do the changes to the core source code in the next version.

Thanks a LOT!