Code archives/User Libs/Change Window Icon

This code has been declared by its author to be Public Domain code.

Download source code

Change Window Icon by em222009
Here is the method for changing you Window Icon in Blitz+. There are various articles explaining the procedure but I could not get it to work until now. So, here is the procedure :)
; 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"
;
;

Comments

_PJ_2012
Where does the QueryObject() function come from? Or is it something from Blitz+ only?


GfK2012
It's a native BlitzPlus function. If you're trying to set the window icon in Blitzmax then I believe there is no better way than this.


Code Archives Forum