Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How do you add icon in Visual Studio?

Author
Message
C4H9Li
10
Years of Service
User Offline
Joined: 13th Apr 2014
Location: VIC, Australia
Posted: 15th Apr 2014 01:11
I made a simple game using the template(is that called tier 2?) in visual studio. After I packed the resources and the program together using related software, It works on other computers as well.

The thing left is to add an icon to the exe file. There is already a template.ico in my solution(same as the original template) but the icon isn't displayed on the executable file. Just want to know how to specify an icon... Could someone give a clue? Thanks

Sorry?
C4H9Li
10
Years of Service
User Offline
Joined: 13th Apr 2014
Location: VIC, Australia
Posted: 15th Apr 2014 05:08
I checked the properties of "template.ico" written "does not participate in build". After changing it into "Resource", it turns out to be "1>template.ico : fatal error LNK1107: invalid or corrupt file: cannot read at...".

I've tried adding a res.rc file but it says cannot open file winres.h

Sorry?
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 15th Apr 2014 09:45
Hi C4H9Li. Yes the C++ template is what is called Tier 2.

As for the icon, I assume you added the icon to your project by right clicking on your project and going Add > Resource > Icon. If so, the icon should be in your res.rc file. Once you've done that, open the res.rc file in the viewer and look at what the icon has been called by VS. The name should look something like IDI_ICON1.

Once you've found this, go to the Core.cpp file in the template and search for the line

which is where the Windows class structure is created. Underneith that, you should see a series of assignments to wcex's components, setting up the window. You want to find where wcex.hIconSm is assigned to and replace that line with the following

of course with the IDI_ICON1 replaced with whatever name VS has given your icon.

I hope that helps. Let me know if you have any problems with it.

C4H9Li
10
Years of Service
User Offline
Joined: 13th Apr 2014
Location: VIC, Australia
Posted: 15th Apr 2014 10:15
Wow Thanks!

At the beginning I tired to add an resource but VS says "cannot find winres.h". Then I found winres.h and copied it into my solution folder and successfully add the ico resource and .rc file. After changing icon name, it works very well!

Cheers

Sorry?

Login to post a reply

Server time is: 2024-11-25 04:26:22
Your offset time is: 2024-11-25 04:26:22