Icon on title bar?

Just starting out? Need help? Post your questions and find answers here.
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Icon on title bar?

Post by gedumer »

How do you put an icon on the left side of the title bar in Linux and Win32 without using the API?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Menu Compiler > Compiler Options > [√] Use Icon > Browse
oh... and have a nice day.
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Post 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?
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Post by Arctic Fox »

He is refering to the PureBasic IDE (the Compiler Options dialog).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

indeed.
oh... and have a nice day.
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

did you activate the checkbox?

with checkbox off, the field is grayed out in the windows version, too.
oh... and have a nice day.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post 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
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

This should be added to feature request as a built-in command SetWindowIcon - like SetWindowTitle.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Post 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.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Icon on title bar?

Post 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
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: Icon on title bar?

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

Re: Icon on title bar?

Post 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.
Post Reply