1 out of 1 rated this helpful - Rate this topic

WM_SETICON message

Applies to: desktop apps only

Associates a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.

#define WM_SETICON                      0x0080

Parameters

wParam

The type of icon to be set. This parameter can be one of the following values.

ValueMeaning
ICON_BIG
1

Set the large icon for the window.

ICON_SMALL
0

Set the small icon for the window.

 

lParam

A handle to the new large or small icon. If this parameter is NULL, the icon indicated by wParamis removed.

Return value

Type: LRESULT

The return value is a handle to the previous large or small icon, depending on the value of wParam. It is NULL if the window previously had no icon of the type indicated by wParam.

Remarks

The DefWindowProc function returns a handle to the previous large or small icon associated with the window, depending on the value of wParam.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
DefWindowProc
WM_GETICON
Conceptual
Windows

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Notes
Couple of notes: * The system does not make a copy of the icon. Do not destroy the icon before destroying the window. * Setting the large icon does not work for windows that have no caption (it will not appear on the Alt+Tab window). This is a bug in Windows. * The small icon is also used on the taskbar. * If no large icon is set, the small icon will appear on the Alt+Tab window.
n/a
n/a
在 對話方塊 標題列 上 加入 圖示

DialogBox Title Bar Add ICON


程式碼區塊

#include "resource.h"
#include <windows.h>
#include <stdio.h>

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

HWND g_Dlg_hWnd = NULL;
HICON hIcon1;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{

hIcon1 = (HICON) LoadImage( hInstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON,
16,
16,
LR_DEFAULTSIZE);


HRESULT hr;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DialogProc);
return 1;
}

BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


switch(uMsg)
{
case WM_INITDIALOG:

SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIcon1 );


g_Dlg_hWnd = hWnd;
break;
case WM_COMMAND:
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
}
return FALSE;
}


執行結果 :
http://netbook-tw.spaces.live.com/blog/cns!1C844F3095EE501D!256.entry


--
Bugs in the above code:
1. Return value of DialogProc should be INT_PTR.
2. WM_CLOSE handler should call EndDialog, not DestroyWindow.
3. Icon is leaked.

  • 12/17/2007
  • cmf
Value
WM_SETICON = &H80
ICON_BIG = 1
ICON_SMALL = 0