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
Solved

Property Sheet icon w/Alt-Tab

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 189
Process filename extension 3 194
java ^ examples 8 69
noX challenge 17 128
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 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