Set icon for each window?

Just starting out? Need help? Post your questions and find answers here.
hdt888
User
User
Posts: 53
Joined: Sun Jul 07, 2024 8:42 am

Set icon for each window?

Post 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) ?
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4979
Joined: Sun Apr 12, 2009 6:27 am

Re: Set icon for each window?

Post by RASHAD »

Hi

Code: Select all

    PostMessage_(WindowID(?),#WM_SETICON,0,hIcon)
Egypt my love
hdt888
User
User
Posts: 53
Joined: Sun Jul 07, 2024 8:42 am

Re: Set icon for each window?

Post by hdt888 »

It's not work. Thank RASHAD sir !
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4979
Joined: Sun Apr 12, 2009 6:27 am

Re: Set icon for each window?

Post 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
Egypt my love
User avatar
Bisonte
Addict
Addict
Posts: 1318
Joined: Tue Oct 09, 2007 2:15 am

Re: Set icon for each window?

Post 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...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4979
Joined: Sun Apr 12, 2009 6:27 am

Re: Set icon for each window?

Post 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

Egypt my love
BarryG
Addict
Addict
Posts: 4211
Joined: Thu Apr 18, 2019 8:17 am

Re: Set icon for each window?

Post by BarryG »

.
Last edited by BarryG on Sat Oct 18, 2025 12:44 am, edited 1 time in total.
Mesa
Enthusiast
Enthusiast
Posts: 444
Joined: Fri Feb 24, 2012 10:19 am

Re: Set icon for each window?

Post by Mesa »

Perhaps it should be clarified that only icons in .ico format work under Windows, not .png, etc.

M.
User avatar
Bisonte
Addict
Addict
Posts: 1318
Joined: Tue Oct 09, 2007 2:15 am

Re: Set icon for each window?

Post 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 ....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply