c++ - 立即调用 OnMove() 而不是等待窗口的实际移动

标签 c++ visual-c++ visual-studio-2013 mfc

我的 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();

}

知道为什么 TEST 这个词在我运行应用程序而不是等待移动时立即出现吗?

最佳答案

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

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

相关文章:

c++ - 这个Arduino sleep setAlarm函数的周长是多少?

C++ - cURL - 将多个 easy_init 与 std::async 一起使用与单个 multi_init 之间的区别

c++ - 构建时 vs2015 和 vc++ 外部依赖项错误

windows - Visual Studio Express 2013 for windows with update 2 安装在 "Configuring Your System"中花费太多时间

c++ - vtable中虚拟函数的地址

c++ - boost::polygon_90_data 无法处理面积值为 0 的多边形?

c++ - MS 特定的 volatile 是否会阻止硬件指令重新排序

c++ - 如何区分ascii值和数字?

visual-studio-2013 - 我的 Visual Studio 2013 有什么问题

boost - 需要在Visual Studio中编译缺少的 `detour 3.0`库