Page 1 of 2

Icon on title bar?

Posted: Tue Jun 16, 2009 11:03 pm
by gedumer
How do you put an icon on the left side of the title bar in Linux and Win32 without using the API?

Posted: Tue Jun 16, 2009 11:07 pm
by Kaeru Gaman
Menu Compiler > Compiler Options > [√] Use Icon > Browse

Posted: Tue Jun 16, 2009 11:33 pm
by gedumer
Kaeru Gaman wrote:Menu Compiler > Compiler Options > [√] Use Icon > Browse
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?

Posted: Tue Jun 16, 2009 11:37 pm
by Arctic Fox
He is refering to the PureBasic IDE (the Compiler Options dialog).

Posted: Wed Jun 17, 2009 1:39 am
by Kaeru Gaman
indeed.

Posted: Wed Jun 17, 2009 1:41 am
by gedumer
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.

Posted: Wed Jun 17, 2009 1:44 am
by Kaeru Gaman
did you activate the checkbox?

with checkbox off, the field is grayed out in the windows version, too.

Posted: Wed Jun 17, 2009 3:58 am
by lexvictory
Linux does not support icons for exe's the way Windows does, hence why you can't use that option on Linux.
GTK API would be needed. I'm sure I've seen samples of it somewhere here on the forum...

@Kaeru: even the checkbox is grayed on linux if I recall correctly.

Posted: Wed Jun 17, 2009 9:35 am
by Trond

Posted: Wed Jun 17, 2009 11:51 am
by Shardik
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

Posted: Wed Jun 17, 2009 3:20 pm
by DoubleDutch
This should be added to feature request as a built-in command SetWindowIcon - like SetWindowTitle.

Posted: Wed Jun 17, 2009 3:52 pm
by gedumer
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
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.

Re: Icon on title bar?

Posted: Wed Sep 15, 2010 11:02 pm
by Vera
Hello Shardik,

today I've come to share your help ~ Image
but it wouldn't work for me on Linux (Suse 11.1) with all pb-versions down to 4.31. (???) until I exchanged the WindowID(0) by an enumerated constant.
Strange this makes a difference ~ but this way the icon shines from the title to me ;)

thanks ~ Vera

Re: Icon on title bar?

Posted: Wed Sep 15, 2010 11:29 pm
by cas
Shardik wrote:

Code: Select all

gtk_window_set_icon_from_file_(WindowID(0), PeekS(@IconPath), IconError)
Why PeekS()? IconPath is already string variable.

Re: Icon on title bar?

Posted: Thu Sep 16, 2010 10:32 am
by Shardik
Vera wrote:but it wouldn't work for me on Linux (Suse 11.1) with all pb-versions down to 4.31. (???)
Dear Vera,

I have tested my above example on OpenSUSE 11.1 with 4 freshly installed PB versions
(4.20, 4.31, 4.41 and 4.51) and discovered that only 4.20 doesn't display the CD icon.
This is caused by a rename in the distributed PB tgz archive of the sub folder /data
from 4.20 to /Data in 4.31 and subsequent versions. Since Linux is case sensitive, this
change of one character from lowercase to uppercase had the effect that the icon file
couldn't be found. Therefore everyone should improve my code example by testing the
return value of the GTK function:

Code: Select all

If gtk_window_set_icon_from_file_(WindowID(0), @IconPath, IconError) = #False
  MessageRequester("Error", "Icon file couldn't be found!")
EndIf
Your described effect with not being able to use WindowID(0) I can't confirm nor explain...


@cas,

you are right, the PeekS(@IconPath) is not necessary. Just using "@IconPath" is sufficient.
Thank you for your hint.