Page 1 of 1

Set icon for each window?

Posted: Fri Oct 17, 2025 12:19 am
by hdt888
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) ?

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 12:44 am
by RASHAD
Hi

Code: Select all

    PostMessage_(WindowID(?),#WM_SETICON,0,hIcon)

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 2:27 am
by hdt888
It's not work. Thank RASHAD sir !

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 4:56 am
by RASHAD
It's not work
Why ?
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

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 6:43 am
by Bisonte
RASHAD wrote: Fri Oct 17, 2025 4:56 am
It's not work
Why ?
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?

Posted: Fri Oct 17, 2025 8:40 am
by RASHAD
Hi Bisonte
If so next is a workaround needs of course more tricks :D

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


Re: Set icon for each window?

Posted: Fri Oct 17, 2025 8:41 am
by BarryG
.

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 11:09 am
by Mesa
Perhaps it should be clarified that only icons in .ico format work under Windows, not .png, etc.

M.

Re: Set icon for each window?

Posted: Fri Oct 17, 2025 4:26 pm
by Bisonte
RASHAD wrote: Fri Oct 17, 2025 8:40 am Hi Bisonte
If so next is a workaround needs of course more tricks :D
;) This one opens here on W11 two windows with two taskbar fields... and each one have the same Icon...

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?

Posted: Sat Oct 18, 2025 2:14 am
by RASHAD
Hi
You can do it for many window's
Use your own icons :wink:

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



Re: Set icon for each window?

Posted: Sat Oct 18, 2025 9:00 am
by hdt888
Thanks RASHAD sir!

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))
viewtopic.php?t=73366