Discussion:
setting the icon for fltk windows
Steve
2005-10-12 21:40:44 UTC
Permalink
Hi,

I would like to set the icon for my FLTK application. That is, the icon that appears on the desktop. Now it is just a default windows icon, but I would like to change that in a custom designed icon. Going trough the FLTK documentation I cannot find any way to set this icon. Is there anybody that knows how to do this ? I'd really appreciate it.

Thanks,

Steve.
Greg Ercolano
2005-10-12 23:41:40 UTC
Permalink
Post by Steve
Hi,
I would like to set the icon for my FLTK application. That is, the icon that appears on the desktop. Now it is just a default windows icon, but I would like to change that in a custom designed icon. Going trough the FLTK documentation I cannot find any way to set this icon. Is there anybody that knows how to do this ? I'd really appreciate it.
You can link it into your application.

Assuming you've made an foo.ico file already inside Visual Studio,
the steps are:

1) Create a one line 'foo.rc' text file
2) Use the Visual Studio 'resource compiler' to convert foo.rc -> foo.res
3) Link the foo.res file into your app

These three steps can be done in a Makefile with these commands:

echo 0 ICON "foo.ico" > foo.rc
rc -r foo.rc
cl foo.obj /link foo.res [..]

Note the quotes must appear in the file; the above commands are assumed
to be run in DOS, where 'echo' passes the ""s verbatim, as opposed to
a BASH or CSH oriented makefile, in which case you'd have to quote the quotes.

I think there's also a way to set the icon within your code
using Microsoft specific commands, but the above avoids all that
by doing it all at the link level. I think approach also helps
Explorer show your icon in the file browser.
Anonymous
2005-10-13 00:23:41 UTC
Permalink
Thanks ! I can now see the right icon in the explorer. However, the icon displayed in the upper left corner of the window when the app is running is still the old default icon. Is there any way I can change this icon as well ?
One more question. My app also has to run under linux and I would also like to get the same icon displayed on the linux version. Any suggestions on how to do this ? Thanks in advance.

Steve.
Post by Greg Ercolano
Post by Steve
Hi,
I would like to set the icon for my FLTK application. That is, the icon that appears on the desktop. Now it is just a default windows icon, but I would like to change that in a custom designed icon. Going trough the FLTK documentation I cannot find any way to set this icon. Is there anybody that knows how to do this ? I'd really appreciate it.
You can link it into your application.
Assuming you've made an foo.ico file already inside Visual Studio,
1) Create a one line 'foo.rc' text file
2) Use the Visual Studio 'resource compiler' to convert foo.rc -> foo.res
3) Link the foo.res file into your app
echo 0 ICON "foo.ico" > foo.rc
rc -r foo.rc
cl foo.obj /link foo.res [..]
Note the quotes must appear in the file; the above commands are assumed
to be run in DOS, where 'echo' passes the ""s verbatim, as opposed to
a BASH or CSH oriented makefile, in which case you'd have to quote the quotes.
I think there's also a way to set the icon within your code
using Microsoft specific commands, but the above avoids all that
by doing it all at the link level. I think approach also helps
Explorer show your icon in the file browser.
Steve
2005-10-13 00:24:35 UTC
Permalink
Post by Anonymous
Thanks ! I can now see the right icon in the explorer. However, the icon displayed in the upper left corner of the window when the app is running is still the old default icon. Is there any way I can change this icon as well ?
One more question. My app also has to run under linux and I would also like to get the same icon displayed on the linux version. Any suggestions on how to do this ? Thanks in advance.
Steve.
Post by Greg Ercolano
Post by Steve
Hi,
I would like to set the icon for my FLTK application. That is, the icon that appears on the desktop. Now it is just a default windows icon, but I would like to change that in a custom designed icon. Going trough the FLTK documentation I cannot find any way to set this icon. Is there anybody that knows how to do this ? I'd really appreciate it.
You can link it into your application.
Assuming you've made an foo.ico file already inside Visual Studio,
1) Create a one line 'foo.rc' text file
2) Use the Visual Studio 'resource compiler' to convert foo.rc -> foo.res
3) Link the foo.res file into your app
echo 0 ICON "foo.ico" > foo.rc
rc -r foo.rc
cl foo.obj /link foo.res [..]
Note the quotes must appear in the file; the above commands are assumed
to be run in DOS, where 'echo' passes the ""s verbatim, as opposed to
a BASH or CSH oriented makefile, in which case you'd have to quote the quotes.
I think there's also a way to set the icon within your code
using Microsoft specific commands, but the above avoids all that
by doing it all at the link level. I think approach also helps
Explorer show your icon in the file browser.
Greg Ercolano
2005-10-13 02:11:36 UTC
Permalink
Post by Anonymous
One more question. My app also has to run under linux and I would also like to get the same icon displayed on the linux version. Any suggestions on how to do this ? Thanks in advance.
I don't know that one offhand.

I think there's some kind of standard among the linux window managers
for this, but I don't think it's something you can do to your executable,
or in fltk when it comes to the item showing on the desktop correctly.

I /think/ a resource file of some kind needs to be 'registered' somewhere
in the file system. Umm... I think this is the doc to look at, not sure:
http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

Others welcome to weigh in on this..
George Garvey
2005-10-13 08:02:09 UTC
Permalink
Post by Greg Ercolano
Post by Anonymous
One more question. My app also has to run under linux and I would also
like to get the same icon displayed on the linux version. Any suggestions
on how to do this ? Thanks in advance.
I don't know that one offhand.
I use the MSW icon in the resources of the executable. I wanted to
use an XPM on Linux.
For Linux, this is what I do. It is code fragments, and won't
compile.

#include <FL/Fl.h>
#include <FL/Fl_Pixmap.h>
#include <FL/x.h>
/*
* We need to do this stupid Bool trick because of somebody's
* stupid database headers. When pointed out to the vendor, their
* response was: "Well, X11 did it, too," or something like that.
*/
#undef Bool
#define Bool int
#include <xpm.h>
#undef Bool
/*
* This is the WM icon, in XPM format
*/
#ifdef __unix__
# include <inX_icon.xpm>
#endif
/*
* NOTE: this is global in our code, because it is used for several
* purposes, one of which is the WM icon (at least on UNIX).
*/
#ifdef __unix__
Pixmap Icon_ID;
#else
HICON Icon_ID;
#endif
/*
* This is a class that encapsulates the main window for a number
* of our programs. It is where the WM icon is set. We don't write
* for Macs yet, so it is either X11 or MSWindows.
*/
inXMain::inXMain(inXDB *&data_base, const char *title,
const char *program_class, const char *icon_label,
cnst char *icon_name, const bool is_inX_Services_program,
const int extra_width
)
: Fl_Window(520 + extra_width, 210, title),
Menu(0, 0, 520 + extra_width, 30),
Box(5, 35, 510 + extra_width, 140),
Status_Line(5, 180, 510 + extra_width, 25),
Height_10(0),
Trx(0),
Data_Base(data_base),
Children(0) {
xclass(program_class);
#ifdef __unix__
if (! Icon_ID) {
fl_open_display();
XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display),
const_cast<char **>(inX_icon),
&Icon_ID, 0, 0
);
}
icon(reinterpret_cast<char *>(Icon_ID));
#else
if (! Icon_ID) {
Icon_ID = Get_icon_from_resource(icon_name);
}
if (Icon_ID) {
icon(reinterpret_cast<char *>(Icon_ID));
}
#endif
iconlabel(icon_label);
/*
* The rest of the constructor deals with our standard main
* window; not very interesting.
*/
}

Loading...