• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

Change Icon of Executable

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
Mortaza Doulaty
Asked:
Mortaza Doulaty
  • 3
  • 3
  • 2
2 Solutions
 
JimBeveridgeCommented:
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
 
Mortaza DoulatyAuthor Commented:
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
 
lucky_jamesCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
JimBeveridgeCommented:
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
 
Mortaza DoulatyAuthor Commented:
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
 
JimBeveridgeCommented:
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
 
Mortaza DoulatyAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now