Change Window/Taskbar Icon using hardcoded one?

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

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*

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.

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]

Bah. :) Well... if you want to change your icon at run-time for some reason, this could help, I suppose...

Thanks to this piece of code, I can convert an icon file to an "O" file, which I simply can import.

Import BRL.FileSystem
Import PUB.stdc
Strict
If AppArgs.length < 2 Then
	Print "Invalid argument count"
	Print "Usage:IconMaker filename"
	Print "Number of arguments = "+AppArgs.length
	End
EndIf
Local iconfilename:String= AppArgs[1]
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("1 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


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!

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.

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.

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


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!?!

.

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]

Nothing to appologise for!
I'm glad for every bit of help!

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

Okay, I've sussed it!

In 'BRL.dxgraphics.mod/d3d7graphics.bmx' @ line 49
(Thanks to 'Ed From Mars' for this one)
Function CreateHWND(width,height,fullscreen)

    Local style,ex_style,hwnd
    Local hinst=GetModuleHandleA(0)
    
    Global wndClas
    
    If Not wndClas
        Local wc:WNDCLASS=New WNDCLASS

        wc.hIcon=LoadIconA(hinst,Byte Ptr(101)) ' Added by yan

        wc.hInstance=hinst
        wc.lpfnWndProc=WndProc
        wc.hCursor=LoadCursorA( Null,Byte Ptr IDC_ARROW )
        wc.lpszClassName=DX_CLASS_NAME
        wndClas=RegisterClassA( wc )
        If Not wndClas
            Throw "Failed to register window class"
        EndIf
    EndIf

    Local wndTitle:Byte Ptr=AppTitle.ToCString()

    If fullscreen
        style=WS_VISIBLE|WS_POPUP
        hwnd=CreateWindowExA( 0,DX_CLASS_NAME,wndTitle,style,0,0,width,height,0,0,hinst,Null )
    Else
        style=WS_VISIBLE|WS_CAPTION|WS_SYSMENU
        Local rect[]=[0,0,width,height]
        AdjustWindowRect rect,style,0
        width=rect[2]-rect[0]
        height=rect[3]-rect[1]        
        hwnd=CreateWindowExA( 0,DX_CLASS_NAME,wndTitle,style,CW_USEDEFAULT,CW_USEDEFAULT,width,height,0,0,hinst,Null )
    EndIf
    MemFree wndTitle
    If Not hwnd Throw "Failed to create window"
    Return hwnd
End Function


In 'BRL.GLGraphics/glgraphics.win32.c' @ line 144
static void _initWndClass(){
	static int _done;
	if( _done ) return;
        WNDCLASS wc={0};
	wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
	wc.lpfnWndProc=(WNDPROC)_wndProc;
	wc.hInstance=GetModuleHandle(0);
	
	wc.hIcon=LoadIcon(GetModuleHandle(0),(const char*)101); //Added by yan
	
	wc.lpszClassName=CLASS_NAME;
	wc.hCursor=(HCURSOR)LoadCursor( 0,IDC_ARROW );
	wc.hbrBackground=0;//(HBRUSH)GetStockObject(BLACK_BRUSH);
	if( !RegisterClass( &wc ) ) exit(-1);
	_done=1;
}


All should be working now after a build mods.

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.

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.

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!