Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将鼠标位置转换为零_C++_Winapi - Fatal编程技术网

C++ 将鼠标位置转换为零

C++ 将鼠标位置转换为零,c++,winapi,C++,Winapi,我有一个远程屏幕,它获取鼠标位置,然后将该位置转换为捕获的屏幕位置,但该位置始终处于关闭状态。我的数学不是最棒的,但我相信我的转换是正确的。我得到的与屏幕相关的图像大小以及窗口大小是正确的。唯一被关闭的是转换后我的点击点 **我也知道我没有错误检查。这有助于提高可读性 示例:我想单击屏幕点1102x999y。远程窗口点约为676584。转换后,该点被转换为1081.5935.3。我会理解可能有几个像素的减少,因为它很难通过RW点击那个确切的点,但它会被转换为向上60像素,向左20像素 假设我的远

我有一个远程屏幕,它获取鼠标位置,然后将该位置转换为捕获的屏幕位置,但该位置始终处于关闭状态。我的数学不是最棒的,但我相信我的转换是正确的。我得到的与屏幕相关的图像大小以及窗口大小是正确的。唯一被关闭的是转换后我的点击点

**我也知道我没有错误检查。这有助于提高可读性

示例:我想单击
屏幕
1102x
999y
远程窗口
点约为
676
584
。转换后,该点被转换为
1081.5
935.3
。我会理解可能有几个像素的减少,因为它很难通过RW点击那个确切的点,但它会被转换为向上60像素,向左20像素

假设我的远程屏幕是800x600,捕获的是1280x1024。 要获得差异,我使用(1280/800)*单击PointX和(1024/600)*单击PointY

我的问题是sWidth和sHeight总是至少关闭20次,有时关闭80次以上,这取决于单击在窗口内的位置

        POINT p;
        float sWidth;
        float sHeight;
        GetCursorPos(&p);
        RECT rect;
        GetWindowRect(hWnd, &rect); // Get Window Size
        ScreenToClient(hWnd, &p); // convert points relative to screen to points relative to window 
        float wWidth = rect.right - rect.left;
        float wHeight = rect.bottom - rect.top;
        Gdiplus::Image* image = Gdiplus::Image::FromStream(sRemote_Handler.istream); //Get Captured image Size;
        float iWidth = image->GetWidth();
        float iHeight = image->GetHeight();
        INPUT input;
        input.type = INPUT_MOUSE;
        input.mi.time = 0;
        float pointx = p.x; 
        float pointy = p.y;
        sWidth = (iWidth / wWidth)*pointx; // divide image width by screen width
        sHeight = (iHeight / wHeight)*pointy; // divide image height by screen height
        input.mi.dx = sWidth*(65536.0f / iWidth); //convert to pixels
        input.mi.dy = sHeight*(65536.0f / iHeight); // ^
        input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
        SendInput(1, &input, sizeof(input)); // move mouse
我尝试将转换方法更改为(Clickpointx*1280)/800和(Clickpointy*1240)/600。结果仍然一样

        sWidth = (pointx * iWidth) / wWidth;
        sHeight = (pointy * iHeight) / wHeight;
再次更改了转换方法。同样的结果

        sWidth = (pointx / iWidth)*wWidth;
        sHeight = (pointy / iHeight)*wHeight;
编辑

我得出的结论是,它是
ScreenToClient
windows函数。
当点击右下角应该在
800600
附近时,两个值都比实际值小50左右。当我点击左上角时,两个值都在它们应该在的位置。数字报告为
0,1
。似乎我从初始
0,0
点得到的越远,
ScreenToClient
得到的越不准确

65536.0f
是像素密度吗?据我所知,是微软使用的坐标系0,0'左上角到'6553665536'右下角。这是高分辨率点,您必须检查远程显示分辨率点才能计算..我遇到的问题是在使用Microsoft坐标系进行转换之前。如果我没有记错,这可能与不同的原点有关:一个值对具有绝对原点(相对于屏幕),另一个具有相对原点(相对于窗口),或一对相对于应用程序窗口(包括框架),另一对相对于客户端窗口(仅在内部)。