C++ 模拟打开记事本并拖动窗口移动

180it 2021-09-14 PM 670℃ 0条
#include <windows.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.14
#define NUMBER_OF_ROTATE 3

double DegreeToRadian(double deg)
{
    return deg * (PI / 180.0);
}

void TurnWindow(HWND hWnd)
{
    int nWidth = GetSystemMetrics(SM_CXSCREEN);
    int nHeight = GetSystemMetrics(SM_CYSCREEN);
    double r = nHeight/4;
    
    for (int i = 0; i < 360*NUMBER_OF_ROTATE; i+=1) {
        
        double radian = DegreeToRadian(i);
        double x = r * cos(radian) + nWidth/2;
        double y = r * sin(radian) + nHeight/2;

        SetForegroundWindow(hWnd);
        MoveWindow(hWnd, (int)x, (int)y, 300, 300, TRUE);
        Sleep(5);
    }
}


BOOL CALLBACK WndEnumProc(HWND hWnd, LPARAM)
{
    char szClassName[256];
    ::GetClassNameA(hWnd, szClassName, _countof(szClassName));

    if (::lstrcmpiA(szClassName, "NOTEPAD") == 0) {
        TurnWindow(hWnd);
    }
    return TRUE;
}

int main()
{
    WinExec("notepad", SW_SHOW);
    ::EnumWindows(WndEnumProc, 0); 
    return 0;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C++ 模拟打开记事本并拖动窗口移动