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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
/*++
Copyright (c) 1993 Microsoft Corporation
Module Name:
ui.c
Abstract:
This function implements the ui (dialog) for getdbg.
Author:
Wesley Witt (wesw) 1-May-1993
Environment:
User Mode
--*/
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mmsystem.h>
#include <direct.h>
#include <shellapi.h>
#include "resource.h"
#include "getdbg.h"
extern DWORD FilesType;
extern BOOL ImmediateCopy;
extern BOOL HelpRequest;
extern CHAR PreferredServer[];
extern CHAR PreferredShare[];
extern CHAR DestinationDir[];
CHAR HelpText[] =
"GETDBG [options] [destination path]\n\n"
"-? Gives this messagebox\n"
"-k Copy KD binaries\n"
"-w Copy WINDBG binaries\n"
"-g Start copy immediatly\n"
"-t Disable network timeouts (use this if the newtwork is slow)\n"
"-s <server> Specify preferred server and/or share\n";
VOID CancelConnection(VOID);
LPCOPYINFO CopyFiles(DWORD,LPSTR,HWND);
LRESULT GetDbgWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL SubclassControls( HWND hwnd );
VOID SetFocusToCurrentControl( VOID );
VOID AddServersToListBox( LPSTR, LPSTR, DWORD, HWND );
VOID DrawMeterBar( HWND, DWORD, DWORD, DWORD, BOOL);
VOID UpdateFilesListbox(DWORD,HWND);
void
GetDbgWinMain( void )
/*++
Routine Description:
This is the entry point for getdbg
Arguments:
None.
Return Value:
None.
--*/
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
HINSTANCE hInst;
hInst = GetModuleHandle( NULL );
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = GetDbgWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(APPICON) );
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "GetDbgDialog";
RegisterClass( &wndclass );
hwnd = CreateDialog( hInst,
MAKEINTRESOURCE( GETDBGDIALOG ),
0,
GetDbgWndProc
);
ShowWindow( hwnd, SW_SHOWNORMAL );
while (GetMessage (&msg, NULL, 0, 0)) {
if (!IsDialogMessage( hwnd, &msg )) {
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return;
}
VOID
DisableControls(
HWND hDlg
)
{
EnableWindow( GetDlgItem( hDlg, ID_SERVERS ), FALSE );
EnableWindow( GetDlgItem( hDlg, ID_SHARES ), FALSE );
EnableWindow( GetDlgItem( hDlg, ID_FILES ), FALSE );
EnableWindow( GetDlgItem( hDlg, ID_KD_DBG ), FALSE );
EnableWindow( GetDlgItem( hDlg, ID_WINDBG_DBG ), FALSE );
EnableWindow( GetDlgItem( hDlg, IDOK ), FALSE );
EnableWindow( GetDlgItem( hDlg, ID_DEST_PATH ), FALSE );
}
VOID
EnableControls(
HWND hDlg
)
{
EnableWindow( GetDlgItem( hDlg, ID_SERVERS ), TRUE );
EnableWindow( GetDlgItem( hDlg, ID_SHARES ), TRUE );
EnableWindow( GetDlgItem( hDlg, ID_FILES ), TRUE );
EnableWindow( GetDlgItem( hDlg, ID_KD_DBG ), TRUE );
EnableWindow( GetDlgItem( hDlg, ID_WINDBG_DBG ), TRUE );
EnableWindow( GetDlgItem( hDlg, IDOK ), TRUE );
EnableWindow( GetDlgItem( hDlg, ID_DEST_PATH ), TRUE );
}
LRESULT
GetDbgWndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
/*++
Routine Description:
Window procedure for the DRWTSN32.EXE main user interface.
Arguments:
hwnd - window handle to the dialog box
message - message number
wParam - first message parameter
lParam - second message parameter
Return Value:
TRUE - did not process the message
FALSE - did process the message
--*/
{
static BOOL first = TRUE;
static BOOL fPaint = FALSE;
static METERINFO mi = {0,0,100,0,100};
static LPCOPYINFO lpci = NULL;
DWORD i;
CHAR server[64];
CHAR share[64];
LPADDSERVERS lpas;
LPMETERINFO lpmi;
LPSTR lpServer = NULL;
LPSTR lpShare = NULL;
switch (message) {
case WM_CREATE:
if (HelpRequest) {
MessageBox(
NULL,
HelpText,
"Debugger Copy Help",
MB_OK | MB_ICONINFORMATION );
ExitProcess( 0 );
}
return 0;
case WM_INITDIALOG:
SubclassControls( hwnd );
if (FilesType == WINDBG_FILES) {
CheckRadioButton( hwnd, ID_WINDBG_DBG, ID_KD_DBG, ID_WINDBG_DBG );
} else if (FilesType == KD_FILES) {
CheckRadioButton( hwnd, ID_WINDBG_DBG, ID_KD_DBG, ID_KD_DBG );
}
SendMessage( GetDlgItem( hwnd, ID_DEST_PATH ), WM_SETTEXT, 0, (LPARAM)DestinationDir );
return 1;
case WU_DRAWMETER:
lpmi = (LPMETERINFO) lParam;
mi.m1Completed = lpmi->m1Completed;
mi.m1Count = lpmi->m1Count;
mi.m2Completed = lpmi->m2Completed;
mi.m2Count = lpmi->m2Count;
DrawMeterBar( hwnd, ID_METER_ALLFILES, mi.m1Completed, mi.m1Count, wParam );
DrawMeterBar( hwnd, ID_METER_ONEFILE, mi.m2Completed, mi.m2Count, wParam );
return 0;
case WU_ADDSERVERS:
if (*PreferredServer) {
lpServer = PreferredServer;
}
if (*PreferredShare) {
lpShare = PreferredShare;
}
DisableControls( hwnd );
AddServersToListBox( lpServer, lpShare, FilesType, hwnd );
return 0;
case WU_COPY_DONE:
EnableControls( hwnd );
if (ImmediateCopy) {
SendMessage( hwnd, WM_CLOSE, 0, 0 );
}
EnableWindow( GetDlgItem( hwnd, ID_STOP ), FALSE );
free( lpci );
lpci = NULL;
return 0;
case WU_AS_DONE:
lpas = (LPADDSERVERS) lParam;
// Shut off all threads
if (lpas->hThreadWait)
{
TerminateThread (lpas->hThreadWait, 0);
}
TerminateThread (lpas->hThread, 0);
if (lpas->rc == 0) {
DestroyWindow( lpas->hwndWait );
if (ImmediateCopy) {
DisableControls( hwnd );
lpci = CopyFiles( FilesType, DestinationDir, hwnd );
} else {
EnableControls( hwnd );
}
} else {
MessageBox( hwnd,
"Could not establish a connection",
"Debugger Copy",
MB_OK | MB_ICONINFORMATION );
DestroyWindow( lpas->hwndWait );
if (ImmediateCopy) {
SendMessage( hwnd, WM_CLOSE, 0, 0 );
return 0;
}
if (*PreferredServer) {
lpServer = PreferredServer;
}
if (*PreferredShare) {
lpShare = PreferredShare;
}
AddServersToListBox( lpServer, lpShare, FilesType, hwnd );
}
SetFocus( GetDlgItem( hwnd, ID_SERVERS ) );
free( lpas );
return 0;
case WM_ACTIVATEAPP:
case WM_SETFOCUS:
fPaint = TRUE;
if (first) {
first = FALSE;
PostMessage( hwnd, WU_ADDSERVERS, 0, 0 );
}
SetFocusToCurrentControl();
return 0;
case WM_COMMAND:
switch (wParam) {
case IDCANCEL:
SendMessage( hwnd, WM_CLOSE, 0, 0 );
break;
case IDOK:
DisableControls( hwnd );
EnableWindow( GetDlgItem( hwnd, ID_STOP ), TRUE );
SendMessage( GetDlgItem( hwnd, ID_DEST_PATH ), WM_GETTEXT, MAX_PATH, (LPARAM)DestinationDir );
lpci = CopyFiles( FilesType, DestinationDir, hwnd );
break;
case ID_STOP:
if (lpci) {
SetEvent( lpci->hStopEvent );
} else {
MessageBeep( 0 );
}
break;
default:
if (LOWORD(wParam) == ID_SERVERS && HIWORD(wParam) == LBN_SELCHANGE) {
i = SendDlgItemMessage( hwnd, ID_SERVERS, LB_GETCURSEL, 0, 0 );
SendDlgItemMessage( hwnd, ID_SERVERS, LB_GETTEXT, i, (LPARAM)server );
DisableControls( hwnd );
AddServersToListBox( server, NULL, FilesType, hwnd );
}
if (LOWORD(wParam) == ID_SHARES && HIWORD(wParam) == LBN_SELCHANGE) {
i = SendDlgItemMessage( hwnd, ID_SERVERS, LB_GETCURSEL, 0, 0 );
SendDlgItemMessage( hwnd, ID_SERVERS, LB_GETTEXT, i, (LPARAM)server );
i = SendDlgItemMessage( hwnd, ID_SHARES, LB_GETCURSEL, 0, 0 );
SendDlgItemMessage( hwnd, ID_SHARES, LB_GETTEXT, i, (LPARAM)share );
DisableControls( hwnd );
AddServersToListBox( server, share, FilesType, hwnd );
}
if (HIWORD(wParam) == BN_CLICKED) {
if (IsDlgButtonChecked( hwnd, ID_KD_DBG ) ) {
FilesType = KD_FILES;
UpdateFilesListbox( FilesType, hwnd );
} else if (IsDlgButtonChecked( hwnd, ID_WINDBG_DBG ) ) {
FilesType = WINDBG_FILES;
UpdateFilesListbox( FilesType, hwnd );
}
}
}
break;
case WM_PAINT:
if (fPaint) {
fPaint = FALSE;
SendMessage( hwnd, WU_DRAWMETER, TRUE, (LPARAM)&mi );
}
break;
case WM_CLOSE:
CancelConnection();
break;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hwnd, message, wParam, lParam );
}
VOID
DrawMeterBar(
HWND hwnd,
DWORD ctlId,
DWORD wPartsComplete,
DWORD wPartsInJob,
BOOL fRedraw
)
{
RECT rcPrcnt;
DWORD dwColor;
SIZE size;
DWORD pct;
CHAR szPercentage[255];
HPEN hpen;
HPEN oldhpen;
HDC hDC;
RECT rcItem;
POINT pt;
wPartsComplete == 0;
hDC = GetDC( hwnd );
GetWindowRect( GetDlgItem(hwnd,ctlId), &rcItem );
pt.x = rcItem.left;
pt.y = rcItem.top;
ScreenToClient( hwnd, &pt );
rcItem.left = pt.x;
rcItem.top = pt.y;
pt.x = rcItem.right;
pt.y = rcItem.bottom;
ScreenToClient( hwnd, &pt );
rcItem.right = pt.x;
rcItem.bottom = pt.y;
hpen = CreatePen( PS_SOLID, 1, RGB(0,0,0) );
oldhpen = SelectObject( hDC, hpen );
if (fRedraw) {
Rectangle( hDC, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom );
}
SelectObject( hDC, oldhpen );
DeleteObject( hpen );
rcItem.left += 2;
rcItem.top += 2;
rcItem.right -= 2;
rcItem.bottom -= 2;
//
// Set-up default foreground and background text colors.
//
SetBkColor( hDC, RGB(125,125,125) );
SetTextColor( hDC, RGB(125,58,125) );
SetTextAlign(hDC, TA_CENTER | TA_TOP);
//
// Invert the foreground and background colors.
//
dwColor = GetBkColor(hDC);
SetBkColor(hDC, SetTextColor(hDC, dwColor));
//
// calculate the percentage done
//
try {
pct = (DWORD)((float)wPartsComplete / (float)wPartsInJob * 100.0);
} except(EXCEPTION_EXECUTE_HANDLER) {
pct = 0;
}
//
// Set rectangle coordinates to include only left part of the window
//
rcPrcnt.top = rcItem.top;
rcPrcnt.bottom = rcItem.bottom;
rcPrcnt.left = rcItem.left;
rcPrcnt.right = rcItem.left +
(DWORD)((float)(rcItem.right - rcItem.left) * ((float)pct / 100));
//
// Output the percentage value in the window.
// Function also paints left part of window.
//
wsprintf(szPercentage, "%d%%", pct);
GetTextExtentPoint(hDC, "X", 1, &size);
ExtTextOut( hDC,
(rcItem.right - rcItem.left) / 2,
rcItem.top + ((rcItem.bottom - rcItem.top - size.cy) / 2),
ETO_OPAQUE | ETO_CLIPPED,
&rcPrcnt,
szPercentage,
strlen(szPercentage),
NULL
);
//
// Adjust rectangle so that it includes the remaining
// percentage of the window.
//
rcPrcnt.left = rcPrcnt.right;
rcPrcnt.right = rcItem.right;
//
// Invert the foreground and background colors.
//
dwColor = GetBkColor(hDC);
SetBkColor(hDC, SetTextColor(hDC, dwColor));
//
// Output the percentage value a second time in the window.
// Function also paints right part of window.
//
ExtTextOut( hDC,
(rcItem.right - rcItem.left) / 2,
rcItem.top + ((rcItem.bottom - rcItem.top - size.cy) / 2),
ETO_OPAQUE | ETO_CLIPPED,
&rcPrcnt,
szPercentage,
strlen(szPercentage),
NULL
);
ReleaseDC( hwnd, hDC );
return;
}
|