在尝试测试此代码时出现Stack around the variable "rc" was corrupted
错误(使用返回的coord将鼠标移动到那里)
请参阅以下代码:
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;}
}
你能告诉我,有什么不对吗?
答案 0 :(得分:3)
是的,应该就是这个
if(GetClientRect(hWnd, &rc)) // get client coords
{
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc), 2);
return rc.left;
}
矩形是两个点(左上角和右下角)。所以你只需要调用一次MapWindowPoints,计数为2。