-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapp.cpp
247 lines (205 loc) · 6.5 KB
/
app.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include <windows.h>
#include <time.h>
#include "lib/lib.h"
HINSTANCE g_hInstance;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND m_hWnd;
// CPU
Win32Cpu cpuusage;
// Win32文件传统搜索
Win32FileSearch fs;
void CALLBACK fs_OnSearch(Win32FileSearch::FileSearchInfo searchInfo);
// Win32文件快速搜索
Win32FileJournals fj;
void CALLBACK fj_OnLoadProgress(TString* deviceName, INT deviceIndex, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime);// 加载进度事件
void CALLBACK fj_OnLoadComplete(INT deviceCount, DWORD fileCount, DOUBLE elapsedTime);// 加载完成事件
void CALLBACK fj_OnQueryProgress(UsnList* fileList, TString* deviceName, INT deviceIndex, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime); // 查询进度事件
void CALLBACK fj_OnQueryComplete(UsnList* fileList, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime); // 查询完成事件
LONG left = 10;
LONG top = 40;
LONG width = 300;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
g_hInstance = hInstance;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(200, 210, 240));//GetStockObject(WHITE_BRUSH) ;//RGB(38,39,41)
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)) return 0;
hwnd = CreateWindow (szAppName, // window class name
TEXT ("鼠标中键传统搜索,鼠标右击快速搜索"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
800, // initial x size
600, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
return msg.wParam ;
}
// 传统的文件搜索
void CALLBACK fs_OnSearch(Win32FileSearch::FileSearchInfo searchInfo)
{
TCHAR file[300] = {0};
if(searchInfo.bIsFinded)
{
RECT rc;
HDC hdc = GetDC(m_hWnd);
rc.left = left;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file, _T("已找到:%d"), searchInfo.dwFindedCount);
Win32GDI::DrawArea(hdc, rc, RGB(255,234,23));
Win32GDI::DrawAText(hdc,file,rc);
ReleaseDC(m_hWnd, hdc);
}
if(searchInfo.bIsFinish)
{
RECT rc;
HDC hdc = GetDC(m_hWnd);
rc.left = left;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file,_T("搜索%d.找到:%d"), searchInfo.dwFindingCount, searchInfo.dwFindedCount);
Win32GDI::DrawArea(hdc, rc, RGB(255,234,23));
Win32GDI::DrawAText(hdc,file,rc);
ReleaseDC(m_hWnd, hdc);
}
}
// 加载进度事件
void CALLBACK fj_OnLoadProgress(TString* deviceName, INT deviceIndex, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime)
{
TCHAR file[300] = { 0 };
RECT rc;
top += 40;
HDC hdc = GetDC(m_hWnd);
rc.left = left;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file, _T("扫描:%s 找到:%d 消耗:%f 秒"), deviceName->toString(), fileCount, elapsedTime / 1000);
Win32GDI::DrawArea(hdc, rc, RGB(255, 234, 23));
Win32GDI::DrawAText(hdc, file, rc);
ReleaseDC(m_hWnd, hdc);
}
// 加载完成事件
void CALLBACK fj_OnLoadComplete(INT deviceCount, DWORD fileCount, DOUBLE elapsedTime)
{
TCHAR file[300] = { 0 };
RECT rc;
top += 40;
HDC hdc = GetDC(m_hWnd);
rc.left = left;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file, _T("扫描完成,找到:%d, 总计消耗:%f 秒"), fileCount, elapsedTime / 1000);
Win32GDI::DrawArea(hdc, rc, RGB(255, 34, 23));
Win32GDI::DrawAText(hdc, file, rc);
ReleaseDC(m_hWnd, hdc);
// 扫描完成,进行查询
top = 40;
fj.Query("*mp3*", fj_OnQueryProgress, fj_OnQueryComplete);
}
// 查询进度事件
void CALLBACK fj_OnQueryProgress(UsnList* fileList, TString* deviceName, INT deviceIndex, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime)
{
TCHAR file[300] = { 0 };
RECT rc;
top += 40;
HDC hdc = GetDC(m_hWnd);
rc.left = left + width + 20;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file, _T("查找:%s 找到:%d 消耗:%f 秒"), deviceName->toString(), fileCount, elapsedTime / 1000);
Win32GDI::DrawArea(hdc, rc, RGB(255, 234, 23));
Win32GDI::DrawAText(hdc, file, rc);
ReleaseDC(m_hWnd, hdc);
}
// 查询完成事件
void CALLBACK fj_OnQueryComplete(UsnList* fileList, INT deviceCount, DWORD fileCount, DOUBLE elapsedTime)
{
TCHAR file[300] = { 0 };
RECT rc;
top += 40;
HDC hdc = GetDC(m_hWnd);
rc.left = left + width + 20;
rc.top = top;
rc.bottom = rc.top + 20;
rc.right = rc.left + width;
format(file, _T("查找完成,找到:%d, 总计消耗:%f 秒"), fileCount, elapsedTime / 1000);
Win32GDI::DrawArea(hdc, rc, RGB(255, 34, 23));
Win32GDI::DrawAText(hdc, file, rc);
ReleaseDC(m_hWnd, hdc);
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
RECT rect ;
switch (message)
{
case WM_CREATE:
m_hWnd = hwnd;
SetTimer(hwnd, 0, 800, NULL);
return 0;
case WM_SHOWWINDOW:
break;
case WM_MBUTTONUP:
{
// 传统的搜索测试
top = 40;
fs.SetSearchPath(_T("c:\\|d:\\|e:\\|f:\\|g:\\"));
fs.SetSearchPath(_T("d:\\"));
fs.SetSearchFilter(_T("*.wmv|*.mp3|*.wav|*.rmvb|*.rm|*.mid|*.avi"));
fs.SetSearchEvent(fs_OnSearch);
fs.Start();
return 0;
}
case WM_RBUTTONUP:
{
// 快速搜索测试
top = 40;
fj.Refresh(fj_OnLoadProgress, fj_OnLoadComplete);
return 0;
}
case WM_TIMER:
hdc = GetDC(hwnd);
GetClientRect (hwnd, &rect);
rect.left = 10;
rect.top = 10;
rect.right = rect.left + 130;
rect.bottom = rect.top + 24;
cpuusage.hDC = hdc;
cpuusage.Rect = rect;
cpuusage.Draw();
ReleaseDC(hwnd,hdc);
return 0;
case WM_DESTROY:
KillTimer(hwnd,0);
PostQuitMessage(0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}