void CBmp TestDlg: OnPaint if (sIconico) CPaintDc dc(this): l/ devce context for painting SendMessage(WM ICoNERASEBKGND, (WPARAM)dc. GetSafeHdco, 0) 1/ Center icon in client rectangle int axIcon GetSystemMetrics(SM_CXICON) int cylon GetSystemMetrICs(SM CYICON): CRect rect int x=(rect Width(-CXlcon+1)/2 int y=(rect. Height0-cylcon 1)/2: ∥ Draw the icon dc. Drawlcon(x, y, m hIcon) CPaintDC dc(this); device context for painting dc. Move To(10, 10); dc Line To(100, 100) dc Ellipse(120,120,160,160); CDialog: OnPaint5.1 void CBmpTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND,(WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle 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; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); // device context for painting dc.MoveTo(10,10); dc.LineTo(100,100); dc.Ellipse(120,120,160,160); CDialog::OnPaint(); } }