C++最小化所有窗口
在某些情况下,模拟 win+D 或者 win+M 键输入或者模拟鼠标点击右下角,去最小化所有窗口并不适用。所以利用 WINAPI 直接去实现这个功能。 上代码 C++ .
#include<windows.h>
#include<iostream>
#include<string>
using namespace std;
int main(int argc, const char* argv[]) {
char szTitle[MAX_PATH] = { 0 };
char szClass[MAX_PATH] = { 0 };
int nMaxCount = MAX_PATH;
LPSTR lpClassName = szClass;
LPSTR lpWindowName = szTitle;
while (true) {
HWND hwnd = GetForegroundWindow();//最前端的窗口
GetWindowTextA(hwnd, lpWindowName, nMaxCount);
GetClassNameA(hwnd, lpClassName, nMaxCount);
cout << "HWND:" << hwnd << " CLASS NAME: " << lpClassName << " WINDOWS NAME: " << lpWindowName << endl;
std::string str = (std::string)lpClassName;
if (str.find("TrayWnd") != std::string::npos) {
std::cout << "HWND: " << hwnd << " --> Desktop Window" << std::endl;
break;
}
PostMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
Sleep(100);
}
Sleep(200);
}
|