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.

864 lines
26 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: welcome.c
  7. //
  8. // Contents: Microsoft Logon GUI DLL
  9. //
  10. // History: 7-14-94 RichardW Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "msgina.h"
  14. #include "wtsapi32.h"
  15. #include <stdio.h>
  16. #include <wchar.h>
  17. extern HICON hLockedIcon;
  18. // Welcome help screen stuff --dsheldon (11/16/98)
  19. // Display the help text for the Ctrl-Alt-Del help dlg --dsheldon
  20. void ShowHelpText(HWND hDlg, BOOL fSmartcard)
  21. {
  22. TCHAR szHelpText[2048];
  23. UINT idHelpText = fSmartcard ? IDS_CADSMARTCARDHELP : IDS_CADHELP;
  24. LoadString(hDllInstance, idHelpText, szHelpText, ARRAYSIZE(szHelpText));
  25. SetDlgItemText(hDlg, IDC_HELPTEXT, szHelpText);
  26. }
  27. // Help dialog wndproc --dsheldon
  28. INT_PTR WINAPI
  29. HelpDlgProc(
  30. HWND hDlg,
  31. UINT message,
  32. WPARAM wParam,
  33. LPARAM lParam
  34. )
  35. {
  36. static HBRUSH hbrWindow = NULL;
  37. static HFONT hBoldFont = NULL;
  38. PGLOBALS pGlobals;
  39. INT_PTR fReturn = FALSE;
  40. ULONG_PTR Value = 0;
  41. switch(message)
  42. {
  43. case WM_INITDIALOG:
  44. {
  45. HWND hwndAnim;
  46. HWND hwndHelpTitle;
  47. HFONT hOld;
  48. hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  49. pGlobals = (PGLOBALS) lParam;
  50. pWlxFuncs->WlxGetOption( pGlobals->hGlobalWlx,
  51. WLX_OPTION_SMART_CARD_PRESENT,
  52. &Value
  53. );
  54. ShowHelpText(hDlg, (0 != Value));
  55. // Animate the press-cad puppy
  56. hwndAnim = GetDlgItem(hDlg, IDC_ANIMATE);
  57. Animate_OpenEx(hwndAnim, hDllInstance, MAKEINTRESOURCE(IDA_ANIMATE));
  58. Animate_Play(hwndAnim, 0, (UINT) -1, (UINT) -1);
  59. // Bold the help title and the Ctrl Alt Delete words
  60. hwndHelpTitle = GetDlgItem(hDlg, IDC_HELPTITLE);
  61. hOld = (HFONT) SendMessage(hwndHelpTitle, WM_GETFONT, 0, 0);
  62. if (hOld)
  63. {
  64. LOGFONT lf;
  65. if (GetObject(hOld, sizeof(lf), &lf))
  66. {
  67. lf.lfHeight = -13;
  68. lf.lfWeight = FW_BOLD;
  69. hBoldFont = CreateFontIndirect(&lf);
  70. if (hBoldFont)
  71. {
  72. SendMessage(hwndHelpTitle, WM_SETFONT, (WPARAM) hBoldFont, 0);
  73. SendDlgItemMessage(hDlg, IDC_CTRL, WM_SETFONT, (WPARAM) hBoldFont, 0);
  74. SendDlgItemMessage(hDlg, IDC_ALT, WM_SETFONT, (WPARAM) hBoldFont, 0);
  75. SendDlgItemMessage(hDlg, IDC_DEL, WM_SETFONT, (WPARAM) hBoldFont, 0);
  76. }
  77. }
  78. }
  79. // Set the dialog's position - but only do this if the help
  80. // dialog will be reasonably on-screen
  81. if (((pGlobals->rcWelcome.left + 70) < 600) &&
  82. ((pGlobals->rcWelcome.top + 20) < 350))
  83. {
  84. SetWindowPos(hDlg, NULL, pGlobals->rcWelcome.left + 70,
  85. pGlobals->rcWelcome.top + 20, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  86. }
  87. fReturn = TRUE;
  88. }
  89. break;
  90. case WM_DESTROY:
  91. {
  92. if (hbrWindow)
  93. DeleteObject(hbrWindow);
  94. if (hBoldFont)
  95. DeleteObject(hBoldFont);
  96. }
  97. break;
  98. case WM_COMMAND:
  99. {
  100. if ((HIWORD(wParam) == BN_CLICKED) &&
  101. ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)))
  102. {
  103. EndDialog(hDlg, IDOK);
  104. }
  105. }
  106. break;
  107. case WM_CTLCOLORSTATIC:
  108. {
  109. SetBkColor((HDC) wParam, GetSysColor(COLOR_WINDOW));
  110. SetTextColor((HDC) wParam, GetSysColor(COLOR_WINDOWTEXT));
  111. fReturn = (INT_PTR) hbrWindow;
  112. }
  113. break;
  114. case WM_ERASEBKGND:
  115. {
  116. RECT rc = {0};
  117. GetClientRect(hDlg, &rc);
  118. FillRect((HDC) wParam, &rc, hbrWindow);
  119. fReturn = TRUE;
  120. }
  121. break;
  122. case WLX_WM_SAS:
  123. {
  124. // Post this to our parent (the c-a-d dialog) and exit
  125. PostMessage(GetParent(hDlg), message, wParam, lParam);
  126. EndDialog(hDlg, IDOK);
  127. }
  128. break;
  129. }
  130. return fReturn;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Function: SetWelcomeCaption
  135. //
  136. // Synopsis: Grabs the Welcome string from the registry, or the default
  137. // welcome from the resource section and slaps it into the
  138. // caption.
  139. //
  140. // Arguments: [hDlg] --
  141. //
  142. // History: 10-20-95 RichardW Created
  143. //
  144. // Notes:
  145. //
  146. //----------------------------------------------------------------------------
  147. #define MAX_CAPTION_LENGTH 256
  148. VOID
  149. SetWelcomeCaption(
  150. HWND hDlg)
  151. {
  152. WCHAR szCaption[MAX_CAPTION_LENGTH];
  153. WCHAR szDefaultCaption[MAX_CAPTION_LENGTH];
  154. DWORD Length;
  155. GetWindowText( hDlg, szDefaultCaption, MAX_CAPTION_LENGTH );
  156. szCaption[0] = TEXT('\0');
  157. // No big deal if that fails, we already have a default.
  158. GetProfileString( APPLICATION_NAME,
  159. WELCOME_CAPTION_KEY,
  160. TEXT(""),
  161. szCaption,
  162. ARRAYSIZE(szCaption) );
  163. if ( szCaption[0] != TEXT('\0') )
  164. {
  165. Length = (DWORD) wcslen( szDefaultCaption );
  166. if (ExpandEnvironmentStrings(szCaption,
  167. &szDefaultCaption[Length + 1],
  168. MAX_CAPTION_LENGTH - Length - 1))
  169. {
  170. szDefaultCaption[Length] = L' ';
  171. }
  172. SetWindowText( hDlg, szDefaultCaption );
  173. }
  174. }
  175. void SetCadMessage(HWND hDlg, PGLOBALS pGlobals, BOOL fSmartcard)
  176. {
  177. TCHAR szCadMessage[256];
  178. UINT idSzCad;
  179. RECT rcEdit;
  180. HWND hwndMessage;
  181. // Set the Press c-a-d message accordingly depending on
  182. // if we have a smartcard or not, if TS session or not
  183. if (!GetSystemMetrics(SM_REMOTESESSION))
  184. {
  185. idSzCad = fSmartcard ? IDS_PRESSCADORSMARTCARD : IDS_PRESSCAD;
  186. }
  187. else
  188. {
  189. idSzCad = fSmartcard ? IDS_PRESSCAEORSMARTCARD : IDS_PRESSCAE;
  190. }
  191. LoadString(hDllInstance, idSzCad, szCadMessage, ARRAYSIZE(szCadMessage));
  192. hwndMessage = GetDlgItem(hDlg, IDC_PRESSCAD);
  193. SetWindowText(hwndMessage, szCadMessage);
  194. SendMessage(hwndMessage, WM_SETFONT, (WPARAM) pGlobals->GinaFonts.hWelcomeFont, 0);
  195. // We now have to center the text beside the icons
  196. if (GetClientRect(hwndMessage, &rcEdit))
  197. {
  198. HDC hdcMessage;
  199. // Calculate the amount of vertical room needed for the text
  200. hdcMessage = GetDC(hwndMessage);
  201. if (hdcMessage)
  202. {
  203. HGDIOBJ hOldFont;
  204. long height;
  205. RECT rcTemp = rcEdit;
  206. // Make sure font is correct for sizing info.
  207. hOldFont = SelectObject(hdcMessage, (HGDIOBJ) pGlobals->GinaFonts.hWelcomeFont);
  208. height = (long) DrawTextEx(hdcMessage, szCadMessage, -1, &rcTemp, DT_EDITCONTROL | DT_CALCRECT | DT_WORDBREAK, NULL);
  209. SelectObject(hdcMessage, hOldFont);
  210. ReleaseDC(hwndMessage, hdcMessage);
  211. hdcMessage = NULL;
  212. if (0 < height)
  213. {
  214. rcEdit.top = (rcEdit.bottom / 2) - (height / 2);
  215. rcEdit.bottom = rcEdit.top + height;
  216. MapWindowPoints(hwndMessage, hDlg, (POINT*) &rcEdit, 2);
  217. SetWindowPos(hwndMessage, 0, rcEdit.left, rcEdit.top, rcEdit.right - rcEdit.left,
  218. rcEdit.bottom - rcEdit.top, SWP_NOZORDER);
  219. }
  220. }
  221. }
  222. }
  223. void SetIcons(HWND hDlg, BOOL fSmartcard)
  224. {
  225. static UINT rgidNoSmartcard[] = {IDC_KEYBOARD, IDC_PRESSCAD};
  226. static INT iLeftRelPos;
  227. static INT iDistance;
  228. if (iDistance == 0) {
  229. // get the left relative position of the kbd icon
  230. // and the distance we would have to move it to the left
  231. // in case we have no reader installed
  232. RECT rcSC, rcKB, rcDlg;
  233. GetWindowRect(hDlg, &rcDlg);
  234. GetWindowRect(GetDlgItem(hDlg, IDC_KEYBOARD), &rcKB);
  235. GetWindowRect(GetDlgItem(hDlg, IDC_SMARTCARD), &rcSC);
  236. iDistance = rcSC.left - rcKB.left;
  237. iLeftRelPos = rcKB.left - rcDlg.left;
  238. }
  239. // Hide the smartcard icon if not required and move over the
  240. // keyboard icon and press c-a-d message
  241. if (!fSmartcard)
  242. {
  243. HWND hwndSmartcard = GetDlgItem(hDlg, IDC_SMARTCARD);
  244. // Hide the smartcard puppy
  245. EnableWindow(hwndSmartcard, FALSE);
  246. ShowWindow(hwndSmartcard, SW_HIDE);
  247. // move the kbd icon over to the left
  248. MoveControls(hDlg, rgidNoSmartcard, ARRAYSIZE(rgidNoSmartcard),
  249. iDistance, 0, FALSE /*Don't size parent*/);
  250. }
  251. else
  252. {
  253. RECT rcKB, rcDlg;
  254. GetWindowRect(hDlg, &rcDlg);
  255. GetWindowRect(GetDlgItem(hDlg, IDC_KEYBOARD), &rcKB);
  256. if ((rcKB.left - rcDlg.left) != iLeftRelPos)
  257. {
  258. // the kbd icon needs to be moved to the right
  259. HWND hwndSmartcard = GetDlgItem(hDlg, IDC_SMARTCARD);
  260. MoveControls(hDlg, rgidNoSmartcard, ARRAYSIZE(rgidNoSmartcard),
  261. iDistance * (-1), 0, FALSE /*Don't size parent*/);
  262. EnableWindow(hwndSmartcard, TRUE);
  263. ShowWindow(hwndSmartcard, SW_SHOW);
  264. }
  265. }
  266. }
  267. BOOL FastUserSwitchingEnabled ()
  268. {
  269. //
  270. // BUGBUG : isn't there any global variable or function which can provide this information?
  271. // fast user switching is enabled if multiple users are allowed, and if its not server.
  272. //
  273. OSVERSIONINFOEX OsVersion;
  274. ZeroMemory(&OsVersion, sizeof(OSVERSIONINFOEX));
  275. OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  276. GetVersionEx( (LPOSVERSIONINFO ) &OsVersion);
  277. return (OsVersion.wProductType == VER_NT_WORKSTATION && ShellIsMultipleUsersEnabled());
  278. }
  279. BOOL GetSessionZeroUser(LPTSTR szUser, int nUserMax)
  280. {
  281. WINSTATIONINFORMATION WSInfo;
  282. ULONG Length;
  283. if (WinStationQueryInformation(
  284. SERVERNAME_CURRENT,
  285. 0,
  286. WinStationInformation,
  287. &WSInfo,
  288. sizeof(WINSTATIONINFORMATION),
  289. &Length))
  290. {
  291. if ((WSInfo.ConnectState == State_Active || WSInfo.ConnectState == State_Disconnected) &&
  292. WSInfo.UserName[0] )
  293. {
  294. if (WSInfo.Domain[0])
  295. {
  296. _snwprintf(szUser, nUserMax, TEXT("%s\\%s"), WSInfo.Domain, WSInfo.UserName);
  297. }
  298. else
  299. {
  300. wcsncpy(szUser, WSInfo.UserName, nUserMax);
  301. }
  302. szUser[nUserMax - 1] = 0; // Zero terminate
  303. return TRUE;
  304. }
  305. }
  306. return FALSE;
  307. }
  308. // ==========================================================================================
  309. // welcome dialog has 2 formats, one that looks like logon normal welcome dialog , another
  310. // that looks like "Computer Locked" dialog. When user connects to session 0 from remote (tsclient)
  311. // the dialog that appears at console need to change to "Computer Locked". so if session 0 is in
  312. // use, and if this session is created at active console. we change welcome dialog to look like
  313. // "Computer locked" dialog.
  314. // This function ComputerInUseMessage does most of the stuff related to switching these
  315. // dialog controls.
  316. // Parameters:
  317. // HWND hDlg - dialog window handle,
  318. // BOOL bShowLocked - if true show locked dialog, if false show normal logon dialog.
  319. // BOOL bInit - TRUE when this function is called for the first time.
  320. // ==========================================================================================
  321. BOOL ComputerInUseMessage(PGLOBALS pGlobals, HWND hDlg, BOOL bShowLocked, BOOL bInit, BOOL bSmartCard)
  322. {
  323. int i;
  324. LONG DlgHeight;
  325. RECT rc;
  326. // locked controls.
  327. UINT rgidLocked[] = {IDC_STATIC_LOCKEDGROUP, IDD_LOCKED_ICON, IDD_LOCKED_LINE, IDD_LOCKED_NAME_INFO, IDD_LOCKED_INSTRUCTIONS};
  328. UINT rgidWelcome[] = {IDC_STATIC_WELCOMEGROUP, IDC_SMARTCARD, IDC_KEYBOARD, IDC_PRESSCAD, IDD_CTRL_DEL_MSG, IDC_HELPLINK};
  329. int nLockedControls = sizeof(rgidLocked) / sizeof(rgidLocked[0]);
  330. int nWelcomeControls = sizeof(rgidWelcome) / sizeof(rgidWelcome[0]);
  331. struct DlgControl
  332. {
  333. HWND hWnd;
  334. RECT rect;
  335. };
  336. static RECT LockedControls[sizeof(rgidLocked) / sizeof(rgidLocked[0])];
  337. static RECT WelcomeControls[sizeof(rgidWelcome) / sizeof(rgidWelcome[0])];
  338. static bCurrentlyLocked = FALSE;
  339. if (!bInit && bCurrentlyLocked == bShowLocked)
  340. {
  341. // nothing to do.
  342. return TRUE;
  343. }
  344. if (bInit)
  345. {
  346. // setup locked icon for the locked dialog box.
  347. if ( !hLockedIcon )
  348. {
  349. hLockedIcon = LoadImage( hDllInstance,
  350. MAKEINTRESOURCE( IDI_LOCKED),
  351. IMAGE_ICON,
  352. 0, 0,
  353. LR_DEFAULTCOLOR );
  354. }
  355. SendMessage( GetDlgItem(hDlg, IDD_LOCKED_ICON),
  356. STM_SETICON,
  357. (WPARAM)hLockedIcon,
  358. 0 );
  359. //
  360. // when this function is called first time, all controls are visible.
  361. // remember their positions.
  362. //
  363. // remember positions Locked Dialog controls.
  364. for ( i = 0; i < nLockedControls; i++)
  365. {
  366. HWND hWnd = GetDlgItem(hDlg, rgidLocked[i]);
  367. ASSERT(hWnd);
  368. GetWindowRect(hWnd, &LockedControls[i] );
  369. MapWindowPoints(NULL, hDlg, (POINT*) &LockedControls[i], 2);
  370. }
  371. // remember positions for Welcome Dialog controls.
  372. for ( i = 0; i < nWelcomeControls; i++)
  373. {
  374. HWND hWnd = GetDlgItem(hDlg, rgidWelcome[i]);
  375. ASSERT(hWnd);
  376. GetWindowRect(hWnd, &WelcomeControls[i]);
  377. // in the dialog template welcome controls are placed below locked controls.
  378. // this is not where they will be placed when dialog is shown.
  379. // calculate their actual target positions.
  380. OffsetRect(&WelcomeControls[i], 0, LockedControls[0].top - LockedControls[0].bottom);
  381. MapWindowPoints(NULL, hDlg, (POINT*) &WelcomeControls[i], 2);
  382. }
  383. // hide group box controls. They were their only for simplifing our control movement calculations.
  384. ShowWindow(GetDlgItem(hDlg, rgidLocked[0]), SW_HIDE);
  385. ShowWindow(GetDlgItem(hDlg, rgidWelcome[0]), SW_HIDE);
  386. // set the dialog right for the first use.
  387. if (bShowLocked)
  388. {
  389. // we want locked desktop dialog, so disable welcome controls.
  390. for ( i = 0; i < nWelcomeControls; i++)
  391. {
  392. HWND hWnd = GetDlgItem(hDlg, rgidWelcome[i]);
  393. ASSERT(hWnd);
  394. MoveWindow(hWnd, 0, 0, 0, 0, FALSE);
  395. ShowWindow(hWnd, SW_HIDE);
  396. EnableWindow(hWnd, FALSE);
  397. }
  398. }
  399. else
  400. {
  401. // we want to welcome dialog, so remove locked desktop controls.
  402. for ( i = 1; i < nLockedControls; i++)
  403. {
  404. HWND hWnd = GetDlgItem(hDlg, rgidLocked[i]);
  405. ASSERT(hWnd);
  406. MoveWindow(hWnd, 0, 0, 0, 0, FALSE);
  407. ShowWindow(hWnd, SW_HIDE);
  408. EnableWindow(hWnd, FALSE);
  409. }
  410. // and move welcome controls to their proper positions. (i.e move them up)
  411. for ( i = 1; i < nWelcomeControls; i++)
  412. {
  413. HWND hWnd = GetDlgItem(hDlg, rgidWelcome[i]);
  414. ASSERT(hWnd);
  415. EnableWindow(hWnd, TRUE);
  416. ShowWindow(hWnd, SW_SHOW);
  417. MoveWindow(hWnd, WelcomeControls[i].left, WelcomeControls[i].top, WelcomeControls[i].right - WelcomeControls[i].left, WelcomeControls[i].bottom - WelcomeControls[i].top, FALSE);
  418. }
  419. }
  420. // set the right size for the dialog window.
  421. GetWindowRect(hDlg, &rc);
  422. MapWindowPoints(NULL, GetParent(hDlg), (LPPOINT)&rc, 2);
  423. DlgHeight = rc.bottom - rc.top;
  424. if (bShowLocked)
  425. {
  426. DlgHeight -= WelcomeControls[0].bottom - WelcomeControls[0].top;
  427. }
  428. else
  429. {
  430. DlgHeight -= LockedControls[0].bottom - LockedControls[0].top;
  431. }
  432. SetWindowPos(hDlg, NULL, 0, 0, rc.right - rc.left, DlgHeight, SWP_NOZORDER|SWP_NOMOVE);
  433. }
  434. else
  435. {
  436. if (bShowLocked)
  437. {
  438. for ( i = 1; i < nLockedControls; i++)
  439. {
  440. HWND hWnd = GetDlgItem(hDlg, rgidLocked[i]);
  441. ASSERT(hWnd);
  442. EnableWindow(hWnd, TRUE);
  443. ShowWindow(hWnd, SW_SHOW);
  444. MoveWindow(hWnd, LockedControls[i].left, LockedControls[i].top, LockedControls[i].right - LockedControls[i].left, LockedControls[i].bottom - LockedControls[i].top, FALSE);
  445. }
  446. for ( i = 1; i < nWelcomeControls; i++)
  447. {
  448. HWND hWnd = GetDlgItem(hDlg, rgidWelcome[i]);
  449. ASSERT(hWnd);
  450. MoveWindow(hWnd, 0, 0, 0, 0, FALSE);
  451. ShowWindow(hWnd, SW_HIDE);
  452. EnableWindow(hWnd, FALSE);
  453. }
  454. }
  455. else
  456. {
  457. for ( i = 1; i < nLockedControls; i++)
  458. {
  459. HWND hWnd = GetDlgItem(hDlg, rgidLocked[i]);
  460. ASSERT(hWnd);
  461. MoveWindow(hWnd, 0, 0, 0, 0, FALSE);
  462. ShowWindow(hWnd, SW_HIDE);
  463. EnableWindow(hWnd, FALSE);
  464. }
  465. for ( i = 1; i < nWelcomeControls; i++)
  466. {
  467. HWND hWnd = GetDlgItem(hDlg, rgidWelcome[i]);
  468. ASSERT(hWnd);
  469. EnableWindow(hWnd, TRUE);
  470. ShowWindow(hWnd, SW_SHOW);
  471. MoveWindow(hWnd, WelcomeControls[i].left, WelcomeControls[i].top, WelcomeControls[i].right - WelcomeControls[i].left, WelcomeControls[i].bottom - WelcomeControls[i].top, FALSE);
  472. }
  473. }
  474. GetWindowRect(hDlg, &rc);
  475. MapWindowPoints(NULL, GetParent(hDlg), (LPPOINT)&rc, 2);
  476. if (bShowLocked)
  477. DlgHeight = rc.bottom - rc.top - (WelcomeControls[0].bottom - WelcomeControls[0].top) + (LockedControls[0].bottom - LockedControls[0].top);
  478. else
  479. DlgHeight = rc.bottom - rc.top + (WelcomeControls[0].bottom - WelcomeControls[0].top) - (LockedControls[0].bottom - LockedControls[0].top);
  480. SetWindowPos(hDlg, NULL, 0, 0, rc.right - rc.left, DlgHeight, SWP_NOZORDER|SWP_NOMOVE);
  481. }
  482. if (!bShowLocked)
  483. {
  484. SetCadMessage(hDlg, pGlobals, bSmartCard);
  485. // let SetIcons hide SmartCard icon if required.
  486. SetIcons(hDlg, bSmartCard);
  487. }
  488. else
  489. {
  490. TCHAR szUser[USERNAME_LENGTH + DOMAIN_LENGTH + 2];
  491. TCHAR szMessage[MAX_STRING_BYTES];
  492. TCHAR szFinalMessage[MAX_STRING_BYTES];
  493. if (GetSessionZeroUser(szUser, USERNAME_LENGTH + DOMAIN_LENGTH + 2))
  494. {
  495. szMessage[0] = 0;
  496. LoadString(hDllInstance, IDS_LOCKED_EMAIL_NFN_MESSAGE, szMessage, MAX_STRING_BYTES);
  497. _snwprintf(szFinalMessage, sizeof(szFinalMessage)/sizeof(TCHAR), szMessage, szUser );
  498. szFinalMessage[MAX_STRING_BYTES - 1] = 0; // Zero terminate
  499. }
  500. else
  501. {
  502. //
  503. // for some reason we could not get the current session zero user.
  504. //
  505. szFinalMessage[0] = 0; // In case the following fails.
  506. LoadString(hDllInstance, IDS_LOCKED_NO_USER_MESSAGE, szFinalMessage, MAX_STRING_BYTES);
  507. }
  508. SetDlgItemText(hDlg, IDD_LOCKED_NAME_INFO, szFinalMessage);
  509. }
  510. //
  511. // update the dialog box caption, accordingly
  512. //
  513. {
  514. TCHAR szCaption[MAX_CAPTION_LENGTH];
  515. LoadString(hDllInstance, bShowLocked ? IDS_CAPTION_LOCKED_DIALOG : IDS_CAPTION_WELCOME_DIALOG, szCaption, ARRAYSIZE(szCaption));
  516. if ( szCaption[0] != TEXT('\0') )
  517. SetWindowText( hDlg, szCaption );
  518. }
  519. InvalidateRect(hDlg, NULL, TRUE);
  520. bCurrentlyLocked = bShowLocked;
  521. return TRUE;
  522. }
  523. /***************************************************************************\
  524. * FUNCTION: WelcomeDlgProc
  525. *
  526. * PURPOSE: Processes messages for welcome dialog
  527. *
  528. * RETURNS: MSGINA_DLG_SUCCESS - the user has pressed the SAS
  529. * DLG_SCREEN_SAVER_TIMEOUT - the screen-saver should be started
  530. * DLG_LOGOFF() - a logoff/shutdown request was received
  531. *
  532. * HISTORY:
  533. *
  534. * 12-09-91 Davidc Created.
  535. *
  536. \***************************************************************************/
  537. INT_PTR WINAPI
  538. WelcomeDlgProc(
  539. HWND hDlg,
  540. UINT message,
  541. WPARAM wParam,
  542. LPARAM lParam
  543. )
  544. {
  545. static HBRUSH hbrWindow = NULL;
  546. PGLOBALS pGlobals = (PGLOBALS)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  547. static BOOL bSmartCard = FALSE;
  548. static BOOL bSessionZeroInUse = FALSE;
  549. static int iSessionRegistrationCount = 0;
  550. switch (message) {
  551. case WM_INITDIALOG:
  552. {
  553. extern BOOL fEscape;
  554. ULONG_PTR Value ;
  555. pGlobals = (PGLOBALS) lParam ;
  556. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pGlobals);
  557. hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  558. //
  559. // The size of the welcome dialog defines the area that
  560. // we will paint into.
  561. //
  562. //
  563. // Size the window allowing for the caption and other stuff to
  564. // be dispalyed.
  565. //
  566. pWlxFuncs->WlxGetOption( pGlobals->hGlobalWlx,
  567. WLX_OPTION_SMART_CARD_PRESENT,
  568. &Value
  569. );
  570. if ( Value )
  571. {
  572. TCHAR szInsertCard[256];
  573. bSmartCard = TRUE;
  574. // Also change unlock message to mention smartcard
  575. LoadString(hDllInstance, IDS_INSERTCARDORSAS_UNLOCK, szInsertCard, ARRAYSIZE(szInsertCard));
  576. SetDlgItemText(hDlg, IDD_LOCKED_INSTRUCTIONS, szInsertCard);
  577. }
  578. else
  579. {
  580. bSmartCard = FALSE;
  581. }
  582. // Enable SC events (if there is no reader yet, no
  583. // events will be triggered anyway...)
  584. pWlxFuncs->WlxSetOption( pGlobals->hGlobalWlx,
  585. WLX_OPTION_USE_SMART_CARD,
  586. 1,
  587. NULL
  588. );
  589. if (GetDisableCad(pGlobals))
  590. {
  591. // Set our size to zero so we don't appear
  592. SetWindowPos(hDlg, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE |
  593. SWP_NOREDRAW | SWP_NOZORDER);
  594. pWlxFuncs->WlxSasNotify( pGlobals->hGlobalWlx,
  595. WLX_SAS_TYPE_CTRL_ALT_DEL );
  596. }
  597. else
  598. {
  599. SizeForBranding(hDlg, TRUE);
  600. }
  601. if (IsActiveConsoleSession() &&
  602. NtCurrentPeb()->SessionId != 0 &&
  603. !FastUserSwitchingEnabled())
  604. {
  605. TCHAR szUser[USERNAME_LENGTH + DOMAIN_LENGTH + 2];
  606. //
  607. // we are at temporary session created at console...
  608. //
  609. // check if a user is logged on at console session
  610. bSessionZeroInUse = GetSessionZeroUser(szUser, USERNAME_LENGTH + DOMAIN_LENGTH + 2);
  611. if (WinStationRegisterConsoleNotification(SERVERNAME_CURRENT, hDlg, NOTIFY_FOR_ALL_SESSIONS))
  612. iSessionRegistrationCount++;
  613. }
  614. else
  615. {
  616. //
  617. // this is not active console nonzero session.
  618. //
  619. bSessionZeroInUse = FALSE;
  620. }
  621. ComputerInUseMessage(pGlobals, hDlg, bSessionZeroInUse, TRUE, bSmartCard);
  622. CentreWindow(hDlg); //Center?? :)
  623. return( TRUE );
  624. }
  625. case WM_ERASEBKGND:
  626. return PaintBranding(hDlg, (HDC)wParam, 0, FALSE, TRUE, bSessionZeroInUse? COLOR_BTNFACE : COLOR_WINDOW);
  627. case WM_QUERYNEWPALETTE:
  628. return BrandingQueryNewPalete(hDlg);
  629. case WM_PALETTECHANGED:
  630. return BrandingPaletteChanged(hDlg, (HWND)wParam);
  631. case WM_NOTIFY:
  632. {
  633. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  634. int id = (int) wParam;
  635. // See if this is a help-link click
  636. if (id == IDC_HELPLINK)
  637. {
  638. if ((pnmhdr->code == NM_CLICK) || (pnmhdr->code == NM_RETURN))
  639. {
  640. // Save the coords of the welcome window so we can
  641. // position the help window relative to it
  642. GetWindowRect(hDlg, &pGlobals->rcWelcome);
  643. pWlxFuncs->WlxDialogBoxParam( pGlobals->hGlobalWlx,
  644. hDllInstance, MAKEINTRESOURCE(IDD_WELCOMEHELP_DIALOG),
  645. hDlg, HelpDlgProc, (LPARAM) pGlobals);
  646. }
  647. }
  648. return FALSE;
  649. }
  650. case WM_CTLCOLORSTATIC:
  651. {
  652. if (!bSessionZeroInUse)
  653. {
  654. SetBkColor((HDC) wParam, GetSysColor(COLOR_WINDOW));
  655. SetTextColor((HDC) wParam, GetSysColor(COLOR_WINDOWTEXT));
  656. return (INT_PTR) hbrWindow;
  657. }
  658. }
  659. break;
  660. case WM_DESTROY:
  661. {
  662. // if registered for console notification unregister now.
  663. if (iSessionRegistrationCount)
  664. {
  665. WinStationUnRegisterConsoleNotification (SERVERNAME_CURRENT, hDlg);
  666. iSessionRegistrationCount--;
  667. ASSERT(iSessionRegistrationCount == 0);
  668. }
  669. // Save the coords of the welcome window so we can
  670. // position the logon window at the same position
  671. GetWindowRect(hDlg, &pGlobals->rcWelcome);
  672. DeleteObject(hbrWindow);
  673. return FALSE;
  674. }
  675. break;
  676. case WLX_WM_SAS :
  677. if ( wParam == WLX_SAS_TYPE_SC_FIRST_READER_ARRIVED ||
  678. wParam == WLX_SAS_TYPE_SC_LAST_READER_REMOVED)
  679. {
  680. bSmartCard = (wParam == WLX_SAS_TYPE_SC_FIRST_READER_ARRIVED);
  681. SetCadMessage(hDlg, pGlobals, bSmartCard);
  682. SetIcons(hDlg, bSmartCard);
  683. ShowWindow(hDlg, SW_SHOW);
  684. return TRUE;
  685. }
  686. if ( wParam == WLX_SAS_TYPE_SC_REMOVE )
  687. {
  688. return TRUE ;
  689. }
  690. break;
  691. case WM_WTSSESSION_CHANGE:
  692. //
  693. // its possible, that we unregister for notification in wm_destroy and still receive this notification,
  694. // as the notification may already have been sent.
  695. //
  696. ASSERT(iSessionRegistrationCount < 2);
  697. if (iSessionRegistrationCount == 1)
  698. {
  699. if (lParam == 0)
  700. {
  701. //
  702. // we are interested only in logon/logoff messages from session 0.
  703. //
  704. if (wParam == WTS_SESSION_LOGON || wParam == WTS_SESSION_LOGOFF)
  705. {
  706. bSessionZeroInUse = (wParam == WTS_SESSION_LOGON);
  707. ComputerInUseMessage(pGlobals, hDlg, bSessionZeroInUse, FALSE, bSmartCard);
  708. }
  709. }
  710. }
  711. break;
  712. }
  713. // We didn't process this message
  714. return FALSE;
  715. }