C++实现自动演示程序信息,防止电脑锁屏和休眠

除了自身程序的窗口以外,在Windows10上把所有打开的应用程序窗口依次最大化,每次窗口最大化之间的间隔是10秒。

使用EnumWindows函数枚举所有顶级窗口。
对于每个窗口,使用“GetWindowThreadProcessId”函数检查它是否与您的程序属于同一进程。
如果没有,请使用带有“SW_SHOWMAXIMIZED”标志的“ShowWindow”函数来最大化窗口。
使用“Sleep”函数在每个窗口最大化之间等待10秒。
#include <windows.h>

// A callback function for EnumWindows
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    // Get the process ID of the window
    DWORD pid;
    GetWindowThreadProcessId(hwnd, &pid);

    // Get the process ID of the current progrạm
    DWORD current_pid = GetCurrentProcessId();
    // If they are different, maximize the window
    if (pid != current_pid)
    {
        ShowWindow(hwnd, SW_SHOWMAXIMIZED);
        Sleep(10000); // Wait for 10 seconds
    }
    return TRUE; // Continue the enumeration
}

int main()
{
    // Enumerate all top-level windows
    EnumWindows(EnumWindowsProc, 0);

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值