Changing icons in dialog box

Posted on 1999-08-31
Medium Priority
Last Modified: 2013-11-20
Is it possible to change an icon in a dialog box when a program is running? I have an icon to represent a switch that the user can turn on or off and I would like to update the icon to represent these states.
Thanks in advance,
Question by:Sman
LVL 23

Expert Comment

ID: 1953709
Call CWnd::SetIcon.

SetIcon(hIcon, TRUE);    // Set big icon
SetIcon(hIcon, FALSE);    // Set small icon

Author Comment

ID: 1953804
With CWnd::SetIcon I am able to change the main icon in the top left corner of the dialog box, but how/ where do I use it to set other icons within my dialog box?
Thanks again,

Expert Comment

ID: 1953897
Call SetIcon() on your dialog;s childs
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

LVL 23

Expert Comment

ID: 1955075
Use ClassWizard to associate the static control with a CStatic member variable and call the following member function.

HICON SetIcon( HICON hIcon );

Author Comment

ID: 2035832
The only reason that I rejected your answer is that I dont know how to implement it. I have an icon in my dialog box and I have associated it with a CStatic member variable. I then created another icon but I don't know how to replace the first icon with this new one.

I will offer you more points for your answer,
Thank you!
LVL 23

Expert Comment

ID: 2037457
What do you mean by replacing it? You can associate it with another CStatic member variable.

Accepted Solution

AAB earned 200 total points
ID: 2121533
first you must cteate an icon by resource icon editor with specific ID in the example I create icon with ID = IDI_RIGHT

second :
in the class add :
HICON hIcon;

third in your implementation first you must need to handle the icon like this "load"
hIcon = AfxGetApp()->LoadIcon (IDI_RIGHT);

finaly to chang the icon :

by this example you change the dialog box icon.
to change the CStatic member variable.
you must create control for it by ClassWizard.
goto ClassWizaed and choose the member variable tab.
then make sure that u have choose the dialog name class under class name, choose the ID for the static control and then press add variable.
another dialog will appear ---> write the name of your
variable example "m_editCtrl"  , then choose under catogory --> control
then press ---> Ok .
this step create a control for static control.

in any part of your code you can in the class dialog and after init the hIcon , you can add

try it
Good Luck.


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

607 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