-
Notifications
You must be signed in to change notification settings - Fork 3
/
dllmain.cpp
96 lines (89 loc) · 2.19 KB
/
dllmain.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
#include <string>
typedef struct
{
HWND hWnd;
DWORD dwPid;
}WNDINFO;
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
WNDINFO* pInfo = (WNDINFO*)lParam;
DWORD dwProcessId = 0;
GetWindowThreadProcessId(hWnd, &dwProcessId);
if (dwProcessId == pInfo->dwPid)
{
wchar_t title_buffer[100] = { 0 };
wchar_t class_buffer[100] = { 0 };
GetWindowText(hWnd, title_buffer, 100);
RealGetWindowClass(hWnd, class_buffer, 100);
std::wstring title = title_buffer;
std::wstring classname = class_buffer;
if (title == L"登录" and classname == L"WeChatLoginWndForPC") {
pInfo->hWnd = hWnd;
return FALSE;
}
else if (title == L"微信" and classname == L"WeChatMainWndForPC") {
pInfo->hWnd = hWnd;
return FALSE;
}
}
return TRUE;
}
HWND GetHwndByProcessId(DWORD dwProcessId)
{
WNDINFO info = { 0 };
info.hWnd = NULL;
info.dwPid = dwProcessId;
EnumWindows(EnumWindowsProc, (LPARAM)&info);
return info.hWnd;
}
extern "C" __declspec(dllexport) long GetWndLeft(DWORD pId) {
//MessageBox(NULL, std::to_wstring(pId).c_str(), NULL, 0);
/*HWND hwnd = FindWindow(L"WeChatMainWndForPC", L"微信");
if (!hwnd) {
hwnd = FindWindow(L"WeChatLoginWndForPC", L"登录");
}
if (hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return rect.left;
}*/
HWND hwnd = GetHwndByProcessId(pId);
if (hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return rect.left;
}
return 0;
}
extern "C" __declspec(dllexport) long GetWndTop(DWORD pId) {
//MessageBox(NULL, std::to_wstring(pId).c_str(), NULL, 0);
/*HWND hwnd = FindWindow(L"WeChatMainWndForPC", L"微信");
if (!hwnd) {
hwnd = FindWindow(L"WeChatLoginWndForPC", L"登录");
}
if (hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return rect.top;
}*/
HWND hwnd = GetHwndByProcessId(pId);
if (hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return rect.top;
}
return 0;
}
extern "C" __declspec(dllexport) int GetWndActiveState(DWORD pId) {
//MessageBox(NULL, std::to_wstring(pId).c_str(), NULL, 0);
HWND hwnd = GetHwndByProcessId(pId);
if (hwnd == GetForegroundWindow()) {
return 1;
}
else if (hwnd == GetForegroundWindow()){
return 1;
}
return 0;
}