• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

Property Sheet icon w/Alt-Tab

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
miker080197
Asked:
miker080197
  • 2
1 Solution
 
AVaulinCommented:
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
 
miker080197Author Commented:
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
 
gelbertCommented:
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
 
miker080197Author Commented:
Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now