在 WM_PAINT 上,我执行以下操作:
//RectF mNameRect;
//WCHAR* mName;
//HWND mWin; // this is the window handle
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(mWin, &ps);
Graphics g(hdc);
g.Clear(Color::White);
StringFormat stringForm;
stringForm.SetLineAlignment(StringAlignmentCenter);
stringForm.SetAlignment(StringAlignmentCenter);
// set the rectangle to the size of the whole window
mNameRect.Width = static_cast<float>(size.cx);
mNameRect.Height = static_cast<float>(size.cy);
g.DrawString(mName, -1, &mNameFont, mNameRect, &stringForm, &mNameBrush);
EndPaint(mWin, &ps);
}
在 XP 中这很好用,mName 显示在窗口中间。但是在 Vista 上,文本不会移动,无论我如何调整窗口大小,它都停留在它的位置。 g.Clear(Color::White)
似乎没有任何区别。当窗口隐藏在另一个窗口后面并且焦点需要重新绘制时,文本甚至不会改变位置。
如何让 mName 在 Vista 中改变位置?
编辑: 绘制代码通过 WM_PAINT 和 WM_SIZE 以下列方式调用:
// WndProc function
switch (msg){
case WM_SIZE:
// intentionally call paint when WM_SIZE is triggered
case WM_PAINT:
paint();
break;
最佳答案
在调整窗口大小时,您明确调用了 paint()
函数。但是,您的窗口并未失效,因此系统可能将您的绘画工作限制在标记为“脏”的区域。
与其直接调用paint()
,不如使用InvalidateRgn
触发重绘。这将导致 WM_PAINT
被发送,这将由您的应用程序以正常方式处理。作为奖励,您还可以告诉 InvalidateRgn
为您删除背景
InvalidateRgn(hWnd, NULL, TRUE);
关于c++ - GDI+ 在为 vista 重绘时没有清除我的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2797451/