Page 1 of 1

How to set a Icon to a WindowBar ?

Posted: Sat Sep 20, 2014 8:18 pm
by Wolfram
Can someone tell me how to set a Icon to the WindowBar?

Maybe this is the right code but I cant translate it :-/
[[<window> standardWindowButton:NSWindowDocumentIconButton] setImage:<image>]

Thanks

Re: How to set a Icon to a WindowBar ?

Posted: Sat Sep 20, 2014 10:48 pm
by Shardik
Wolfram wrote:Can someone tell me how to set a Icon to the WindowBar?
You may try to do it in two steps:

1. You have to create a NSWindowsDocumentButton by yourself because a window created with OpenWindow() doesn't create one. Therefore your posted code always returns 0. The following code takes an existing file and displays its filename together with the corresponding icon to the left of the filename in the window's title bar:

Code: Select all

OpenWindow(0, 270, 100, 250, 170, "")
Filename$ = #PB_Compiler_Home + "Install.Txt"
CocoaMessage(0, WindowID(0), "setTitleWithRepresentedFilename:$", @Filename$)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
2. Now your code from above works and you are able to replace the icon with your own icon. You may also change the filename in the window title to your own window title:

Code: Select all

#NSWindowDocumentIconButton = 4

UsePNGImageDecoder()

If LoadImage(0, #PB_Compiler_Home + "logo.png")
  OpenWindow(0, 270, 100, 230, 170, "")
  Filename$ = #PB_Compiler_Home + "Install.Txt"
  CocoaMessage(0, WindowID(0), "setTitleWithRepresentedFilename:$", @Filename$)
  CocoaMessage(0, CocoaMessage(0, WindowID(0),
    "standardWindowButton:", #NSWindowDocumentIconButton),
    "setImage:", ImageID(0))
  SetWindowTitle(0, "PureBasic rulez!")
EndIf

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: How to set a Icon to a WindowBar ?

Posted: Sat Sep 20, 2014 11:17 pm
by Wolfram
Thanks! ;-)