Changing the Icon of a Window

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Changing the Icon of a Window

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by freak.

Somebody asked some time ago how to change the Icon of a Window,
and here's a very simple way to do it using API:

Code: Select all

iconFile.s = OpenFileRequester("Choose icon file:", "",
                               "Icon files | *.ico", 0)
LoadImage(1, iconFile)
OpenWindow(0, #PB_Any, #PB_Any, 300, 200, "Change Window Icon",
           #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
SendMessage_(WindowID(0), #WM_SETICON, 0, ImageID(1))

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
WindowID: The ID of the Window you want to change the Icon of (returned by OpenWindow() )
IconType: If set to 0, it changes the Icon in the Systemmenu
If set to 1, it changes the Icon which is displayed when you press ALT+Tab (this can be a 32x32 Icon)
ImageID: The ID of a Icon loaded with LoadImage()

With this Command, you can also give every Window of your Application a different Icon.

Well, that's it, hope it helps.

Timo



A debugged program is one for which you have not yet found the conditions that make it fail.


Edited by - freak on 16 April 2002 19:25:02