Page 1 of 1

Can a window's titlebar icon be changed?

Posted: Tue Oct 19, 2010 6:33 am
by DeanH
Hi,

I would like to be able to specify or change the icon that appears on a titlebar after an OpenWindow( statement -- e.g. a program with an already open window opens a second window which should have a different titlebar icon. Is this possible? If so, how?

Thanks.

Re: Can a window's titlebar icon be changed?

Posted: Tue Oct 19, 2010 9:37 am
by gnozal
A quick example :

Code: Select all

DataSection
  Image:
  Data.l $00010000,$20200001,$00010004,$02E80004,$00160000,$00280000,$00200000,$00400000,$00010000,$00000004,$02800000,$00000000
  Data.l $00000000,$00000000,$00000000,$00000000,$80000000,$00800000,$80800000,$00000000,$80000080,$00800080,$80800080,$C0C00080
  Data.l $FF0000C0,$00FF0000,$FFFF0000,$00000000,$FF0000FF,$00FF00FF,$FFFF00FF,$000000FF,$00000000,$00000000,$00000000,$00000000
  Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000
  Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$BFBFFFB8,$00000000,$00000000,$8B000000,$FBFBFF8B,$000000FB,$00000000
  Data.l $B8080000,$BFBFFFB8,$0000A0BF,$00000000,$8BFF0000,$FBFBFF8B,$0000AAFA,$00000000,$F8BF0F00,$BFBFFFB8,$00A0AFBA,$00000000
  Data.l $FFFBFB00,$FBFB8F8B,$00FBFBAA,$00000000,$BFBFBF00,$BABFBFF8,$00BFBFAF,$00000000,$FBFBFB0B,$AAFB8FFF,$F0FBFBFB,$00000000
  Data.l $BFBFBF0F,$AF0000BF,$B0BFBFBF,$00000000,$FBEEEE0E,$0B0000F0,$F0FBFBFB,$00000000,$EEEEEE0E,$0E0000E0,$E0EEEEEE,$00000000
  Data.l $FBFBFB0B,$0B0000F0,$E0EEEEFB,$00000000,$BFBFBF0F,$FF0000BA,$B0BFBFBF,$00000000,$FBFBFB0B,$FFF8FBAA,$F0FBFBFB,$00000000
  Data.l $BABFBF0F,$8FFBBFAF,$B0BFBFFF,$00000000,$AAFBFB00,$B8F8FBFB,$00FBFBFF,$00000000,$AFBABF00,$8BFFBFBF,$00BFFF8F,$00000000
  Data.l $ABAA0B00,$B8FFFBFB,$00F0FFB8,$00000000,$BFAA0000,$8BFFBFBF,$00008F8B,$00000000,$FB0B0000,$B8FFFBFB,$0000B0B8,$00000000
  Data.l $BF000000,$8BFFBFBF,$0000008B,$00000000,$00000000,$B8FFFBFB,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000
  Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000,$00000000
  Data.l $00000000,$00000000,$00000000,$FFFF0000,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$F0FFFFFF,$C0FFFF0F,$80FFFF03,$00FFFF01,$00FEFF00
  Data.l $00FC7F00,$00F83F00,$00F81F00,$00F01F00,$00F00F00,$03F00F00,$03F00FC0,$03F00FC0,$00F00FC0,$00F00F00,$00F00F00,$00F80F00
  Data.l $00F81F00,$00FC1F00,$00FE3F00,$00FF7F00,$80FFFF00,$C0FFFF01,$F0FFFF03,$FFFFFF0F,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
  Data.b $FF,$FF
EndDataSection
If OpenWindow(0, 450, 200, 266, 123, "Change Window Icon Example", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
  ButtonGadget(0, 44, 33, 181, 43, "Change Window Icon")
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        If EventGadget() = 0
          SendMessage_(WindowID(0), #WM_SETICON, 0, CatchImage(0, ?Image)) 
        EndIf
      Case #PB_Event_CloseWindow
        CloseWindow(0)
        Break
    EndSelect
  ForEver
EndIf

Re: Can a window's titlebar icon be changed?

Posted: Tue Oct 19, 2010 11:55 pm
by Mistrel
See here for loading an icon at runtime:

http://www.purebasic.fr/english/viewtop ... 12&t=35534

Re: Can a window's titlebar icon be changed?

Posted: Wed Oct 20, 2010 12:43 am
by DeanH
Thank you!
It was the #WM_SETICON message that I needed.
The following works:

If OpenWindow(0,0,0,640,480,"Test Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
img=LoadImage(#PB_Any,"bm32.ico")
SendMessage_(WindowID(0),#WM_SETICON,0,ImageID(img))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf

I found that it has to be a icon file type. A bmp type does not show.
I also discovered that the 32x32 icon image can appear fairly "messed up" on the titlebar after it is loaded, I am assuming due to the resizing.

Re: Can a window's titlebar icon be changed?

Posted: Wed Oct 20, 2010 3:42 am
by Vera
DeanH wrote:I also discovered that the 32x32 icon image can appear fairly "messed up" on the titlebar after it is loaded, I am assuming due to the resizing.
Good idea, because the titlebar only needs a 16x16 icon size so the OS needs to resize it 'somehow' if you don't provide it.
That's the point, your better off if you provide an icon which includes all seperat images which may be needed, e.g. 16x16 / 32x32 each 8bit/32bit and 256png image for Vista & Win7.
There's a small great tool with which you can quickly compose such icons from a single picture: ToYcon

greetings ~ Vera