有沒有辦法在C++中獲得當前的鼠標dpi設置?Windows - 在C++中讀取鼠標的dpi設置
問題是,向系統發送鼠標移動消息將導致不同的光標位置,具體取決於鼠標的dpi分辨率。
編輯:
我找到了一個解決方案,我並不需要從DPI鼠標設置。使用SystemParametersInfo獲得鼠標速度,並通過以下公式計算移動距離: moveDistance.x * 5.0/mouseSpeed。 5.0/mouseSpeed是保證移動距離始終正確的魔術數字。
// get mouse speed
int mouseSpeed;
mouseSpeed = 0;
SystemParametersInfo(SPI_GETMOUSESPEED, 0, &mouseSpeed, 0);
// calculate distance to gaze position
POINT moveDistance;
moveDistance.x = m_lastEyeX - m_centerOfScreen.x;
moveDistance.y = m_lastEyeY - m_centerOfScreen.y;
// 5.0/mouseSpeed -> magic numbers, this will halve the movedistance if mouseSpeed = 10, which is the default setting
// no need to get the dpi of the mouse, but all mouse acceleration has to be turned off
double xMove = moveDistance.x * 5.0/static_cast<double>(mouseSpeed);
double yMove = moveDistance.y * 5.0/static_cast<double>(mouseSpeed);
INPUT mouse;
memset(&mouse, 0, sizeof(INPUT));
mouse.type = INPUT_MOUSE;
// flag for the mouse hook to tell that it's a synthetic event.
mouse.mi.dwExtraInfo = 0x200;
mouse->mi.dx = static_cast<int>(xMove);
mouse->mi.dy = static_cast<int>(yMove);
mouse->mi.dwFlags = mouse->mi.dwFlags | MOUSEEVENTF_MOVE;
SendInput(1, &mouse, sizeof(mouse));
我希望這可以幫助別人:)
您是否嘗試過使用Windows管理工具?在這裏試試這個:[wikipedia](http://en.wikipedia.org/wiki/Windows_Management_Instrumentation) – 2013-02-15 10:35:56
非常感謝bash.d我會通讀。 :) – Flo 2013-02-15 12:23:29