Icon - Normal Window

Simple application of afxApp()

2025-11-17

Written by: xiaobin

The handle needs to be obtained in the constructor; the icon is set in the subsequent call. For example, in InitUpdate() or InitDialog().

handle

protected:
    HICON m_hIcon;
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);

AfxGetApp

Obtains a pointer to the CWinApp object.

LoadIcon

Loads an icon resource.

HICON LoadIcon(LPCTSTR lpszResourceName) const;
HICON LoadIcon(UINT nIDResource) const;

set icon

SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon