How to change a Window Icon

BlitzPlus Forums/BlitzPlus Programming/How to change a Window Icon

em22(Posted 2009) [#1]
Took me ages to finally figure this out, so, if you have been looking how to do this, take a look:

; Example to change window icon in Blitz+
;
; by em22
;
; make sure you add the user decs to blitz at the end.

EditWindow=CreateWindow("Test Window",50, 50,392,186,0,1)

test=GetWinOSHandle(EditWindow)
SetWindowIcon(test,"c:\windows\explorer.exe")     ; this can be an ico file or an exe with an icon resource.

Repeat  ; test loop

	id=WaitEvent()

	Select id
	
		Case $803
		
		End
	
	End Select 
	
Forever

Function GetWinOSHandle(win)
	Return(QueryObject(win,1))	
End Function

Function SetWindowIcon(hWnd,ICOfile$)
	icon=ExtractIconA(hWnd,ICOfile$,0)
	SetClassLongA(hWnd,-14,icon)
End Function

;
; user decs - create a file called user.decls in C:\Program Files\BlitzPlus\userlibs, and copy the following, remove the ;
; .lib "shell32.dll"
; ShellExecuteA(hwnd%,op$,file$,params$,dir$,showcmd%)
; ExtractIconA%(hWnd%,File$,Index%):"ExtractIconA"
;
;
; .lib "user32.dll"
; SetClassLongA%(hWnd%,nIndex%,Value%):"SetClassLongA"
;
;


Edit : Added missing dec


Sauer(Posted 2009) [#2]
Thanks for sharing, this will certainly come in handy.


Gladclef - Ben B(Posted 2009) [#3]
My comp doesn't recognize "SetClassLongA." Is this from another .dll/decls?


em22(Posted 2009) [#4]
Sorry, it does require another decls that I forgot to add. Fixed this now.