15,980
社区成员




void CRTSDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDC dcMem;
BITMAP bm;
CRect rect;
m_Background.GetBitmap(&bm);
GetClientRect(&rect);
dcMem.CreateCompatibleDC(&dc);
CBitmap *oldbitmap = dcMem.SelectObject(&m_Background);
dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject(oldbitmap);
CDialogEx::OnPaint();
}
}
HBRUSH CRTSDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
if (CTLCOLOR_STATIC == nCtlColor)
{
switch (pWnd->GetDlgCtrlID())
{
default:
pDC->SetTextColor(RGB(0, 0, 0));
pDC->SetBkMode(TRANSPARENT);
hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
return hbr;
}
}
else if (nCtlColor == CTLCOLOR_DLG)
return m_brush;
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
WINDOWPLACEMENT lwndpl;
WINDOWPLACEMENT * lpwndpl;
lpwndpl = &lwndpl;
GetWindowPlacement(lpwndpl);
lpwndpl->showCmd = SW_SHOWMINIMIZED;
SetWindowPlacement(lpwndpl);