Repository navigation
Expand file tree
/
Copy pathScanThread.cpp
More file actions
125 lines (98 loc) · 3.75 KB
/
Copy pathScanThread.cpp
File metadata and controls
125 lines (98 loc) · 3.75 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include "ScanThread.hpp"
#include <sstream>
#include <thread>
#include "RuleSet.hpp"
#include "config.h"
extern bool Scanning;
extern std::thread *scanthrd;
extern int windowcount, filteredwindowcount;
extern HWND main_hwnd, _hStatusBar;
extern HTREEITEM tree_conduct;
bool notFirstScan;
void EnumSubWindows(HTREEITEM tree, HWND hwnd)
{
char className[256], windowTitle[256];
GetClassName(hwnd, className, sizeof(className));
GetWindowText(hwnd, windowTitle, sizeof(windowTitle));
if ( Config.EnableBlockList && RuleSet.match(className, windowTitle, ApplyTo::Children) ) {
return;
}
HANDLE updevent = CreateEventA(NULL, FALSE, FALSE, NULL);
std::stringstream sstr; std::string tstr;
sstr << std::hex<< hwnd; tstr = sstr.str(); sstr.str("");
tstr = tstr.substr(tstr.length()-6);
sstr << "0x" << tstr << " | " << className;
if(!std::string(windowTitle).empty()) sstr << " | " << windowTitle;
MsgDataPackB datapack(sstr.str(), hwnd, tree, updevent);
PostMessage(main_hwnd, WM_ADDCHILD, 0, reinterpret_cast<LPARAM>(&datapack));
DWORD dwWaitResult = WaitForSingleObject(updevent, INFINITE);
HTREEITEM htree = tree_conduct;
CloseHandle(updevent);
HWND child = GetWindow(hwnd, GW_CHILD);
while (child != NULL)
{
EnumSubWindows(htree, child);
child = GetWindow(child, GW_HWNDNEXT);
}
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
char className[256], windowTitle[256];
GetClassName(hwnd, className, sizeof(className));
GetWindowText(hwnd, windowTitle, sizeof(windowTitle));
if ( !Config.EnableBlockList || !RuleSet.match(className, windowTitle, ApplyTo::TopLevel) ) {
HANDLE updevent = CreateEventA(NULL, FALSE, FALSE, NULL);
std::stringstream sstr; std::string tstr;
sstr << std::hex<< hwnd; tstr = sstr.str(); sstr.str("");
tstr = tstr.substr(tstr.length()-6);
sstr << "0x" << tstr << " | " << className;
if(!std::string(windowTitle).empty()) sstr << " | " << windowTitle;
MsgDataPackA datapack(sstr.str(), hwnd, updevent);
PostMessage(main_hwnd, WM_ADDROOT, 0, reinterpret_cast<LPARAM>(&datapack));
DWORD dwWaitResult = WaitForSingleObject(updevent, INFINITE);
HTREEITEM htree = tree_conduct;
CloseHandle(updevent);
HWND child = GetWindow(hwnd, GW_CHILD);
while (child != NULL)
{
EnumSubWindows(htree, child);
child = GetWindow(child, GW_HWNDNEXT);
}
} else filteredwindowcount++;
windowcount++;
return TRUE;
}
int ScanThread() {
Scanning = true;
EnumWindows(EnumWindowsProc, 0);
std::stringstream sstr;
sstr << "窗口数:(" << windowcount-filteredwindowcount << "/" << windowcount << ")";
SendMessage(_hStatusBar, SB_SETTEXT, 2, (LPARAM)sstr.str().c_str());
sstr.str("");
SendMessage(_hStatusBar, SB_SETTEXT, 0, (LPARAM)"就绪");
UpdateWindow(main_hwnd);
Scanning = false;
return 0;
}
int BeginScan() {
if(Scanning) return 1;
if(!notFirstScan) {
SendMessage(_hStatusBar, SB_SETTEXT, 0, (LPARAM)"扫描中");
scanthrd = new std::thread(ScanThread);
notFirstScan = true;
} else {
if(scanthrd->joinable()) {
SendMessage(_hStatusBar, SB_SETTEXT, 0, (LPARAM)"挂起");
scanthrd->join();
}
HANDLE updevent = CreateEventA(NULL, FALSE, FALSE, NULL);
SendMessage(main_hwnd, WM_RESET, 0, (LPARAM)updevent);
DWORD dwWaitResult = WaitForSingleObject(updevent, INFINITE);
CloseHandle(updevent);
windowcount = filteredwindowcount = 0;
SendMessage(_hStatusBar, SB_SETTEXT, 0, (LPARAM)"扫描中");
scanthrd = new std::thread(ScanThread);
}
return 0;
}