Thread: Well

  1. #1
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412

    Well

    Icons are kicking my arse. I am using Borlands Free 5.5.1 command line compiler and making a console application.

    I figured out how to make a .res file and after searching all over the place, found this script...

    #define MYICON 100
    MYICON ICON "file.ico"

    So I put that in there with my filename and used brcc32.exe to make a .res file from the .rc file.

    I then put #include "myres.res" in my file that holds main, but it wouldn't compile with it in there. So I took that out...

    So I have an executable and a .res file. I tried using ilink32 myexe myres and that didn't work. I got an error stating that my executable contains an invalid OMF record, type 0x4d... whatever the hell that means.

    I tried looking (searching) at this site and many others, and I am still having no luck finding how to do this.

    If you know how... can you help me before I take a bat to my laptop. I am going to keep searching... but it is looking grimm. I found a million and a half ways to make an Icon and bits and pieces of how to include one.

    Thanks
    Blue

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    mfc or api?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    doh! borland! not likely to be mfc so here goes...

    in msvc we have a resource script that looks like this....

    Resource.h
    #define IDI_ICON 101

    YourProg.rc
    #include "Resource.h"
    #include "Afxres.h"
    IDI_ICON ICON DISCARDABLE "file.ico"

    then in your program....
    #include "windows.h"
    #include "Resource.h"
    .
    .
    .
    .
    WNDCLASS YourWndClass;
    .
    .
    .
    YourWndClass.hIcon=LoadIcon (hInstance,MAKEINTRESOURCE(IDI_ICON));
    .
    .


    Thats how its done on msvc. Borland is probably similar.Consult your helpfiles for resource scripts details.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    ralphw
    Guest

    Wink

    bcc32 -c -tW file.c

    ilink32 -aa -c -x -Gn file.obj c0w32.obj,file.exe,,import32.lib
    cw32.lib,,myres.res

    The above two lines at the command prompt should get you to heaven...

  5. #5
    ralphw
    Guest

    if a console app, tW should be tWC

    Sorry..

  6. #6
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Thanks... I am going to play around with that.

    I got it to work by cheating. I got a resource hacker and got the icons in that way.

    Still it will be good for me to learn the right way.
    Blue

  7. #7
    ralphw
    Guest

    Unhappy may still have told you wrong...

    maybe the following two lines will get an icon resource to link in with a console application...

    bcc32 -c -tWC file.c

    ilink32 -aa -c -x -Gn file.obj c0x32.obj,file.exe,,import32.lib
    cw32.lib,,myres.res

    i believe that the obj file for main is c0x32.obj. WinMain is c0w32.
    hope this works for you...

  8. #8
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    can any of these switches be passed through the compiler. The compiler has the linker retrieve all of the necessary .obj files... then I wouldn't have to specify.

    i.e.

    bcc32 -c file1.cpp

    bcc32 -c file2.cpp

    bcc32 file1.obj file2.obj


    If I could do something like

    bcc32 -tWC file1.obj file2.obj myres.res

    it would make it soooo much easier. But I bet that I can't, huh.

    Are you showing the compile/link technique utilizing the code that stoned coder showed?
    Blue

  9. #9
    ralphw
    Guest

    bcc32 -tWC file1.obj file2.obj myres.res

    I have never gotten the above to work for me either, and it truly is ashamed that you can't. Your right, it would make things so much easier...

    I have not tried what Stoned_Coder shows to do...

  10. #10
    ralphw
    Guest

    Smile

    WAIT... excuse me, I'm kind of sleepy, yes exactly as Stoned_Coder shows...

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    I'm using mingw, its a free comandline based thing as well, and to include a resource file you have to use a different program to compile it. That then gives you an object file which you link to the rest of your program.

  12. #12
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Or why not just:

    HICON mico = (HICON)LoadImage("mico.ico", IMAGE_ICON, height, width, LR_LOADFROMFILE);

    ...and be done with it instead of messing with resource files??
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  13. #13
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    if you do the loadfromfile does it require that the .ico icon file be with the executable.

    I have seen some people have it like that. By utilizing a resource file, it is somehow stored within the executable.
    Blue

  14. #14
    Registered User
    Join Date
    Dec 2001
    Posts
    108

    Lightbulb Try this...

    brcc32 icon.rc

    bcc32 -c tWC -OS -5 file.cpp

    ilink32 -ap -c -x -Gn file.obj c0x32.obj,file.exe,,import32.lib cw32.lib,,icon.res




    Hello Betazep, I looked at this problem, and think this will surely work. The 3 lines above entered sequentially at the DOS prompt should build a console executable with a custom icon attached to it.

    In the icon.rc file I placed this line: 500 ICON "icon.ico"

    I DID NOT #include "icon.rc" in file.cpp, that was not neccessary.

    Strangely, after linking, the exe file was still diplaying the standard application icon, I had to press the F5 key to refresh the screen to display the exe file with the custom icon that was linked in from the icon.res file.

    Two of the switches passed to bcc32.exe ( -OS -5 ) may not be neccessary, -5 is for Pentium 80586 CPU specific instructions.

  15. #15
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Yeah that worked. Thanks for your help. I had other .obj files to link in with it so I just put them in there with 'file.obj.' Worked quite nicely.

    Once again thanks.

    This thread might make a good FAQ. Perhaps we should fill it up with other ways to include an icon with other compilers.

    Stoned Coder, do you feel up to writing how to do it MFC with the MSVC++ compiler. If others have a solid comments on adding an icon to an executable, get them in here.

    I will ask the mods to FAQ this once we get more info.

    Thank you everyone for you help. I learned a lot.
    Last edited by Betazep; 02-03-2002 at 04:12 PM.
    Blue

Popular pages Recent additions subscribe to a feed