I suposuse you have to pass the memory address of the long variable, not the value itself. Use pointers or even the memory address of your LONG variable when calling the API.
Would you mind showing me how to do that? If you could run the code and try to debug it, I would really appreciate it.
* Update *
Here is the updated code. For some reason, changing my Ints to Longs for calls like GetActiveWindow makes them stop working, so I've left them alone. Also, if Local Icon is cast as a Long instead of an Int, it returns 0.
Import "-lshell32" Import "-lkernel32" Extern Function LoadIcon:Long(hWnd%, file$z, index%) = "ExtractIconA@12" End Extern Extern Function GetLastError%() = "GetLastError@0" End Extern Extern "win32" Function GetActiveWindow%() Function GetDesktopWindow%() Function GetWindowRect%(hWnd%, lpRect:Byte Ptr) Function SetWindowPos%(hWnd%, after%, x%, y%, w%, h%, flags%) Function SetClassLong%(hWnd%, nIndex%, dwNewLong:Long) = "SetClassLongA@12" End Extern Type lpRECT Field l%, t%, r%, b% End Type Const GFX_WIDTH = 320, GFX_HEIGHT = 200, BIT_DEPTH = 0, HERTZ = -1 Graphics GFX_WIDTH, GFX_HEIGHT, BIT_DEPTH, HERTZ Local hWnd% = GetActiveWindow() Print "hWnd: " + hWnd Local icon% = LoadIcon(hWnd, "c:\icon.ico", 0) Print "icon: " + icon Local ret% = SetClassLong(hWnd, -14, icon) Print "ret: " + ret If Not ret Then Notify GetLastError() Local desk_hWnd% = GetDesktopWindow(), l:lpRect = New lpRECT GetWindowRect desk_hWnd, l:lpRECT SetWindowPos hWnd, -2, (l.r / 2) - (GFX_WIDTH / 2), (l.b / 2) - (GFX_HEIGHT / 2), 0, 0, 1 Repeat; FlushMem; Flip; Until KeyDown(KEY_ESCAPE)
GetLastError is returning 1414, which means "Invalid Icon Handle". Sounds like we're getting closer.