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().
protected:
HICON m_hIcon;
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
Obtains a pointer to the CWinApp object.
HICON LoadIcon(LPCTSTR lpszResourceName) const;
HICON LoadIcon(UINT nIDResource) const;
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon