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.
Value Meaning - 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 |
|
See also
- Reference
- DefWindowProc
- WM_GETICON
- Conceptual
- Windows
Send comments about this topic to Microsoft
Build date: 2/3/2012
- 1/27/2012
- Greg Wittmeyer
- 1/28/2012
- Greg Wittmeyer
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
- 6/30/2009
- Raymond Chen MS