【发布时间】:2019-01-13 01:00:06
【问题描述】:
每次我调整我的绘图大小时如何处理这个问题似乎没有正确绘制。 我想我每次调整窗口大小时都需要调用 Invalidate() 但每次移动或调整窗口大小时不会自动调用 WM_PAINT 吗?
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);
if (IsIconic())
{
//CPaintDC dc(this); // device context for painting
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
{
for(int ndx(0); ndx < rect.Width() - 150; ndx += 10)
{
dc.MoveTo( rect.left + 50, rect.bottom / 2 );
dc.LineTo( rect.left + 50 + ndx, rect.bottom / 2 );
}
CBrush mybrush(RGB(30,30,30));
dc.FillRect( CRect(rect.left + 10, rect.top + 10, rect.Width() / 4, rect.Height() / 4),&mybrush );
CDialogEx::OnPaint();
}
调整大小之前:
调整大小后:
【问题讨论】:
-
WM_PAINT消息在调整大小时生成,只要窗口类注册为CS_HREDRAW和/或CS_VREDRAW类样式。系统使用窗口类中指定的画笔自动擦除背景。这里的窗口类是指WNDCLASS,而不是CWnd。使用 Spy++ 检查窗口上的窗口类样式。
标签: c++ windows winapi mfc win32gui