Solved

Change Icon of Executable

Posted on 2010-11-17
8
393 Views
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)
0
Comment
Question by:Mortaza Doulaty
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:JimBeveridge
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".
0
 
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.
0
 
LVL 7

Assisted Solution

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

::SHGetFileInfo(ucPath.GrabTString(), FILE_ATTRIBUTE_NORMAL, &info, sizeof(info),
    SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON);
ICONINFO stIconInfo;
GetIconInfo(s_sfi.hIcon, &stIconInfo);
HBITMAP hBmp = stIconInfo.hbmColor;
DestroyIcon(s_sfi.hIcon) ;
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 34164192
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 7

Expert Comment

by:JimBeveridge
ID: 34165593
lucky_james:

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:

http://qualapps.blogspot.com/2010/11/extracting-icons-with-windows-sdk.html
0
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 34178673
lucky_james:
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.

JimBeveridge:
I've read them, so what to do next?
0
 
LVL 7

Accepted Solution

by:
JimBeveridge earned 350 total points
ID: 34178783
Mortaza_doulaty:
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.
0
 
LVL 12

Author Comment

by:Mortaza Doulaty
ID: 34178796
JimBeveridge:
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!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now