Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

535 lines
16 KiB

  1. //
  2. // Copyright 1995-2002 by Microsoft Corporation
  3. //
  4. #include "precomp.h"
  5. #include "userdlgs.h"
  6. //***********************************************************************************
  7. //CUsrDialog class
  8. //base class for simple dialogs
  9. //***********************************************************************************
  10. INT_PTR CUsrDialog::DoDialog(HWND hwndParent)
  11. {
  12. return DialogBoxParam(
  13. g_hInstance,
  14. MAKEINTRESOURCE(m_wDlgID),
  15. hwndParent,
  16. DlgProc,
  17. (LPARAM) this);
  18. }
  19. //
  20. //
  21. //
  22. INT_PTR CALLBACK CUsrDialog::DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  23. {
  24. CUsrDialog * thisdlg = (CUsrDialog *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  25. switch(uMsg)
  26. {
  27. case WM_INITDIALOG:
  28. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  29. thisdlg = (CUsrDialog *) lParam;
  30. thisdlg->OnInitDialog(hwndDlg);
  31. return FALSE; // don't set focus.
  32. case WM_COMMAND:
  33. if (LOWORD(wParam) == IDOK)
  34. {
  35. thisdlg->OnOk(hwndDlg);
  36. EndDialog(hwndDlg, IDOK);
  37. return TRUE;
  38. }
  39. else if (LOWORD(wParam) == IDCANCEL)
  40. {
  41. EndDialog(hwndDlg, IDCANCEL);
  42. return TRUE;
  43. }
  44. else
  45. {
  46. thisdlg->OnCommand(hwndDlg,HIWORD(wParam), LOWORD(wParam));
  47. }
  48. break;
  49. }
  50. return FALSE;
  51. }
  52. //***********************************************************************************
  53. //CShadowStartDlg class
  54. //Remote Control dialog
  55. //***********************************************************************************
  56. const int KBDSHIFT = 0x01;
  57. const int KBDCTRL = 0x02;
  58. const int KBDALT = 0x04;
  59. struct {
  60. LPCTSTR String;
  61. DWORD VKCode;
  62. } HotkeyLookupTable[] =
  63. {
  64. TEXT("0"), '0',
  65. TEXT("1"), '1',
  66. TEXT("2"), '2',
  67. TEXT("3"), '3',
  68. TEXT("4"), '4',
  69. TEXT("5"), '5',
  70. TEXT("6"), '6',
  71. TEXT("7"), '7',
  72. TEXT("8"), '8',
  73. TEXT("9"), '9',
  74. TEXT("A"), 'A',
  75. TEXT("B"), 'B',
  76. TEXT("C"), 'C',
  77. TEXT("D"), 'D',
  78. TEXT("E"), 'E',
  79. TEXT("F"), 'F',
  80. TEXT("G"), 'G',
  81. TEXT("H"), 'H',
  82. TEXT("I"), 'I',
  83. TEXT("J"), 'J',
  84. TEXT("K"), 'K',
  85. TEXT("L"), 'L',
  86. TEXT("M"), 'M',
  87. TEXT("N"), 'N',
  88. TEXT("O"), 'O',
  89. TEXT("P"), 'P',
  90. TEXT("Q"), 'Q',
  91. TEXT("R"), 'R',
  92. TEXT("S"), 'S',
  93. TEXT("T"), 'T',
  94. TEXT("U"), 'U',
  95. TEXT("V"), 'V',
  96. TEXT("W"), 'W',
  97. TEXT("X"), 'X',
  98. TEXT("Y"), 'Y',
  99. TEXT("Z"), 'Z',
  100. TEXT("{backspace}"), VK_BACK,
  101. TEXT("{delete}"), VK_DELETE,
  102. TEXT("{down}"), VK_DOWN,
  103. TEXT("{end}"), VK_END,
  104. TEXT("{enter}"), VK_RETURN,
  105. /// TEXT("{esc}"), VK_ESCAPE, // KLB 07-16-95
  106. /// TEXT("{F1}"), VK_F1,
  107. TEXT("{F2}"), VK_F2,
  108. TEXT("{F3}"), VK_F3,
  109. TEXT("{F4}"), VK_F4,
  110. TEXT("{F5}"), VK_F5,
  111. TEXT("{F6}"), VK_F6,
  112. TEXT("{F7}"), VK_F7,
  113. TEXT("{F8}"), VK_F8,
  114. TEXT("{F9}"), VK_F9,
  115. TEXT("{F10}"), VK_F10,
  116. TEXT("{F11}"), VK_F11,
  117. TEXT("{F12}"), VK_F12,
  118. TEXT("{home}"), VK_HOME,
  119. TEXT("{insert}"), VK_INSERT,
  120. TEXT("{left}"), VK_LEFT,
  121. TEXT("{-}"), VK_SUBTRACT,
  122. TEXT("{pagedown}"), VK_NEXT,
  123. TEXT("{pageup}"), VK_PRIOR,
  124. TEXT("{+}"), VK_ADD,
  125. TEXT("{prtscrn}"), VK_SNAPSHOT,
  126. TEXT("{right}"), VK_RIGHT,
  127. TEXT("{spacebar}"), VK_SPACE,
  128. TEXT("{*}"), VK_MULTIPLY,
  129. TEXT("{tab}"), VK_TAB,
  130. TEXT("{up}"), VK_UP,
  131. NULL, NULL
  132. };
  133. LPCTSTR CShadowStartDlg::m_szShadowHotkeyKey = TEXT("ShadowHotkeyKey");
  134. LPCTSTR CShadowStartDlg::m_szShadowHotkeyShift = TEXT("ShadowHotkeyShift");
  135. //
  136. //
  137. //
  138. CShadowStartDlg::CShadowStartDlg()
  139. {
  140. m_wDlgID = IDD_SHADOWSTART;
  141. //set default values
  142. m_ShadowHotkeyKey = VK_MULTIPLY;
  143. m_ShadowHotkeyShift = KBDCTRL;
  144. //get las saved values from the registry
  145. HKEY hKey;
  146. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, KEY_READ, &hKey))
  147. {
  148. DWORD dwTmp;
  149. DWORD dwType;
  150. DWORD dwSize = sizeof(DWORD);
  151. if ( ERROR_SUCCESS == RegQueryValueEx(hKey, m_szShadowHotkeyKey, 0, &dwType, (LPBYTE) &dwTmp, &dwSize)
  152. && dwType == REG_DWORD
  153. )
  154. {
  155. m_ShadowHotkeyKey = dwTmp;
  156. }
  157. dwSize = sizeof(DWORD);
  158. if ( ERROR_SUCCESS == RegQueryValueEx(hKey, m_szShadowHotkeyShift, 0, &dwType, (LPBYTE) &dwTmp, &dwSize)
  159. && dwType == REG_DWORD
  160. )
  161. {
  162. m_ShadowHotkeyShift = dwTmp;
  163. }
  164. RegCloseKey(hKey);
  165. }
  166. }
  167. //
  168. //
  169. //
  170. CShadowStartDlg::~CShadowStartDlg()
  171. {
  172. //save values into the registry
  173. HKEY hKey;
  174. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, TEXT("REG_BINARY"),
  175. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  176. &hKey, NULL))
  177. {
  178. DWORD dwType = REG_DWORD;
  179. DWORD dwSize = sizeof(DWORD);
  180. RegSetValueEx(hKey, m_szShadowHotkeyKey, 0,
  181. dwType, (LPBYTE) &m_ShadowHotkeyKey, dwSize);
  182. RegSetValueEx(hKey, m_szShadowHotkeyShift, 0,
  183. dwType, (LPBYTE) &m_ShadowHotkeyShift, dwSize);
  184. RegCloseKey(hKey);
  185. }
  186. }
  187. //
  188. //
  189. //
  190. void CShadowStartDlg::OnInitDialog(HWND hwndDlg)
  191. {
  192. ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_NUMKEYPAD), SW_HIDE);
  193. ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_KEY), SW_SHOW);
  194. LRESULT index, match = -1;
  195. HWND hComboBox = GetDlgItem(hwndDlg, IDC_SHADOWSTART_HOTKEY);
  196. //
  197. // Initialize the hotkey combo box.
  198. //
  199. for(int i=0; HotkeyLookupTable[i].String; i++ )
  200. {
  201. if((index = SendMessage(hComboBox,CB_ADDSTRING,0,LPARAM(HotkeyLookupTable[i].String))) < 0)
  202. {
  203. break;
  204. }
  205. if(SendMessage(hComboBox,CB_SETITEMDATA, index, LPARAM(HotkeyLookupTable[i].VKCode)) < 0)
  206. {
  207. SendMessage(hComboBox,CB_DELETESTRING,index,0);
  208. break;
  209. }
  210. // If this is our current hotkey key, save it's index.
  211. if(m_ShadowHotkeyKey == (int)HotkeyLookupTable[i].VKCode)
  212. {
  213. match = index;
  214. switch ( HotkeyLookupTable[i].VKCode)
  215. {
  216. case VK_ADD :
  217. case VK_MULTIPLY:
  218. case VK_SUBTRACT:
  219. // change the text
  220. ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_KEY), SW_HIDE);
  221. ShowWindow(GetDlgItem(hwndDlg, IDC_PRESS_NUMKEYPAD), SW_SHOW);
  222. break;
  223. }
  224. }
  225. }
  226. //
  227. // Select the current hotkey string in the combo box.
  228. //
  229. if(match)
  230. {
  231. SendMessage(hComboBox,CB_SETCURSEL,match,0);
  232. }
  233. //
  234. // Initialize shift state checkboxes.
  235. //
  236. CheckDlgButton(hwndDlg, IDC_SHADOWSTART_SHIFT,(m_ShadowHotkeyShift & KBDSHIFT) ? TRUE : FALSE );
  237. CheckDlgButton(hwndDlg, IDC_SHADOWSTART_CTRL,(m_ShadowHotkeyShift & KBDCTRL) ? TRUE : FALSE );
  238. CheckDlgButton(hwndDlg, IDC_SHADOWSTART_ALT,(m_ShadowHotkeyShift & KBDALT) ? TRUE : FALSE );
  239. }
  240. //
  241. //
  242. //
  243. void CShadowStartDlg::OnOk(HWND hwndDlg)
  244. {
  245. HWND hComboBox = GetDlgItem(hwndDlg, IDC_SHADOWSTART_HOTKEY);
  246. // Get the current hotkey selection.
  247. m_ShadowHotkeyKey = (DWORD)SendMessage(hComboBox,CB_GETITEMDATA,
  248. SendMessage(hComboBox,CB_GETCURSEL,0,0),0);
  249. // Get shift state checkbox states and form hotkey shift state.
  250. m_ShadowHotkeyShift = 0;
  251. m_ShadowHotkeyShift |=
  252. IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_SHIFT) ?
  253. KBDSHIFT : 0;
  254. m_ShadowHotkeyShift |=
  255. IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_CTRL) ?
  256. KBDCTRL : 0;
  257. m_ShadowHotkeyShift |=
  258. IsDlgButtonChecked(hwndDlg, IDC_SHADOWSTART_ALT) ?
  259. KBDALT : 0;
  260. }
  261. //***********************************************************************************
  262. //CUserColSelectDlg class
  263. //***********************************************************************************
  264. const WCHAR g_szUsrColumns[] = L"UsrColumnSettings";
  265. UserColumn CUserColSelectDlg::m_UsrColumns[USR_MAX_COLUMN]=
  266. {
  267. {IDS_USR_COL_USERNAME, IDC_USER_NAME, LVCFMT_LEFT, 120, TRUE},
  268. {IDS_USR_COL_SESSION_ID, IDC_SESSION_ID, LVCFMT_RIGHT, 35, TRUE},
  269. {IDS_USR_COL_SESSION_STATUS,IDC_SESSION_STATUS, LVCFMT_LEFT, 93, TRUE},
  270. {IDS_USR_COL_CLIENT_NAME, IDC_CLIENT_NAME, LVCFMT_LEFT, 100, TRUE},
  271. {IDS_USR_COL_WINSTA_NAME, IDC_WINSTA_NAME, LVCFMT_LEFT, 120, TRUE}
  272. };
  273. //
  274. // get last saved values from the registry
  275. //
  276. BOOL CUserColSelectDlg::Load()
  277. {
  278. BOOL bResult=FALSE;
  279. UserColumn * pdata = (UserColumn *) LocalAlloc( 0, sizeof(m_UsrColumns) );
  280. if ( NULL != pdata )
  281. {
  282. HKEY hKey;
  283. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, szTaskmanKey, 0, KEY_READ, &hKey))
  284. {
  285. DWORD dwType;
  286. DWORD dwSize = sizeof(m_UsrColumns);
  287. if ( ERROR_SUCCESS == RegQueryValueEx(hKey, g_szUsrColumns, 0, &dwType, (LPBYTE) pdata, &dwSize)
  288. && dwType == REG_BINARY && dwSize == sizeof(m_UsrColumns) )
  289. {
  290. bResult = TRUE;
  291. //
  292. // Validate the data
  293. //
  294. for ( ULONG idx = 0; idx < ARRAYSIZE(m_UsrColumns); idx ++ )
  295. {
  296. if ( pdata->dwNameID != m_UsrColumns->dwNameID
  297. || pdata->dwChkBoxID != m_UsrColumns->dwChkBoxID
  298. || pdata->Align != pdata->Align
  299. )
  300. {
  301. bResult = FALSE;
  302. break;
  303. }
  304. }
  305. }
  306. RegCloseKey(hKey);
  307. }
  308. if ( bResult )
  309. {
  310. CopyMemory( m_UsrColumns, pdata, sizeof(m_UsrColumns) );
  311. }
  312. LocalFree( pdata );
  313. }
  314. return bResult;
  315. }
  316. //
  317. // save values into the registry
  318. //
  319. BOOL CUserColSelectDlg::Save()
  320. {
  321. HKEY hKey;
  322. BOOL bResult=FALSE;
  323. if (ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER
  324. , szTaskmanKey
  325. , 0
  326. , NULL
  327. , REG_OPTION_NON_VOLATILE
  328. , KEY_WRITE
  329. , NULL
  330. , &hKey
  331. , NULL
  332. ))
  333. {
  334. DWORD dwSize = sizeof(m_UsrColumns);
  335. if ( ERROR_SUCCESS == RegSetValueEx(hKey, g_szUsrColumns, 0, REG_BINARY, (LPBYTE) m_UsrColumns, dwSize) )
  336. {
  337. bResult = TRUE;
  338. }
  339. RegCloseKey(hKey);
  340. }
  341. return bResult;
  342. }
  343. //
  344. // check checkboxes for all active columns
  345. //
  346. void CUserColSelectDlg::OnInitDialog(HWND hwndDlg)
  347. {
  348. for (int i = 0; i < USR_MAX_COLUMN; i++)
  349. {
  350. CheckDlgButton( hwndDlg, m_UsrColumns[i].dwChkBoxID,
  351. m_UsrColumns[i].bActive ? BST_CHECKED : BST_UNCHECKED );
  352. }
  353. }
  354. //
  355. // First, make sure the column width array is up to date
  356. //
  357. void CUserColSelectDlg::OnOk(HWND hwndDlg)
  358. {
  359. for (int i = 1; i < USR_MAX_COLUMN; i++)
  360. {
  361. (BST_CHECKED == IsDlgButtonChecked(hwndDlg, m_UsrColumns[i].dwChkBoxID)) ?
  362. m_UsrColumns[i].bActive=TRUE : m_UsrColumns[i].bActive=FALSE;
  363. }
  364. }
  365. //***********************************************************************************
  366. //CSendMessageDlg class
  367. //***********************************************************************************
  368. //
  369. // Handles "Send Message" dialog
  370. //
  371. void CSendMessageDlg::OnInitDialog(HWND hwndDlg)
  372. {
  373. RECT parentRect, childRect;
  374. INT xPos, yPos;
  375. GetWindowRect(GetParent(hwndDlg), &parentRect);
  376. GetWindowRect(hwndDlg, &childRect);
  377. xPos = ( (parentRect.right + parentRect.left) -
  378. (childRect.right - childRect.left)) / 2;
  379. yPos = ( (parentRect.bottom + parentRect.top) -
  380. (childRect.bottom - childRect.top)) / 2;
  381. SetWindowPos(hwndDlg,
  382. NULL,
  383. xPos, yPos,
  384. 0, 0,
  385. SWP_NOSIZE | SWP_NOACTIVATE);
  386. SendMessage(GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE), EM_LIMITTEXT,
  387. MSG_MESSAGE_LENGTH, 0L );
  388. EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
  389. //
  390. // Prepare default title
  391. //
  392. WCHAR szTime[MAX_DATE_TIME_LENGTH+1];
  393. WCHAR szTemplate[MSG_TITLE_LENGTH+1];
  394. WCHAR szUserName[MAX_PATH+1];
  395. DWORD dwLen = LoadString( g_hInstance, IDS_DEFAULT_MESSAGE_TITLE, szTemplate, ARRAYSIZE(szTemplate) );
  396. ASSERT( 0 != dwLen ); // Missing resource string?
  397. dwLen; // unreferenced on FRE builds.
  398. CurrentDateTimeString(szTime);
  399. //
  400. // Get user name.
  401. // User does not always have "display name"
  402. // in this case get his "sam compatible" name
  403. //
  404. ULONG MaxUserNameLength = ARRAYSIZE(szUserName);
  405. if ( !GetUserNameEx( NameDisplay, szUserName, &MaxUserNameLength ) )
  406. {
  407. MaxUserNameLength = ARRAYSIZE(szUserName);
  408. if ( !GetUserNameEx( NameSamCompatible, szUserName, &MaxUserNameLength) )
  409. {
  410. szUserName[ 0 ] = L'\0';
  411. }
  412. }
  413. // UI only - don't care if it truncates
  414. StringCchPrintf( m_szTitle, ARRAYSIZE(m_szTitle), szTemplate, szUserName, szTime );
  415. SetDlgItemText(hwndDlg, IDC_MESSAGE_TITLE, m_szTitle);
  416. SendMessage(GetDlgItem(hwndDlg, IDC_MESSAGE_TITLE), EM_LIMITTEXT, MSG_TITLE_LENGTH, 0L );
  417. }
  418. //
  419. //
  420. //
  421. void CSendMessageDlg::OnOk(HWND hwndDlg)
  422. {
  423. GetWindowText( GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE), m_szMessage, ARRAYSIZE(m_szMessage) );
  424. GetWindowText( GetDlgItem(hwndDlg, IDC_MESSAGE_TITLE), m_szTitle, ARRAYSIZE(m_szTitle) );
  425. }
  426. //
  427. //
  428. //
  429. void CSendMessageDlg::OnCommand(HWND hwndDlg,WORD NotifyId, WORD ItemId)
  430. {
  431. if (ItemId == IDC_MESSAGE_MESSAGE)
  432. {
  433. if (NotifyId == EN_CHANGE)
  434. {
  435. EnableWindow(GetDlgItem(hwndDlg, IDOK),
  436. GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE_MESSAGE)) != 0);
  437. }
  438. }
  439. }
  440. //***********************************************************************************
  441. //CConnectPasswordDlg class
  442. //***********************************************************************************
  443. //
  444. //
  445. //
  446. void CConnectPasswordDlg::OnInitDialog(HWND hwndDlg)
  447. {
  448. WCHAR szPrompt[MAX_PATH+1];
  449. LoadString( g_hInstance, m_ids, szPrompt, ARRAYSIZE(szPrompt) );
  450. SetDlgItemText(hwndDlg, IDL_CPDLG_PROMPT, szPrompt);
  451. SendMessage(GetDlgItem(hwndDlg, IDC_CPDLG_PASSWORD), EM_LIMITTEXT, PASSWORD_LENGTH, 0L );
  452. }
  453. //
  454. //
  455. //
  456. void CConnectPasswordDlg::OnOk(HWND hwndDlg)
  457. {
  458. GetWindowText(GetDlgItem(hwndDlg, IDC_CPDLG_PASSWORD), m_szPassword, PASSWORD_LENGTH);
  459. }