Minimize the child window to redraw the icon.
2025-11-17
Written by: xiaobin
If you add a minimize button to your dialog/form, you will need the code below to draw the icon. For MFC applications using the document/view model, this is automatically done for you by the framework.
Minimize box: True
Style: Child
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
afx_msg HCURSOR OnQueryDragIcon();
(HCURSOR)m_hIcon;
Draw Icon:
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}