在尝试测试此代码时遇到Stack around the variable "rc"was corrupted
错误(使用返回的坐标将鼠标移到那里)
请看下面的代码:
int TestPluginAPI::getmidX()
{
//RECT rect;
HWND hWnd;
hWnd = getBrowserHwnd();
RECT rc;
if(GetClientRect(hWnd, &rc)) // get client coords
{
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.left), 2); // convert top-left x
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.right), 2); // convert bottom-right x
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.top), 2); // convert top-left y
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc.bottom), 2); // convert bottom-right y
return rc.left;
}
else {return 0;}
}
你能告诉我,这是怎么回事吗?
最佳答案
是的,应该就是这个
if(GetClientRect(hWnd, &rc)) // get client coords
{
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc), 2);
return rc.left;
}
矩形是两个点(左上角和右下角)。所以你只需要调用 MapWindowPoints 一次,计数为 2。
关于c++ - 使用 MapWindowPoints 时堆栈损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15799205/