Adding an icon to FB app

New to FreeBASIC? Post your questions here.
festivus
Posts: 7
Joined: Sep 19, 2005 16:51

Adding an icon to FB app

Postby festivus » Sep 19, 2005 17:00

Hi all!! I just created my first small console app in free basic!

Is it possible to add an icon to the exe file and how do I do it? I tried going to the properties and doing it there, but no luck.
MichaelR
Posts: 21
Joined: Aug 21, 2005 6:54
Location: Georgia, USA
Contact:

Postby MichaelR » Sep 19, 2005 18:12

You need to have a resource script (RC) file, then add an icon entry to the script. It needs to be the lowest index I belive in the script as windows will use that as the "default" icon.

~~~~~~~~~~~

In resource.rc

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON "main.ico"

~~~~~~~~~~~

In Resource.bi

#define IDI_MAIN 101


You then compile the rc file in with your application and the icon should show up in explorer.
festivus
Posts: 7
Joined: Sep 19, 2005 16:51

Postby festivus » Sep 20, 2005 0:03

Thanks MichaelR!!! I got it to work the first time! Thanks for the help. Now I can give all of my old apps icons too..

One other thing though, What exactly does a .bi file do?

Thanks again
jofers
Posts: 1525
Joined: May 27, 2005 17:18
Contact:

Postby jofers » Sep 20, 2005 0:23

It's nothing different than a .bas file, it's just an extension. But it's very convenient and effiencient to put all your delcare subs and declare functions into a "header" file, because then you can "#include" that file when you compile your program into a library and still be able to use all the routines.

So in basic, these files traditionally have a ".bi" extension.
festivus
Posts: 7
Joined: Sep 19, 2005 16:51

Postby festivus » Sep 20, 2005 0:35

ok...I think I understand. So technically I could add the icon without th .bi file if I call use the code below at the beginning of my .bas file. Am I right?

#define IDI_MAIN 101

Thanks.
Nodtveidt
Posts: 484
Joined: Aug 24, 2005 0:32
Location: Camuy, PR
Contact:

Postby Nodtveidt » Sep 20, 2005 2:37

You can do it even simpler than that...this is how I set my RC file for a default icon:

1 ICON myicon.ico

and you don't need any .bi or any #defines for it...

fbc myprog.bas myscript.rc

and the icon will show up just fine. :)
festivus
Posts: 7
Joined: Sep 19, 2005 16:51

Postby festivus » Sep 20, 2005 12:08

Thank you all for all of your help and quick responses!!
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Postby Clyde » Feb 08, 2006 16:30

Great stuff cant wait to try it out. can i ask, how do you compile the resource file into the application please dudes?

Is it something you do in the code, or with the compiler settings. Im using FBIDE too.

Cheers and many thanks.
Clyde :)
jofers
Posts: 1525
Joined: May 27, 2005 17:18
Contact:

Postby jofers » Feb 08, 2006 16:58

Compile it like this:

Code: Select all

fbc program.bas myresource.rc


And fbc will handle it for you.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Postby Clyde » Feb 08, 2006 20:00

ta, tried that in FBIDE with:

in the compiler command option.

<fbc> <filename> -s gui addicon.rc

But told me that it could not open source file "addicon.rc"
Obj File not made.
Fragmeister
Posts: 545
Joined: Nov 08, 2005 14:36

Postby Fragmeister » Feb 08, 2006 21:28

For the icon to be displayed in the titlebar of the program, you must use a different icon name. For example:
this would be the .rc file:

Code: Select all

FB_PROGRAM_ICON ICON myicon.ico


then to compile it, you would use the procedure described above.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Postby Clyde » Feb 08, 2006 23:50

Ok this is what Ive done for adding an icon to an fb exe.

In a text file called AddIcon and saved as .rc

FB_PROGRAM_ICON ICON nameoffile.ico

Then in the first option box ( Compiler Command ) under view-settings-FREEBasic

<fbc> <filename> -s gui addicon.rc


Then on F9, compile and run. it gives the failed error:

unable to open source file "addicon.rc"
Obj File not made.



In the mainprogram.bas source, i have put #define IDI_MAIN 101


Thankyou,
Clyde.
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Postby tunginobi » Feb 08, 2006 23:59

The current directory deal rears its head once again. Have you tried it on the command line, in the same directory as your project? Have you tried double-clicking on the main project file, rather than using the Windows shortcut?

If it works, that's the problem. If not... I haven't a clue.
Clyde
Posts: 235
Joined: Jan 21, 2006 14:03
Contact:

Postby Clyde » Feb 09, 2006 0:09

Interesting :)

Not tried it in the command line yet, will do that now mate.
And Not too sure what you mean on double clicking the main project file.

Btw, if this is successful for me. do i have to keep recompiling the exe with the icon bits again and again. or is the resource set to it from doing it the once.

Just going to try the command line.

Cheers,
Clyde
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Postby tunginobi » Feb 09, 2006 0:12

Clyde wrote:And Not too sure what you mean on double clicking the main project file.

Well, only if you've associated .bas files to FBIde in Windows like I have.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 12 guests