Solved

Change Icon of Executable

Posted on 2010-11-17
8
428 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
[X]
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
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
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!

 
LVL 7

Expert Comment

by:lucky_james
ID: 34164192
0
 
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

Technology Partners: 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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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