每个分辨率的自动关闭程序

时间:2016-12-12 17:33:02

标签: c++ screen mouse center centering

我是一个热心的程序员,我刚刚从一些我的朋友学到的基本知识开始。 (例如:'keybd_event(VK_SHIFT,0,0,0);'和X ++;             SetCursorPos(X,Y);             睡眠(1);) 但我的程序有问题,我想为每个屏幕分辨率制作我的程序。不仅仅是我的1600x900。我尝试过很多东西,比如“GetDesktopResolution(水平,垂直);”和“GetWindowRect”,但没有帮助。我为我的解决方案制作了一个代码并且它有效但我输入的内容无法与拥有1910x1075或类似内容的人一起工作。所以我希望它自动检测屏幕并运行程序并关闭电脑。最大的问题是让我的鼠标居中,这样它就可以到达X-lenght的中间,然后到Y-Lenght的中间。这是我的解决方案代码(1600x900):

int main()
{
    while (X < 800)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X < 450)
    {
        Y++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X < 1600)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y < 900)
    {
        Y++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X > 800)
    {
        X--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y > 450)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X > 1)
    {
        X--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y > 1)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);`enter code here`
    }
    while (X < 1589)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    void left_click()
        ;
    {
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); //Clicks to close program
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }
    while (X < 800)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y < 450)
    {
        Y++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X < 1600)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y < 900)
    {
        Y++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X > 800)
    {
        X--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y > 450)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X > 1)
    {
        X--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y > 1)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y < 900)
    {
        Y++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    void right_click()
        ;
    {
        mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); //Right clicks on windows icon
        mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
    }
    while (Y > 862)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (X < 378)
    {
        X++;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    while (Y > 835)
    {
        Y--;
        SetCursorPos(X, Y);
        Sleep(1);
    }
    void left_click()
        ;
    {
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); //Clicks on Shut Down
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }
}

感谢您的帮助!!!

1 个答案:

答案 0 :(得分:0)

要在MSWindows中获取屏幕大小,您可以使用GetDeviceCaps函数https://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx