Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Property Sheet icon w/Alt-Tab

Posted on 1997-08-01
4
Medium Priority
?
728 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
[X]
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
  • 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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