概述
通过FindWindow
可以找到对应的窗口句柄,然后通过ShowWindow
可以最小化最大化窗口
样例
查找一个记事本应用,如果找到则循环对其执行最大化、最小化操作
#include <iostream>
#include <chrono>
#include <thread>
#include "windows.h"
using namespace std;
static constexpr int OPE_INTERVAL_SEC = 20;;
int main()
{
HWND hdl = FindWindow(L"Notepad", nullptr);
if (hdl == 0) {
cout << "Find window fail" << endl;
return -1;
}
bool isMin = true;
uint32_t loopTimes = 0;
while (true) {
int ret;
if (isMin) {
ret = ShowWindow(hdl, SW_MINIMIZE);
} else {
ret = ShowWindow(hdl, SW_MAXIMIZE);
}
cout << "start exec, isMin:" << isMin << " loopTimes: " << loopTimes << " ret: " << ret << endl;
isMin = !isMin;
loopTimes++;
this_thread::sleep_for(chrono::seconds(OPE_INTERVAL_SEC));
}
std::cout << "Hello World!
";
}