简体   繁体   中英

How to apply compiler rules when resource.h or icon.ico should be included in the exe?

I am using #define and #ifndef to strip down the exe size, i noticed the resource.h and icon.ico files eat a lot of space, so i would like to not include those in my exe at all.

How do i add rule for this that obeys my #define commands ? I could edit the resource.h, but every time i change it, it would get overwritten by Visual Studio.

Edit: i dont know what is the correct name for these resource things, but my "resource.h" includes the window menu option stuff etc.

How much is "a lot of space" that you speak of?

resource.h is used for #define -ing constants that identify resources, eg they're just numbers. They shouldn't be a factor in executable size.

What is a factor in executable size is the resources that you embed in the executable, specified by a *.rc file. icon.ico takes up space in the *.exe because the compiler embeds the binary of the icon into the executable file itself. This icon is specified in an *.rc file that should be somewhere in your project.

You can choose to remove the icon from the *.rc file and store it separately from the *.exe file, but it's easier to just embed it into the executable. The information for defining menus, icons, dialogs, etc. has to be stored somewhere, after all.

Edit: You can have multiple resource files, so Visual Studio doesn't overwrite your directives. Refer to http://msdn.microsoft.com/en-us/library/6t3612sk(v=VS.80).aspx to see how Visual Studio handles multiple resource files. The section called " Using Multiple Resource Files in the Same Project " seems to be relevant to your problem.

In VS2010, properties for icon resources include an item "Condition" which is described as "Specifies the preprocessor symbol that determines the inclusion of the resource".

Can you upgrade?

The edit window is disabled though, you have to jump through some hoops to set the Condition. Right-click the resource and choose "Insert Copy", then you can set the condition, then delete the original unconditional icon.

Maybe this trick would work in VS2008 as well, don't have it installed on this computer so I can't test it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM