on WM_PAINT i do the following:
//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);
}
In XP this works fine, the mName is displayed in the middle of the window. However on Vista the text doesn't move, it stays in its location no matter how I resize the window. th开发者_运维技巧e g.Clear(Color::White)
doesn't seem to do any difference. The text doesn't even change position when the window is hidden behind another window and on focus needs to be repainted again.
How do I make mName change position in Vista?
Edit: The paint code gets called via WM_PAINT and via WM_SIZE in the following manner:
// WndProc function
switch (msg){
case WM_SIZE:
// intentionally call paint when WM_SIZE is triggered
case WM_PAINT:
paint();
break;
You are explicitly calling your paint()
function when the window is resized. However, your window is not invalidated, so it could be that the system is restricting your painting efforts to the region marked "dirty".
Instead of calling paint()
directly, it is better to use InvalidateRgn
to trigger a repaint. This will cause a WM_PAINT
to be sent which will be handled by your application in the normal way. As a bonus, you can also tell InvalidateRgn
to erase the background for you
InvalidateRgn(hWnd, NULL, TRUE);
精彩评论