运行之后,只需要打开对应的应用即可获取,系统轮询1秒1次
#include<iostream>
#include<Windows.h>
using namespace std;
int main() {
HWND Windows;
while (true) {
Windows = GetForegroundWindow(); //获取窗口实例子
DWORD dwProcess;
LRESULT result = 0;
DWORD dwPID = GetWindowThreadProcessId(Windows, &dwProcess);
cout << "dwPID = " << dwPID << endl;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcess);
WCHAR wszProcessPath[MAX_PATH] = { 0 };
DWORD dwSize = MAX_PATH;
QueryFullProcessImageNameW(hProcess, 0, wszProcessPath, &dwSize);
CHAR wszTitle[MAX_PATH] = { 0 };
result = GetWindowTextA(Windows, wszTitle, MAX_PATH);
cout << "窗口标题:[" << wszTitle << "]" << endl;
Sleep(1000);
}
return true;
}
关于作者