我的MFC应用程序遇到问题
它应该显示窗口的坐标,然后在移动窗口时显示带有新坐标的新行。我的问题是OnMove()函数似乎立即被调用,并且所有内容总是一次全部显示。

这是我的OnPaint()代码:

void CMainFrame::OnPaint()
{

CRect rect;
HWND hWnd;
CPaintDC dc(this); // device context for painting
GetClientRect(&rect);

CString topLeftx, topLefty, topRightx, topRighty;
CString bottomLeftx, bottomLefty, bottomRightx, bottomRighty;
CString topLeft, topRight, bottomLeft, bottomRight;
CString topLeftxL, topLeftyL, topRightxL, topRightyL;
CString bottomLeftxL, bottomLeftyL, bottomRightxL, bottomRightyL;
CString topLeftL, topRightL, bottomLeftL, bottomRightL;


topLeftx.Format(_T("%d"), (rect.TopLeft().x));
topLefty.Format(_T("%d"), rect.TopLeft().y);
topLeft = topLeftx + "," + topLefty;

topRightx.Format(_T("%d"), rect.TopLeft().x + rect.Width());
topRighty.Format(_T("%d"), rect.TopLeft().y);
topRight = topRightx + "," + topRighty;

bottomLeftx.Format(_T("%d"), rect.BottomRight().x - rect.Width());
bottomLefty.Format(_T("%d"), rect.BottomRight().y);
bottomLeft = bottomLeftx + "," + bottomLefty;

bottomRightx.Format(_T("%d"), rect.BottomRight().x);
bottomRighty.Format(_T("%d"), rect.BottomRight().y);
bottomRight = bottomRightx + "," + bottomRighty;

GetWindowRect(&rect);

topLeftxL.Format(_T("%d"), rect.left);
topLeftyL.Format(_T("%d"), rect.top);
topLeftL = topLeftxL + "," + topLeftyL;

topRightxL.Format(_T("%d"), rect.TopLeft().x + rect.Width());
topRightyL.Format(_T("%d"), rect.TopLeft().y);
topRightL = topRightxL + "," + topRightyL;

bottomLeftxL.Format(_T("%d"), rect.BottomRight().x - rect.Width());
bottomLeftyL.Format(_T("%d"), rect.BottomRight().y);
bottomLeftL = bottomLeftxL + "," + bottomLeftyL;

bottomRightxL.Format(_T("%d"), rect.BottomRight().x);
bottomRightyL.Format(_T("%d"), rect.BottomRight().y);
bottomRightL = bottomRightxL + "," + bottomRightyL;




dc.TextOutW(0, 20, _T("Hello from ROSSSSSSS!!!!"));
dc.TextOutW(0, 40, _T("TopLeft:"));
dc.TextOutW(60, 40, topLeft);
dc.TextOutW(130, 40, _T("TopRight:"));
dc.TextOutW(200, 40, topRight);
dc.TextOutW(280, 40, _T("BottomLeft:"));
dc.TextOutW(365, 40, bottomLeft);
dc.TextOutW(445, 40, _T("BottomRight:"));
dc.TextOutW(550, 40, bottomRight);
dc.TextOutW(0, 60, _T("TopLeft:"));
dc.TextOutW(60, 60, topLeftL);
dc.TextOutW(130, 60, _T("TopRight:"));
dc.TextOutW(200, 60, topRightL);
dc.TextOutW(280, 60, _T("BottomLeft:"));
dc.TextOutW(365, 60, bottomLeftL);
dc.TextOutW(445, 60, _T("BottomRight:"));
dc.TextOutW(550, 60, bottomRightL);



Invalidate();
UpdateWindow();
}


这是OnMove

void CMainFrame::OnMove(int x, int y)

{
CFrameWnd::OnMove(x, y);
CDC *dc;

dc = GetDC();
Invalidate();

dc->TextOutW(0, 80, _T("TEST"));

UpdateWindow();

}


知道为什么在我运行应用程序而不是等待移动时立即出现“测试”一词吗?

最佳答案

因为窗口的初始创建和显示会导致对OnMove()的调用。另一个提示-通过仅在OnPaint()函数中绘制文本,您将省去很多麻烦。其他消息处理程序应捕获数据供OnPaint()以后使用,而不是立即进行绘制。

关于c++ - 立即调用OnMove()而不是等待窗口的实际移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26747031/

10-13 04:10