Page 1 of 2

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.

Re: Icon on title bar?

Posted: Thu Sep 16, 2010 3:29 pm
by freak
If you use PB 4.40 or newer, you can just load the image normally with PB commands, and then do:

Code: Select all

gtk_window_set_icon_(WindowID(#YourWindow), ImageID(#YourImage))
Or, if you want it to apply to all new windows, do:

Code: Select all

gtk_window_set_default_icon_(ImageID(#YourImage))
Just keep in mind that PB/Linux doesn't load *.ico files. The best is to use png's with alpha channel (don't forget UsePNGImageDecoder() ;))

Re: Icon on title bar?

Posted: Thu Sep 16, 2010 7:07 pm
by Vera
Hello Shardik,

thanks for regarding my hint. As for the path - that was the first I checked, but only for the first version.
I tested it all again (several 100 times) and it's a case of driving nuts, as this time it wouldn't work with the constant until I switched back to the first code. There again it only worked once then 10 times not, then again .... the same with the world.png. But today I saw that in all cases the image is always displayed on the taskbarbutton [standart hidden on my OS] but not necessarily on the titlebar.

I have no clue why it behaves like this. I made another 10 passes of 60 compilations (devided by minimal changes) and it wouldn't even show up in each circle (1 time each in 3 passes, 2 times in 2 passes and 4 times in 1 pass).

As the application where I use your method only seldom lacks to display the icon on compilation it might be due to the shortness of the code snippet. Maybe the window is already final build up before the image can be supplied?

I would conclude it works fine (except for this special incidence) and have an eye on it when I'll apply it in coming usages.

greetings ~ Vera