Modeless Dialog Iconic--but no icon!
Deepak Saxena -- Deepak_Saxena@ccm.ch.intel.com
Friday, June 21, 1996
[MSVC 4.1, WintNT351sp4]
How does one make a modeless dialog box display an icon when it is
minimized. I've tried calling SetWindow(), over riding
PreCreateWindow()...which was useless since dialogs don't call
precreatewindow! I haven't tried handling WM_PAINT and manually
blitting the icon, but I'd much rather not do that. If I minimize the
dlg, it just displays and empty grey square. But if I drag the icon, it
displays the app icon!
Deepak
I do not speak for Intel
Colin Angus Mackay -- colin.angus.mackay@dial.pipex.com
Monday, June 24, 1996
[Mini-digest: 2 responses]
> [MSVC 4.1, WintNT351sp4]
> How does one make a modeless dialog box display an icon when it is
> minimized. I've tried calling SetWindow(), over riding
> PreCreateWindow()...which was useless since dialogs don't call
> precreatewindow! I haven't tried handling WM_PAINT and manually
> blitting the icon, but I'd much rather not do that. If I minimize the
> dlg, it just displays and empty grey square. But if I drag the icon, it
> displays the app icon!
Try the following, this code is generated by the AppWizard when creating a dialog based application:
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
NOTES:
The icon "m_hIcon" is set up in the constructor with the line:
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
In the InitDialog function the following appears:
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
I hope this helps,
Colin.
-----From: David.Lowndes@bj.co.uk
Deepak,
Here's a couple of references that might help you:
KB article Q108936 "Using a Dialog Box as the Main Window of an Application"
Win32 Programmers Reference - "Custom Dialog Boxes"
If you do a search on MSDN for "DLGWINDOWEXTRA" or "DefDlgProc" you
should find plenty of articles giving information on how to do this.
Dave Lowndes
Bill Campbell -- bill_campbell@ppp.ablecom.net
Monday, June 24, 1996
[MSVC 4.1, WintNT351sp4]
How does one make a modeless dialog box display an icon when it is
minimized. I've tried calling SetWindow(), over riding
PreCreateWindow()...which was useless since dialogs don't call
precreatewindow! I haven't tried handling WM_PAINT and manually
blitting the icon, but I'd much rather not do that. If I minimize the
dlg, it just displays and empty grey square. But if I drag the icon, it
displays the app icon!
Deepak
I do not speak for Intel
This may Doit
In OnEraseBackground() | OnPaint()
if (IsIconic())
{
APP.LoadIcon( youricon );
CDC.DrawIcon( params );
}
BIll 3rd Wave
rick cameron -- rick_cameron@msn.com
Monday, July 22, 1996
Did you try CWnd::SetIcon?
- rick
> [MSVC 4.1, WintNT351sp4]
>
> How does one make a modeless dialog box display an icon when it is
> minimized. I've tried calling SetWindow(), over riding
> PreCreateWindow()...which was useless since dialogs don't call
> precreatewindow! I haven't tried handling WM_PAINT and manually
> blitting the icon, but I'd much rather not do that. If I minimize the
> dlg, it just displays and empty grey square. But if I drag the icon, it
> displays the app icon!
>
> Deepak
> I do not speak for Intel
>
| Вернуться в корень Архива
|