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

x
?
Solved

Changing the application icon on the fly

Posted on 2002-07-22
7
Medium Priority
?
404 Views
Last Modified: 2008-02-01
I'm writing a simple SDI MFC application. The application is loading in the InitApplication (loading IDR_MAINFRAME by default) when registering the window class. I would like to change that icon later in the execution because I don't have it at that time. Later, in the InitInstance(), I load a resource DLL and then I would be ready to change the icon of my application.

How can I change the icon of my application after the InitApplication()?
0
Comment
Question by:mahtieubrault
[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
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7170859
HICON hNewIcon = LoadIcon(...);
::SetClassLong(m_hYourWnd, GCL_HICON, (LONG)hNewIcon);
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7171552
Since you are using MFC you could also use:

AfxGetMainWnd()->SetIcon( ::LoadIcon(...), FALSE );
0
 

Author Comment

by:mahtieubrault
ID: 7171713
Thanks guys but there is one last thing. The icon I use has a lot of formats (16x16,32x32,48x48,64x64). If I put the icon as the regular MyApp.ico in the res directory, the icon is displayed fine (the 16x16 version in the taskbar). But if I use one of your calls, it seems like it uses a bigger icon and shrinks it. That looks ugly.

I tried
AfxGetMainWnd()->SetIcon( ::LoadIcon(...), FALSE )
AfxGetMainWnd()->SetIcon( ::LoadIcon(...), TRUE )
but it doesn't change anything.

btw, it workd fine for a SDI app, the icon glitch is only with my dialog-based application.
0
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.

 
LVL 9

Expert Comment

by:BeyondWu
ID: 7173182
Make another call,
::SetClassLong(m_hYourWnd, GCL_HICONSM, (LONG)hNewIcon);
0
 

Author Comment

by:mahtieubrault
ID: 7174123
Doing the two calls with SetIcon (big and small) or the two calls with SetClassLong (big and small) don't change anything. The application icon in the taskbar is still blurry like it was srunk from another format that 16x16. In my SDI application it works fine!
0
 
LVL 8

Accepted Solution

by:
fl0yd earned 800 total points
ID: 7174236
I guess I found a solution: Use ::LoadImage(...) instead of ::LoadIcon(...). With ::LoadImage(...) you can specified the desired width and height of the icon to load. You can find further information here:
http://search.microsoft.com/gomsuri.asp?n=4&c=rp_Results&siteid=us/dev&target=http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/loadimage.asp
0
 

Author Comment

by:mahtieubrault
ID: 7174293
Thanks it works good. I have to do one LoadImage (16x16) for the icon in the taskbar and one LoadImage (32x32) for when I do ALT-Tab.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 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