Source code of Windows XP (NT5)
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.

458 lines
14 KiB

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