Implementing AppIcon!

BlitzMax Forums/BlitzMax Module Tweaks/Implementing AppIcon!

SLotman(Posted 2009) [#1]
Dont be alarmed by the long post... this is actually quite simple to implement!

Did you ever wanted to have something simple as "AppIcon$" variable, just to show a Icon on your program window? Well. here is how it can be implemented!

Only one drawback - it's just for windows, since I dont know how to do it on MAC our Linux :P

I dont even own a Mac or have Linux installed here, so if you can, please help to bring this to both Mac and Linux (probably would be just to tweak glgraphics.linux.c and glgraphics.macos.m)

Well, let's start!

Open brl.mod/blitz.mod/blitz.bmx and just before the AppDir$ line (and it's comments, of course) add this:

Rem
bbdoc: Application icon
about: The #AppIcon global variable contains the name of an icon to be applied on the program window. Should be on the same path as the EXE. Works on Windows only for now.
End Rem
Global AppIcon$="bbAppIcon"


Then, on blr.mod/dxgraphics.mod/d3d7graphics.bmx, on function Create:TD3D7Graphics, just below "if not hwnd return null" add:

	    ?Win32
	       Local icon%
	       Local ICON_SMALL% = 0
 	       Local ICON_BIG% = 1

		   If AppIcon$<>"" Then
   	          icon=ExtractIconA(hwnd, AppIcon$, 0)
		
              SetClassLongA(hwnd,-14,icon)	
              PostMessageA(hwnd, WM_SETICON, ICON_BIG, icon)	
              SendMessageA(hwnd, WM_SETICON, ICON_BIG, icon)
		   End If
        ?


To get it working ALSO on OpenGL, continue...

Open brl.mod/glgraphics.mod/glgraphics.win32.c

just below this:
static const char *_appTitle(){
	return bbStringToCString( bbAppTitle );
}


add:
static const char *_appIcon(){
	return bbStringToCString( bbAppIcon );
}


Then on bbGLGraphicsCreateGraphics, below the line "if ( !hwnd ) return 0;" add:

	if (_appIcon() && !(depth))
	{
        icon=ExtractIconA(hwnd, _appIcon(), 0);
		
        SetClassLongA(hwnd,-14,icon);
        PostMessageA(hwnd, WM_SETICON, 1, icon);
        SendMessageA(hwnd, WM_SETICON, 1, icon);   
	}


Phew! (I hope I didnt forget anything... )

Now save everything, recompile modules... and all you have to do to show a Icon on your window (on Windows only, sorry!) is to set AppIcon$ to the name of your icon. Dont forget to put the icon on the same path as the EXE, and it will work (Tested from win98 to Vista64)

And if you dont want an icon on your window, just set AppIcon$="" so it wont load anything and your window will be the same as always :)


degac(Posted 2009) [#2]
Good, but unfortunately it's a mod only for windows...so dont' use BRL/PUB mod to make this changes as they are not for all platforms - and they are not 'permanent' (at every new update you need to manually change it...)


Mark Tiffany(Posted 2009) [#3]
Alternatively, for a cross-platform solution, have you tried SetGadgetPixmap with a window recently?

SetGadgetPixmap window gadget , pixmap , GADGETPIXMAP_ICON



Brucey(Posted 2009) [#4]
The Mac doesn't have an App icon in the sense of the little image in the corner of a window... so you don't need to worry too much about that platform.


SLotman(Posted 2009) [#5]

(at every new update you need to manually change it...)


I know... I just needed a quick and easy way to set the application icon... and set it as soon as the window is created, so I implemented it. I even did more like centering the window... things I wish would be on the official build, but since it isn't...


Alternatively, for a cross-platform solution, have you tried SetGadgetPixmap with a window recently?


But isn't that for MaxGUI only?


The Mac doesn't have an App icon in the sense of the little image in the corner of a window... so you don't need to worry too much about that platform.


Great! So now I just have to worry about Linux ;)
Maybe after I finish the current game I'm working on right now (which will be ported to Linux) I'll take a look :)