我想获取窗口的当前鼠标位置,并将其分配给2个变量
x
和 y
(相对于窗口而不是整个屏幕的坐标)。
我正在使用Win32和C ++。
并且一个快速的奖励问题:您如何隐藏光标/取消隐藏?
您可以通过调用GetCursorPos
获取光标位置。
POINT p;
if (GetCursorPos(&p))
{
//cursor position now in p.x and p.y
}
此函数返回光标相对于屏幕坐标的位置。调用ScreenToClient
将其映射为窗口坐标。
if (ScreenToClient(hwnd, &p))
{
//p.x and p.y are now relative to hwnd's client area
}
您可以使用ShowCursor
来隐藏或显示光标。
ShowCursor(FALSE);//hides the cursor
ShowCursor(TRUE);//shows it again
您必须确保每次隐藏光标的调用都有相应的显示光标的调用。