Solved

Property Sheet icon w/Alt-Tab

Posted on 1997-08-01
4
710 Views
Last Modified: 2013-11-20
I want to assign an icon 32x32 to a property sheet. The property sheet is the main window of the application. I am using VC++4.2 on NT4.0.

I defined the following:

class CAdSheet : public CPropertySheet
...
CAdSheet addlg();
m_pMainWnd = &addlg;

HICON secIcon = AfxGetApp()->LoadIcon(IDI_MAINICO);
HWND hWndParent = (HWND)this;
SendMessage(hWndParent,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)secIcon);
addlg.m_psh.dwFlags |= PSH_USEHICON;
addlg.m_psh.hIcon = secIcon;

nResponse = addlg.DoModal();
...

The icon IDI_MAINICO is assigned to my property sheet. It appears in the upper left of the window, in the taskbar and in the Explorer as both small and large icons. But, when I use Alt-Tab, the icon is the Windows flag. I would like to have the IDI_MAINICO appear when I Alt-Tab. Is there a way to do this or is this the only way a dialog can appear in that situation?
0
Comment
Question by:miker080197
  • 2
4 Comments
 
LVL 4

Expert Comment

by:AVaulin
ID: 1302980
Handle WM_PAINT message in  like this:

void CAdSheet::OnPaint()
{
 if( IsIconic() )
 {
  CPaintDC dc(this);
  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
 // Center icon in client rectangle
   int cxIcon = GetSystemMetrics(SM_CXICON);
   int cyIcon = GetSystemMetrics(SM_CYICON);
   CRect rect;
   GetClientRect(&rect);
   int x = (rect.Width() - cxIcon + 1) / 2;
   int y = (rect.Height() - cyIcon + 1) / 2;
   dc.DrawIcon(x, y, m_hIcon);
 }
 else CDialog::OnPaint();
}

This is a fragment from dialog based application created by AppWizard.
0
 

Author Comment

by:miker080197
ID: 1302981
Pardon the 'F'. I placed the code in the CAdSheet class, but I am still getting the Windows Flag when I Alt-Tab. CAdSheet is a class defined in CAdSheet.h and .cpp and included in the main program. The code above is called in the InitInstance function of the main program. The class in the main program is: "class CSecAdminApp : public CWinApp". I appreciated your earlier response. Thanks.
0
 
LVL 8

Accepted Solution

by:
gelbert earned 200 total points
ID: 1302982
You can use SetIcon is an MFC 4.0 wrapper for SendMessage(WM_SETICON...), and the Boolean argument is FALSE if you want to set the small (16´16) icon or TRUE if you want to set the big (32´32) one. According to the Win32® API documentation, the big icon is used when the window is minimized and the small one goes in the window title but I'm here to say it ain't so! Windows 95 uses the small icon in both places, but it does use the large icon when you task-switch with Alt-TAB.

BOOL CMyDialog::OnInitDialog()
{
   SetIcon(AfxGetApp()->LoadIcon(IDI_MYDIALOG_SM),
           FALSE);
   SetIcon(AfxGetApp()->LoadIcon(IDI_MYDIALOG_LG),
           TRUE);
   return CDialog::OnInitDialog();
}
 
You can find a good sample in MSJ 1996 April in section "C/C++ Q&A"
Check www.microsoft.com/msj

0
 

Author Comment

by:miker080197
ID: 1302983
Thanks.
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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

861 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

23 Experts available now in Live!

Get 1:1 Help Now