Icon on title bar?
Posted: Tue Jun 16, 2009 11:03 pm
How do you put an icon on the left side of the title bar in Linux and Win32 without using the API?
http://www.purebasic.com
https://www.purebasic.fr/english/
I assume you're refering to the Visual Designer? That does not appear to be available in the Linux version of PB. Linux is my primary development platform. Can this be done through code alone?Kaeru Gaman wrote:Menu Compiler > Compiler Options > [√] Use Icon > Browse
That option is "grayed out" on the Linux version, so there must be another way to do it since the PB IDE has an icon.Kaeru Gaman wrote:Menu Compiler > Compiler Options > [√] Use Icon > Browse
Code: Select all
IconPath.S = #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
OpenWindow(0, 0, 0, 300, 100, "<-- Changed titlebar icon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
gtk_window_set_icon_from_file_(WindowID(0), PeekS(@IconPath), IconError)
CompilerElse
IconPath = ReplaceString(IconPath, "/", "\")
If LoadImage(0, IconPath)
SendMessage_(WindowID(0), #WM_SETICON, 0, ImageID(0))
EndIf
CompilerEndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
This works well and I can even use CatchImage in the Windows version so I don't have to load it from a file. Is it possible to do the same thing with the GTK API? I looked at the docs but I don't see any possibility... of course I've never looked at GTK docs before so I'm probably missing something.Shardik wrote:A short example which runs in Windows and Linux and uses a CDPlayer icon which is contained in each PB Windows and Linux installation:Code: Select all
IconPath.S = #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico" OpenWindow(0, 0, 0, 300, 100, "<-- Changed titlebar icon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) CompilerIf #PB_Compiler_OS = #PB_OS_Linux gtk_window_set_icon_from_file_(WindowID(0), PeekS(@IconPath), IconError) CompilerElse IconPath = ReplaceString(IconPath, "/", "") If LoadImage(0, IconPath) SendMessage_(WindowID(0), #WM_SETICON, 0, ImageID(0)) EndIf CompilerEndIf Repeat Until WaitWindowEvent() = #PB_Event_CloseWindow
Why PeekS()? IconPath is already string variable.Shardik wrote:Code: Select all
gtk_window_set_icon_from_file_(WindowID(0), PeekS(@IconPath), IconError)
Dear Vera,Vera wrote:but it wouldn't work for me on Linux (Suse 11.1) with all pb-versions down to 4.31. (???)
Code: Select all
If gtk_window_set_icon_from_file_(WindowID(0), @IconPath, IconError) = #False
MessageRequester("Error", "Icon file couldn't be found!")
EndIf