Set icon for each window?
Set icon for each window?
I have a program with 2 windows:
+ main1 -> icon1
+ main2 -> icon2
And 2 child windows of main window 2.
+child2_1 -> icon3
+child2_2 -> icon4
How to set window icons for these 4 windows (this icon will be displayed under the Windows Taskbar) ?
+ main1 -> icon1
+ main2 -> icon2
And 2 child windows of main window 2.
+child2_1 -> icon3
+child2_2 -> icon4
How to set window icons for these 4 windows (this icon will be displayed under the Windows Taskbar) ?
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
Re: Set icon for each window?
Hi
Code: Select all
PostMessage_(WindowID(?),#WM_SETICON,0,hIcon)
Egypt my love
Re: Set icon for each window?
It's not work. Thank RASHAD sir !
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
Re: Set icon for each window?
Why ?It's not work
PB 6.21 x64 Windows 11 x64
Code: Select all
CatchImage(0,?icon1)
CatchImage(1,?icon2)
OpenWindow(0, 0, 0, 800,600, "PureBasic Window #1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PostMessage_(WindowID(0),#WM_SETICON,0,ImageID(0))
OpenWindow(1, 0, 0, 400,300, "PureBasic Window #2", #PB_Window_SystemMenu| #PB_Window_ScreenCentered ,WindowID(0))
PostMessage_(WindowID(1),#WM_SETICON,0,ImageID(1))
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
End
DataSection
icon1:
IncludeBinary #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
icon2:
IncludeBinary #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
EndDataSection
Egypt my love
Re: Set icon for each window?
I think he mean, that the Icon on the Taskbar should change also to the window that has the focus...
Re: Set icon for each window?
Hi Bisonte
If so next is a workaround needs of course more tricks
If so next is a workaround needs of course more tricks

Code: Select all
CatchImage(0,?icon1)
CatchImage(1,?icon2)
OpenWindow(0, 400, 400, 400,300, "PureBasic Window #1", #PB_Window_SystemMenu )
OpenWindow(1, 420 + WindowWidth(0), 400, 400,300, "PureBasic Window #2", #PB_Window_SystemMenu )
AddWindowTimer(0,125,10)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If GetActiveWindow() = 0
PostMessage_(WindowID(0),#WM_SETICON,0,ImageID(0))
PostMessage_(WindowID(1),#WM_SETICON,0,ImageID(0))
ElseIf GetActiveWindow() = 1
PostMessage_(WindowID(0),#WM_SETICON,0,ImageID(1))
PostMessage_(WindowID(1),#WM_SETICON,0,ImageID(1))
EndIf
Case #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndSelect
Until Quit = 1
End
DataSection
icon1:
IncludeBinary #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
icon2:
IncludeBinary "d:/PBLogoBig.ico"
EndDataSection
Egypt my love
Re: Set icon for each window?
.
Last edited by BarryG on Sat Oct 18, 2025 12:44 am, edited 1 time in total.
Re: Set icon for each window?
Perhaps it should be clarified that only icons in .ico format work under Windows, not .png, etc.
M.
M.
Re: Set icon for each window?
RASHAD wrote: Fri Oct 17, 2025 8:40 am Hi Bisonte
If so next is a workaround needs of course more tricks![]()

I think he ment : MainWindow Icon0, Childwindow 1 Icon1, ChildWindow2 Icon 2
only one Taskbarentry and the icon at the taskbar should change...
I think its not really possible without a mysterious hack

The design of Windows is not made for this ....
Re: Set icon for each window?
Hi
You can do it for many window's
Use your own icons
You can do it for many window's
Use your own icons

Code: Select all
CatchImage(0,?icon1)
CatchImage(1,?icon2)
CatchImage(2,?icon3)
OpenWindow(100, -400, 0, 0,0, "main", #PB_Window_SystemMenu ) ;hidden window
OpenWindow(0, 420, 400, 400,300, "PureBasic Window #1", #PB_Window_SystemMenu )
PostMessage_(WindowID(0),#WM_SETICON,0,ImageID(0))
OpenWindow(1, 420 + WindowWidth(0), 400, 400,300, "PureBasic Window #2", #PB_Window_SystemMenu ,WindowID(0))
PostMessage_(WindowID(1),#WM_SETICON,0,ImageID(1))
OpenWindow(2, 200 + WindowWidth(0), 700, 400,300, "PureBasic Window #3", #PB_Window_SystemMenu ,WindowID(1))
PostMessage_(WindowID(2),#WM_SETICON,0,ImageID(2))
AddWindowTimer(0,125,10)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If GetActiveWindow() = 0
PostMessage_(WindowID(100),#WM_SETICON,0,ImageID(0))
ElseIf GetActiveWindow() = 1
PostMessage_(WindowID(100),#WM_SETICON,0,ImageID(1))
ElseIf GetActiveWindow() = 2
PostMessage_(WindowID(100),#WM_SETICON,0,ImageID(2))
EndIf
Case #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndSelect
Until Quit = 1
End
DataSection
icon1:
IncludeBinary #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
icon2:
IncludeBinary "d:/PBLogoBig.ico"
icon3:
IncludeBinary "d:/icons8_trash.ico"
EndDataSection
Egypt my love
Re: Set icon for each window?
Thanks RASHAD sir!
Edited: Add the icon to the resource file generated by PackEx (Thorsten1867), the code "PostMessage_" work too.
viewtopic.php?t=73366
Edited: Add the icon to the resource file generated by PackEx (Thorsten1867), the code "PostMessage_" work too.
Code: Select all
ResourceEx::Open(#ResEx, #RES_NAME)
ResourceEx::UseImage(#ResEx, #ICO_1, "my_ico_64x64.ico")
PostMessage_(WindowID(2),#WM_SETICON,1,ImageID(#ICO_1))
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.