-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarterchecker.h
83 lines (65 loc) · 2.16 KB
/
starterchecker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef STARTERCHECKER_H
#define STARTERCHECKER_H
#include <QObject>
#include <QThread>
#include <Windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <tchar.h>
class StarterChecker : public QThread
{
Q_OBJECT
private slots:
void run(){
bool ret=isStartMenuWindowActive();
if(ret)
{
emit startMenuOpen();
}
}
bool isStartMenuWindowActive() {
HWND hForegroundWindow = GetForegroundWindow();
if (hForegroundWindow == NULL) {
return false; // 如果没有前台窗口,返回false
}
DWORD dwForegroundPID = 0;
GetWindowThreadProcessId(hForegroundWindow, &dwForegroundPID);
// 检查进程是否为explorer.exe
if (dwForegroundPID == 0) {
return false; // 如果进程ID为0,可能是无效的进程ID
}
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwForegroundPID);
if (hProcess == NULL) {
return false; // 无法打开进程
}
// 检查进程名称是否为explorer.exe
TCHAR processName[MAX_PATH];
if (!GetModuleBaseName(hProcess, NULL, processName, sizeof(processName) / sizeof(TCHAR))) {
CloseHandle(hProcess);
return false; // 获取进程名称失败
}
if (_tcsicmp(processName, TEXT("explorer.exe")) != 0) {
CloseHandle(hProcess);
return false; // 进程名称不匹配
}
// 检查窗口标题是否为“开始”
TCHAR windowTitle[256];
if (!GetWindowText(hForegroundWindow, windowTitle, sizeof(windowTitle) / sizeof(TCHAR))) {
CloseHandle(hProcess);
return false; // 获取窗口标题失败
}
if (_tcsicmp(windowTitle, TEXT("开始")) != 0) {
CloseHandle(hProcess);
return false; // 窗口标题不匹配
}
CloseHandle(hProcess); // 关闭进程句柄
return true; // 所有条件都满足,返回true
}
public:
explicit StarterChecker(QObject *parent = nullptr);
signals:
void startMenuOpen();
private:
QTimer * timer;
};
#endif // STARTERCHECKER_H