Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Change Icon of Executable

Posted on 2010-11-17
Medium Priority
Last Modified: 2012-05-10
I have two executable files, file A and file B. I want to have a piece of code in C or C++ that reads the icon of file A and change the icon of file B to that icon. (I'm not using MFC, nor .NET, just pure MS Visual C++ Windows API's)
Question by:Mortaza Doulaty
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2

Expert Comment

ID: 34161958
See http://www.codeproject.com/KB/cpp/dynares.aspx

The article is titled "Reading and Using", but there is a discussion of writing resources in the text. The related Windows API functions for writing are BeginUpdateResource, UpdateResource, and EndUpdateResource.

I realize you asked for code, but if you only need to do this a few times, you can use a tool like "Resource Hacker".
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 34161978
Thanks for your quick reply. I've already used "Resource Hacker", but I need a piece of code. I'm not sure what to do with resources, in case of using and changing icons.

Assisted Solution

lucky_james earned 600 total points
ID: 34164179
PMString ucPath("C:\\path\\to\\file.extension");
SHFILEINFO info;    

::SHGetFileInfo(ucPath.GrabTString(), FILE_ATTRIBUTE_NORMAL, &info, sizeof(info),
ICONINFO stIconInfo;
GetIconInfo(s_sfi.hIcon, &stIconInfo);
HBITMAP hBmp = stIconInfo.hbmColor;
DestroyIcon(s_sfi.hIcon) ;
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

ID: 34165593

Your solution and the articles you referenced will not work. SHGetFileIcon throws away all sizes and formats except one and you lose the information about the format of the resource itself.

See my recent blog entry as well as the blog entry by Raymond Chen referenced in the comments of my post:

LVL 12

Author Comment

by:Mortaza Doulaty
ID: 34178673
Thanks for your reply. Could you please describe more about s_sfi
What is this, where it is declared and initialized. It seems that you've copied and pasted the code from somewhere and you forget to include a reference to that variable. Thanks.

I've read them, so what to do next?

Accepted Solution

JimBeveridge earned 1400 total points
ID: 34178783
If you read my blog entry I mentioned, then you know the question you are asking is not simple. I'm an expert in Windows SDK development. To write the routine you want, including researching it, writing unit tests, packaging it for reuse, and documenting it is easily a day of work. Anything less than that will probably fail when put into use.

Even the requirements are not entirely straightforward... Does it have to support PNG icons? 64-bit? 16-bit?

I'm obviously not going to do that much work for 500 points. If the information I've provided you isn't enough, then you should hire a C++/SDK expert to do the development work for you.
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 34178796
Thanks for your quick reply. I've already read your blog entry. I've used ResourceHacker before, I thought I could find some piece of source code to do that job for me easily.
About requirements, I'm not sure yet, ResourceHacker works just fine for me, I think it supports PNG, 64-bit and 16 bit altogether.

I'll wait for other experts to post their comments, after some days, I'll finalize this question.

Thanks for your support!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question