🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: de.comp.lang.c++
Article #174

Re: Icons fuer Dialoge

#174
From: Karsten Pries
Date: Mon, 31 Jul 1995 11:48
137 lines
4054 bytes
In article <MSGID_242=3A1000=2F303.0_301930fb@Fido.DE>, Alexander_Floedl@cray-ii.fido.de (Alexander Floedl) writes:
|> Hallo All,
|> 
|> ich benutze Borland C++ 4.5 und habe eine Frage:
|> 
|> Wie kann ich einem Dialog ein Icon zuordnen, das dann angezeigt wird,
|> wenn ich den Dialog zum Symbol verkleinere ?
|> 
|> Wenn jemand mit der API oder mit Visual C++ die Loesung kennt,
|> kann er mir diese stattdessen mailen.
|> 

Nur mit MSVC:

int CTestDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	/* Load icon resource. */

	m_hIcon = ::LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_MYICON));

	return 0L;
}


HCURSOR CTestDialog::OnQueryDragIcon()
{
	/* Icon is about to be dragged. Return handle to custom icon. */
	return (m_hIcon);
}


void CTestDialog::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	if ( IsIconic())
	{
		int OldMapMode = dc.SetMapMode( MM_TEXT );
		dc.DrawIcon( 0, 0, m_hIcon);
		dc.SetMapMode( OldMapMode );
	}
}


See also: \msvc\help\tips.hlp:


Drawing the Icon for a Minimized Application 

Summary

This article describes how a Windows application can draw its own icon when 
minimized. An application may want to do this, for example, in order to draw different 
icons depending on the state of the application.

More Information

To draw its own icon when minimized, a Windows application should perform the 
following five steps:


1.	Specify a NULL hIcon when registering the main window's window class.

2.	Keep a static variable for the icon that the application will use:



      HICON hIcon;


Initialize this variable, perhaps by using LoadIcon or CreateIcon.



3.	To draw the icon, add a WM_PAINT case, such as the following to the main 
window's window procedure:



   case WM_PAINT:
      {
      PAINTSTRUCT ps;

      if (IsIconic(hWnd))
         {
         BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
         // Paint the desktop window background
         DefWindowProc(hWnd, WM_ICONERASEBKGND, (WORD)ps.hdc, 0L);
         // Draw the icon on top of it
         DrawIcon(ps.hdc, 0,0, hIcon);

         EndPaint(hWnd, (LPPAINTSTRUCT)&ps);

         }
      else
         return (DefWindowProc(hWnd, message, wParam, lParam));
      }


4.	To prevent flickering when the icon is drawn, add a WM_ERASEBKGND case:


   case WM_ERASEBKGND:
      if (IsIconic(hWnd))
         // Don't erase the background now, since we will do it
         // at WM_PAINT time when we paint our own icon...
         return(TRUE);
      else
         return (DefWindowProc(hWnd, message, wParam, lParam));



5.	Add a WM_QUERYDRAGICON case. WM_QUERYDRAGICON is sent to an 
iconic window that is about to be dragged by the user but does not have an icon 
defined for its class. The code below causes Windows to use the specified icon 
when creating a cursor to display during dragging. Windows automatically 
converts color icons to monochrome.


   case WM_QUERYDRAGICON:
      return((LONG)(WORD)hIcon);
      break;


In Windows 3.1, an application can use DDE to ask Program Manager which icon 
the user has associated with the application, and draw that icon using the techniques 
outlined above.  


Das sollte helfen
-- 
Karsten Pries      E-Mail: pries@informatik.tu-muenchen.de
Munich, Germany    http://www.informatik.tu-muenchen.de/~pries/
Technical Details
Message-ID: <3vifth$9di@sunsystem5.informatik.tu-muenchen.de>
Path: arc1-ca.pugleaf.net!informatik.tu-muenchen.de!pries
References: <MSGID_242=3A1000=2F303.0_301930fb@Fido.DE>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!informatik.tu-muenchen.de!pries
From: pries@informatik.tu-muenchen.de (Karsten Pries)
Newsgroups: de.comp.lang.c++
Subject: Re: Icons fuer Dialoge
Date: 31 Jul 1995 11:48:01 GMT
Organization: Technische Universitaet Muenchen, Germany
Distribution: world
Message-ID: <3vifth$9di@sunsystem5.informatik.tu-muenchen.de>
References: <MSGID_242=3A1000=2F303.0_301930fb@Fido.DE>
NNTP-Posting-Host: hphalle4.informatik.tu-muenchen.de
To: Alexander_Floedl@cray-ii.fido.de (Alexander Floedl)
Originator: pries@hphalle4.informatik.tu-muenchen.de