How to set a Icon to a WindowBar ?

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 608
Joined: Thu May 30, 2013 4:39 pm

How to set a Icon to a WindowBar ?

Post 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
macOS Catalina 10.15.7
User avatar
Shardik
Addict
Addict
Posts: 2074
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to set a Icon to a WindowBar ?

Post 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
Wolfram
Enthusiast
Enthusiast
Posts: 608
Joined: Thu May 30, 2013 4:39 pm

Re: How to set a Icon to a WindowBar ?

Post by Wolfram »

Thanks! ;-)
macOS Catalina 10.15.7
Post Reply