Solved

Changing the application icon on the fly

Posted on 2002-07-22
7
386 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

14 Experts available now in Live!

Get 1:1 Help Now