-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserdlgs.cpp
535 lines (459 loc) · 15.4 KB
/
userdlgs.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
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
//
// Copyright 1995-2002 by Microsoft Corporation
//
#include "precomp.h"
#include "userdlgs.h"
//***********************************************************************************
//CUsrDialog class
//base class for simple dialogs
//***********************************************************************************
INT_PTR CUsrDialog::DoDialog(HWND hwndParent)
{
return DialogBoxParam(
g_hInstance,
MAKEINTRESOURCE(m_wDlgID),
hwndParent,
DlgProc,
(LPARAM) this);
}
//
//
//
INT_PTR CALLBACK CUsrDialog::DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CUsrDialog * thisdlg = (CUsrDialog *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch(uMsg)
{
case WM_INITDIALOG:
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
thisdlg = (CUsrDialog *) lParam;
thisdlg->OnInitDialog(hwndDlg);
return FALSE; // don't set focus.
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
thisdlg->OnOk(hwndDlg);
EndDialog(hwndDlg, IDOK);
return TRUE;
}
else if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwndDlg, IDCANCEL);
return TRUE;
}
else
{
thisdlg->OnCommand(hwndDlg,HIWORD(wParam), LOWORD(wParam));
}
break;
}
return FALSE;
}
//***********************************************************************************
//CShadowStartDlg class
//Remote Control dialog
//***********************************************************************************
const int KBDSHIFT = 0x01;
const int KBDCTRL = 0x02;
const int KBDALT = 0x04;
struct {
LPCTSTR String;
DWORD VKCode;
} HotkeyLookupTable[] =
{
TEXT("0"), '0',
TEXT("1"), '1',
TEXT("2"), '2',
TEXT("3"), '3',
TEXT("4"), '4',
TEXT("5"), '5',
TEXT("6"), '6',
TEXT("7"), '7',
TEXT("8"), '8',
TEXT("9"), '9',
TEXT("A"), 'A',
TEXT("B"), 'B',
TEXT("C"), 'C',
TEXT("D"), 'D',
TEXT("E"), 'E',
TEXT("F"), 'F',
TEXT("G"), 'G',
TEXT("H"), 'H',
TEXT("I"), 'I',
TEXT("J"), 'J',
TEXT("K"), 'K',
TEXT("L"), 'L',
TEXT("M"), 'M',
TEXT("N"), 'N',
TEXT("O"), 'O',
TEXT("P"), 'P',
TEXT("Q"), 'Q',
TEXT("R"), 'R',
TEXT("S"), 'S',
TEXT("T"), 'T',
TEXT("U"), 'U',
TEXT("V"), 'V',
TEXT("W"), 'W',
TEXT("X"), 'X',
TEXT("Y"), 'Y',
TEXT("Z"), 'Z',
TEXT("{backspace}"), VK_BACK,
TEXT("{delete}"), VK_DELETE,
TEXT("{down}"), VK_DOWN,
TEXT("{end}"), VK_END,
TEXT("{enter}"), VK_RETURN,
/// TEXT("{esc}"), VK_ESCAPE, // KLB 07-16-95
/// TEXT("{F1}"), VK_F1,
TEXT("{F2}"), VK_F2,
TEXT("{F3}"), VK_F3,
TEXT("{F4}"), VK_F4,
TEXT("{F5}"), VK_F5,
TEXT("{F6}"), VK_F6,
TEXT("{F7}"), VK_F7,
TEXT("{F8}"), VK_F8,
TEXT("{F9}"), VK_F9,
TEXT("{F10}"), VK_F10,
TEXT("{F11}"), VK_F11,
TEXT("{F12}"), VK_F12,
TEXT("{home}"), VK_HOME,
TEXT("{insert}"), VK_INSERT,
TEXT("{left}"), VK_LEFT,
TEXT("{-}"), VK_SUBTRACT,
TEXT("{pagedown}"), VK_NEXT,
TEXT("{pageup}"), VK_PRIOR,
TEXT("{+}"), VK_ADD,
TEXT("{prtscrn}"), VK_SNAPSHOT,
TEXT("{right}"), VK_RIGHT,
TEXT("{spacebar}"), VK_SPACE,
TEXT("{*}"), VK_MULTIPLY,
TEXT("{tab}"), VK_TAB,
TEXT("{up}"), VK_UP,
NULL, NULL
};
LPCTSTR CShadowStartDlg::m_szShadowHotkeyKey = TEXT("ShadowHotkeyKey");
LPCTSTR CShadowStartDlg::m_szShadowHotkeyShift = TEXT("ShadowHotkeyShift");
//
//
//
CShadowStartDlg::CShadowStartDlg()
{
m_wDlgID = IDD_SHADOWSTART;
//set default values
m_ShadowHotkeyKey = VK_MULTIPLY;
m_ShadowHotkeyShift = KBDCTRL;
//get las saved values from the registry
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, KEY_READ, &hKey))
{
DWORD dwTmp;
DWORD dwType;
DWORD dwSize = sizeof(DWORD);
if ( ERROR_SUCCESS == RegQueryValueEx(hKey, m_szShadowHotkeyKey, 0, &dwType, (LPBYTE) &dwTmp, &dwSize)
&& dwType == REG_DWORD
)
{
m_ShadowHotkeyKey = dwTmp;
}
dwSize = sizeof(DWORD);
if ( ERROR_SUCCESS == RegQueryValueEx(hKey, m_szShadowHotkeyShift, 0, &dwType, (LPBYTE) &dwTmp, &dwSize)
&& dwType == REG_DWORD
)
{
m_ShadowHotkeyShift = dwTmp;
}
RegCloseKey(hKey);
}
}
//
//
//
CShadowStartDlg::~CShadowStartDlg()
{
//save values into the registry
HKEY hKey;
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, (LPTSTR)TEXT("REG_BINARY"),
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
&hKey, NULL))
{
DWORD dwType = REG_DWORD;
DWORD dwSize = sizeof(DWORD);
RegSetValueEx(hKey, m_szShadowHotkeyKey, 0,
dwType, (LPBYTE) &m_ShadowHotkeyKey, dwSize);
RegSetValueEx(hKey, m_szShadowHotkeyShift, 0,
dwType, (LPBYTE) &m_ShadowHotkeyShift, dwSize);
RegCloseKey(hKey);
}
}
//
//
//
void CShadowStartDlg::OnInitDialog(HWND hwndDlg)
{
ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_NUMKEYPAD), SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_KEY), SW_SHOW);
LRESULT index, match = -1;
HWND hComboBox = GetDlgItem(hwndDlg, IDC_SHADOWSTART_HOTKEY);
//
// Initialize the hotkey combo box.
//
for(int i=0; HotkeyLookupTable[i].String; i++ )
{
if((index = SendMessage(hComboBox,CB_ADDSTRING,0,LPARAM(HotkeyLookupTable[i].String))) < 0)
{
break;
}
if(SendMessage(hComboBox,CB_SETITEMDATA, index, LPARAM(HotkeyLookupTable[i].VKCode)) < 0)
{
SendMessage(hComboBox,CB_DELETESTRING,index,0);
break;
}
// If this is our current hotkey key, save it's index.
if(m_ShadowHotkeyKey == (int)HotkeyLookupTable[i].VKCode)
{
match = index;
switch ( HotkeyLookupTable[i].VKCode)
{
case VK_ADD :
case VK_MULTIPLY:
case VK_SUBTRACT:
// change the text
ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_KEY), SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_NUMKEYPAD), SW_SHOW);
break;
}
}
}
//
// Select the current hotkey string in the combo box.
//
if(match)
{
SendMessage(hComboBox,CB_SETCURSEL,match,0);
}
//
// Initialize shift state checkboxes.
//
CheckDlgButton(hwndDlg, IDC_SHADOWSTART_SHIFT,(m_ShadowHotkeyShift & KBDSHIFT) ? TRUE : FALSE );
CheckDlgButton(hwndDlg, IDC_SHADOWSTART_CTRL,(m_ShadowHotkeyShift & KBDCTRL) ? TRUE : FALSE );
CheckDlgButton(hwndDlg, IDC_SHADOWSTART_ALT,(m_ShadowHotkeyShift & KBDALT) ? TRUE : FALSE );
}
//
//
//
void CShadowStartDlg::OnOk(HWND hwndDlg)
{
HWND hComboBox = GetDlgItem(hwndDlg, IDC_SHADOWSTART_HOTKEY);
// Get the current hotkey selection.
m_ShadowHotkeyKey = (DWORD)SendMessage(hComboBox,CB_GETITEMDATA,
SendMessage(hComboBox,CB_GETCURSEL,0,0),0);
// Get shift state checkbox states and form hotkey shift state.
m_ShadowHotkeyShift = 0;
m_ShadowHotkeyShift |=
IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_SHIFT) ?
KBDSHIFT : 0;
m_ShadowHotkeyShift |=
IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_CTRL) ?
KBDCTRL : 0;
m_ShadowHotkeyShift |=
IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_ALT) ?
KBDALT : 0;
}
//***********************************************************************************
//CUserColSelectDlg class
//***********************************************************************************
const WCHAR g_szUsrColumns[] = L"UsrColumnSettings";
UserColumn CUserColSelectDlg::m_UsrColumns[USR_MAX_COLUMN]=
{
{IDS_USR_COL_USERNAME, IDC_USER_NAME, LVCFMT_LEFT, 120, TRUE},
{IDS_USR_COL_SESSION_ID, IDC_SESSION_ID, LVCFMT_RIGHT, 35, TRUE},
{IDS_USR_COL_SESSION_STATUS,IDC_SESSION_STATUS, LVCFMT_LEFT, 93, TRUE},
{IDS_USR_COL_CLIENT_NAME, IDC_CLIENT_NAME, LVCFMT_LEFT, 100, TRUE},
{IDS_USR_COL_WINSTA_NAME, IDC_WINSTA_NAME, LVCFMT_LEFT, 120, TRUE}
};
//
// get last saved values from the registry
//
BOOL CUserColSelectDlg::Load()
{
BOOL bResult=FALSE;
UserColumn * pdata = (UserColumn *) LocalAlloc( 0, sizeof(m_UsrColumns) );
if ( NULL != pdata )
{
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, KEY_READ, &hKey))
{
DWORD dwType;
DWORD dwSize = sizeof(m_UsrColumns);
if ( ERROR_SUCCESS == RegQueryValueEx(hKey, g_szUsrColumns, 0, &dwType, (LPBYTE) pdata, &dwSize)
&& dwType == REG_BINARY && dwSize == sizeof(m_UsrColumns) )
{
bResult = TRUE;
//
// Validate the data
//
for ( ULONG idx = 0; idx < ARRAYSIZE(m_UsrColumns); idx ++ )
{
if ( pdata->dwNameID != m_UsrColumns->dwNameID
|| pdata->dwChkBoxID != m_UsrColumns->dwChkBoxID
|| pdata->Align != pdata->Align
)
{
bResult = FALSE;
break;
}
}
}
RegCloseKey(hKey);
}
if ( bResult )
{
CopyMemory( m_UsrColumns, pdata, sizeof(m_UsrColumns) );
}
LocalFree( pdata );
}
return bResult;
}
//
// save values into the registry
//
BOOL CUserColSelectDlg::Save()
{
HKEY hKey;
BOOL bResult=FALSE;
if (ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER
, szTaskmanKey
, 0
, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
))
{
DWORD dwSize = sizeof(m_UsrColumns);
if ( ERROR_SUCCESS == RegSetValueEx(hKey, g_szUsrColumns, 0, REG_BINARY, (LPBYTE) m_UsrColumns, dwSize) )
{
bResult = TRUE;
}
RegCloseKey(hKey);
}
return bResult;
}
//
// check checkboxes for all active columns
//
void CUserColSelectDlg::OnInitDialog(HWND hwndDlg)
{
for (int i = 0; i < USR_MAX_COLUMN; i++)
{
CheckDlgButton( hwndDlg, m_UsrColumns[i].dwChkBoxID,
m_UsrColumns[i].bActive ? BST_CHECKED : BST_UNCHECKED );
}
}
//
// First, make sure the column width array is up to date
//
void CUserColSelectDlg::OnOk(HWND hwndDlg)
{
for (int i = 1; i < USR_MAX_COLUMN; i++)
{
(BST_CHECKED == IsDlgButtonChecked(hwndDlg, m_UsrColumns[i].dwChkBoxID)) ?
m_UsrColumns[i].bActive=TRUE : m_UsrColumns[i].bActive=FALSE;
}
}
//***********************************************************************************
//CSendMessageDlg class
//***********************************************************************************
//
// Handles "Send Message" dialog
//
void CSendMessageDlg::OnInitDialog(HWND hwndDlg)
{
RECT parentRect, childRect;
INT xPos, yPos;
GetWindowRect(GetParent(hwndDlg), &parentRect);
GetWindowRect(hwndDlg, &childRect);
xPos = ( (parentRect.right + parentRect.left) -
(childRect.right - childRect.left)) / 2;
yPos = ( (parentRect.bottom + parentRect.top) -
(childRect.bottom - childRect.top)) / 2;
SetWindowPos(hwndDlg,
NULL,
xPos, yPos,
0, 0,
SWP_NOSIZE | SWP_NOACTIVATE);
SendMessage(GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE), EM_LIMITTEXT,
MSG_MESSAGE_LENGTH, 0L );
EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
//
// Prepare default title
//
WCHAR szTime[MAX_DATE_TIME_LENGTH+1];
WCHAR szTemplate[MSG_TITLE_LENGTH+1];
WCHAR szUserName[MAX_PATH+1];
DWORD dwLen = LoadString( g_hInstance, IDS_DEFAULT_MESSAGE_TITLE, szTemplate, ARRAYSIZE(szTemplate) );
ASSERT( 0 != dwLen ); // Missing resource string?
dwLen; // unreferenced on FRE builds.
CurrentDateTimeString(szTime);
//
// Get user name.
// User does not always have "display name"
// in this case get his "sam compatible" name
//
ULONG MaxUserNameLength = ARRAYSIZE(szUserName);
if ( !GetUserNameEx( NameDisplay, szUserName, &MaxUserNameLength ) )
{
MaxUserNameLength = ARRAYSIZE(szUserName);
if ( !GetUserNameEx( NameSamCompatible, szUserName, &MaxUserNameLength) )
{
szUserName[ 0 ] = L'\0';
}
}
// UI only - don't care if it truncates
StringCchPrintf( m_szTitle, ARRAYSIZE(m_szTitle), szTemplate, szUserName, szTime );
SetDlgItemText(hwndDlg, IDC_MESSAGE_TITLE, m_szTitle);
SendMessage(GetDlgItem(hwndDlg, IDC_MESSAGE_TITLE), EM_LIMITTEXT, MSG_TITLE_LENGTH, 0L );
}
//
//
//
void CSendMessageDlg::OnOk(HWND hwndDlg)
{
GetWindowText( GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE), m_szMessage, ARRAYSIZE(m_szMessage) );
GetWindowText( GetDlgItem(hwndDlg, IDC_MESSAGE_TITLE), m_szTitle, ARRAYSIZE(m_szTitle) );
}
//
//
//
void CSendMessageDlg::OnCommand(HWND hwndDlg,WORD NotifyId, WORD ItemId)
{
if (ItemId == IDC_MESSAGE_MESSAGE)
{
if (NotifyId == EN_CHANGE)
{
EnableWindow(GetDlgItem(hwndDlg, IDOK),
GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE)) != 0);
}
}
}
//***********************************************************************************
//CConnectPasswordDlg class
//***********************************************************************************
//
//
//
void CConnectPasswordDlg::OnInitDialog(HWND hwndDlg)
{
WCHAR szPrompt[MAX_PATH+1];
LoadString( g_hInstance, m_ids, szPrompt, ARRAYSIZE(szPrompt) );
SetDlgItemText(hwndDlg, IDL_CPDLG_PROMPT, szPrompt);
SendMessage(GetDlgItem(hwndDlg, IDC_CPDLG_PASSWORD), EM_LIMITTEXT, PASSWORD_LENGTH, 0L );
}
//
//
//
void CConnectPasswordDlg::OnOk(HWND hwndDlg)
{
GetWindowText(GetDlgItem(hwndDlg, IDC_CPDLG_PASSWORD), m_szPassword, PASSWORD_LENGTH);
}