Solved

Property Sheet icon w/Alt-Tab

Posted on 1997-08-01
4
706 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 150
Process filename extension 3 158
sum13 challenge 24 78
withoutTen challenge 14 88
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 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

15 Experts available now in Live!

Get 1:1 Help Now