-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameprocesshandle.cpp
51 lines (36 loc) · 986 Bytes
/
gameprocesshandle.cpp
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
#include "gameprocesshandle.h"
GameProcessHandle::GameProcessHandle(QObject *parent) : QObject(parent)
{
}
/**
* @brief 获取进程句柄,通过类名方式
*
* @param[in] gameClassName 游戏类名
*
* @return NULL 表示失败
*/
HANDLE GameProcessHandle::getProcessHandleByClassName(LPCSTR gameClassName)
{
HWND windowHandle = FindWindowA(gameClassName,NULL);
if (!windowHandle)
{
qWarning() << "get window handle failed,game is open?";
return NULL;
}
DWORD processId = 0;
GetWindowThreadProcessId(windowHandle,&processId);
if (!processId)
{
qWarning() << "get window process id fialed!";
return NULL;
}
qDebug() << "process id = " << processId;
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS,false,processId);
if (!processHandle)
{
qWarning() << "open process fialed!";
return nullptr;
}
qDebug() << processHandle;
return processHandle;
}