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.

861 lines
25 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. GetProfileString( APPLICATION_NAME,
  158. WELCOME_CAPTION_KEY,
  159. TEXT(""),
  160. szCaption,
  161. ARRAYSIZE(szCaption) );
  162. if ( szCaption[0] != TEXT('\0') )
  163. {
  164. Length = (DWORD) wcslen( szDefaultCaption );
  165. if (ExpandEnvironmentStrings(szCaption,
  166. &szDefaultCaption[Length + 1],
  167. MAX_CAPTION_LENGTH - Length - 1))
  168. {
  169. szDefaultCaption[Length] = L' ';
  170. }
  171. SetWindowText( hDlg, szDefaultCaption );
  172. }
  173. }
  174. void SetCadMessage(HWND hDlg, PGLOBALS pGlobals, BOOL fSmartcard)
  175. {
  176. TCHAR szCadMessage[256];
  177. UINT idSzCad;
  178. RECT rcEdit;
  179. HWND hwndMessage;
  180. // Set the Press c-a-d message accordingly depending on
  181. // if we have a smartcard or not, if TS session or not
  182. if (!GetSystemMetrics(SM_REMOTESESSION))
  183. {
  184. idSzCad = fSmartcard ? IDS_PRESSCADORSMARTCARD : IDS_PRESSCAD;
  185. }
  186. else
  187. {
  188. idSzCad = fSmartcard ? IDS_PRESSCAEORSMARTCARD : IDS_PRESSCAE;
  189. }
  190. LoadString(hDllInstance, idSzCad, szCadMessage, ARRAYSIZE(szCadMessage));
  191. hwndMessage = GetDlgItem(hDlg, IDC_PRESSCAD);
  192. SetWindowText(hwndMessage, szCadMessage);
  193. SendMessage(hwndMessage, WM_SETFONT, (WPARAM) pGlobals->GinaFonts.hWelcomeFont, 0);
  194. // We now have to center the text beside the icons
  195. if (GetClientRect(hwndMessage, &rcEdit))
  196. {
  197. HDC hdcMessage;
  198. // Calculate the amount of vertical room needed for the text
  199. hdcMessage = GetDC(hwndMessage);
  200. if (hdcMessage)
  201. {
  202. HGDIOBJ hOldFont;
  203. long height;
  204. RECT rcTemp = rcEdit;
  205. // Make sure font is correct for sizing info.
  206. hOldFont = SelectObject(hdcMessage, (HGDIOBJ) pGlobals->GinaFonts.hWelcomeFont);
  207. height = (long) DrawTextEx(hdcMessage, szCadMessage, -1, &rcTemp, DT_EDITCONTROL | DT_CALCRECT | DT_WORDBREAK, NULL);
  208. SelectObject(hdcMessage, hOldFont);
  209. ReleaseDC(hwndMessage, hdcMessage);
  210. hdcMessage = NULL;
  211. if (0 < height)
  212. {
  213. rcEdit.top = (rcEdit.bottom / 2) - (height / 2);
  214. rcEdit.bottom = rcEdit.top + height;
  215. MapWindowPoints(hwndMessage, hDlg, (POINT*) &rcEdit, 2);
  216. SetWindowPos(hwndMessage, 0, rcEdit.left, rcEdit.top, rcEdit.right - rcEdit.left,
  217. rcEdit.bottom - rcEdit.top, SWP_NOZORDER);
  218. }
  219. }
  220. }
  221. }
  222. void SetIcons(HWND hDlg, BOOL fSmartcard)
  223. {
  224. static UINT rgidNoSmartcard[] = {IDC_KEYBOARD, IDC_PRESSCAD};
  225. static INT iLeftRelPos;
  226. static INT iDistance;
  227. if (iDistance == 0) {
  228. // get the left relative position of the kbd icon
  229. // and the distance we would have to move it to the left
  230. // in case we have no reader installed
  231. RECT rcSC, rcKB, rcDlg;
  232. GetWindowRect(hDlg, &rcDlg);
  233. GetWindowRect(GetDlgItem(hDlg, IDC_KEYBOARD), &rcKB);
  234. GetWindowRect(GetDlgItem(hDlg, IDC_SMARTCARD), &rcSC);
  235. iDistance = rcSC.left - rcKB.left;
  236. iLeftRelPos = rcKB.left - rcDlg.left;
  237. }
  238. // Hide the smartcard icon if not required and move over the
  239. // keyboard icon and press c-a-d message
  240. if (!fSmartcard)
  241. {
  242. HWND hwndSmartcard = GetDlgItem(hDlg, IDC_SMARTCARD);
  243. // Hide the smartcard puppy
  244. EnableWindow(hwndSmartcard, FALSE);
  245. ShowWindow(hwndSmartcard, SW_HIDE);
  246. // move the kbd icon over to the left
  247. MoveControls(hDlg, rgidNoSmartcard, ARRAYSIZE(rgidNoSmartcard),
  248. iDistance, 0, FALSE /*Don't size parent*/);
  249. }
  250. else
  251. {
  252. RECT rcKB, rcDlg;
  253. GetWindowRect(hDlg, &rcDlg);
  254. GetWindowRect(GetDlgItem(hDlg, IDC_KEYBOARD), &rcKB);
  255. if ((rcKB.left - rcDlg.left) != iLeftRelPos)
  256. {
  257. // the kbd icon needs to be moved to the right
  258. HWND hwndSmartcard = GetDlgItem(hDlg, IDC_SMARTCARD);
  259. MoveControls(hDlg, rgidNoSmartcard, ARRAYSIZE(rgidNoSmartcard),
  260. iDistance * (-1), 0, FALSE /*Don't size parent*/);
  261. EnableWindow(hwndSmartcard, TRUE);
  262. ShowWindow(hwndSmartcard, SW_SHOW);
  263. }
  264. }
  265. }
  266. BOOL FastUserSwitchingEnabled ()
  267. {
  268. //
  269. // BUGBUG : isn't there any global variable or function which can provide this information?
  270. // fast user switching is enabled if multiple users are allowed, and if its not server.
  271. //
  272. OSVERSIONINFOEX OsVersion;
  273. ZeroMemory(&OsVersion, sizeof(OSVERSIONINFOEX));
  274. OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  275. GetVersionEx( (LPOSVERSIONINFO ) &OsVersion);
  276. return (OsVersion.wProductType == VER_NT_WORKSTATION && ShellIsMultipleUsersEnabled());
  277. }
  278. BOOL GetSessionZeroUser(LPTSTR szUser)
  279. {
  280. WINSTATIONINFORMATION WSInfo;
  281. ULONG Length;
  282. if (WinStationQueryInformation(
  283. SERVERNAME_CURRENT,
  284. 0,
  285. WinStationInformation,
  286. &WSInfo,
  287. sizeof(WINSTATIONINFORMATION),
  288. &Length))
  289. {
  290. if ((WSInfo.ConnectState == State_Active || WSInfo.ConnectState == State_Disconnected) &&
  291. WSInfo.UserName[0] )
  292. {
  293. if (WSInfo.Domain[0])
  294. {
  295. lstrcpy(szUser, WSInfo.Domain);
  296. lstrcat(szUser, TEXT("\\"));
  297. }
  298. else
  299. {
  300. lstrcpy(szUser, TEXT(""));
  301. }
  302. lstrcat(szUser, WSInfo.UserName);
  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))
  494. {
  495. LoadString(hDllInstance, IDS_LOCKED_EMAIL_NFN_MESSAGE, szMessage, MAX_STRING_BYTES);
  496. _snwprintf(szFinalMessage, sizeof(szFinalMessage)/sizeof(TCHAR), szMessage, szUser );
  497. }
  498. else
  499. {
  500. //
  501. // for some reason we could not get the current session zero user.
  502. //
  503. LoadString(hDllInstance, IDS_LOCKED_NO_USER_MESSAGE, szFinalMessage, MAX_STRING_BYTES);
  504. }
  505. SetDlgItemText(hDlg, IDD_LOCKED_NAME_INFO, szFinalMessage);
  506. }
  507. //
  508. // update the dialog box caption, accordingly
  509. //
  510. {
  511. TCHAR szCaption[MAX_CAPTION_LENGTH];
  512. LoadString(hDllInstance, bShowLocked ? IDS_CAPTION_LOCKED_DIALOG : IDS_CAPTION_WELCOME_DIALOG, szCaption, ARRAYSIZE(szCaption));
  513. if ( szCaption[0] != TEXT('\0') )
  514. SetWindowText( hDlg, szCaption );
  515. }
  516. InvalidateRect(hDlg, NULL, TRUE);
  517. bCurrentlyLocked = bShowLocked;
  518. return TRUE;
  519. }
  520. /***************************************************************************\
  521. * FUNCTION: WelcomeDlgProc
  522. *
  523. * PURPOSE: Processes messages for welcome dialog
  524. *
  525. * RETURNS: MSGINA_DLG_SUCCESS - the user has pressed the SAS
  526. * DLG_SCREEN_SAVER_TIMEOUT - the screen-saver should be started
  527. * DLG_LOGOFF() - a logoff/shutdown request was received
  528. *
  529. * HISTORY:
  530. *
  531. * 12-09-91 Davidc Created.
  532. *
  533. \***************************************************************************/
  534. INT_PTR WINAPI
  535. WelcomeDlgProc(
  536. HWND hDlg,
  537. UINT message,
  538. WPARAM wParam,
  539. LPARAM lParam
  540. )
  541. {
  542. static HBRUSH hbrWindow = NULL;
  543. PGLOBALS pGlobals = (PGLOBALS)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  544. static BOOL bSmartCard = FALSE;
  545. static BOOL bSessionZeroInUse = FALSE;
  546. static int iSessionRegistrationCount = 0;
  547. switch (message) {
  548. case WM_INITDIALOG:
  549. {
  550. extern BOOL fEscape;
  551. ULONG_PTR Value ;
  552. pGlobals = (PGLOBALS) lParam ;
  553. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pGlobals);
  554. hbrWindow = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  555. //
  556. // The size of the welcome dialog defines the area that
  557. // we will paint into.
  558. //
  559. //
  560. // Size the window allowing for the caption and other stuff to
  561. // be dispalyed.
  562. //
  563. pWlxFuncs->WlxGetOption( pGlobals->hGlobalWlx,
  564. WLX_OPTION_SMART_CARD_PRESENT,
  565. &Value
  566. );
  567. if ( Value )
  568. {
  569. TCHAR szInsertCard[256];
  570. bSmartCard = TRUE;
  571. // Also change unlock message to mention smartcard
  572. LoadString(hDllInstance, IDS_INSERTCARDORSAS_UNLOCK, szInsertCard, ARRAYSIZE(szInsertCard));
  573. SetDlgItemText(hDlg, IDD_LOCKED_INSTRUCTIONS, szInsertCard);
  574. }
  575. else
  576. {
  577. bSmartCard = FALSE;
  578. }
  579. // Enable SC events (if there is no reader yet, no
  580. // events will be triggered anyway...)
  581. pWlxFuncs->WlxSetOption( pGlobals->hGlobalWlx,
  582. WLX_OPTION_USE_SMART_CARD,
  583. 1,
  584. NULL
  585. );
  586. if (GetDisableCad(pGlobals))
  587. {
  588. // Set our size to zero so we don't appear
  589. SetWindowPos(hDlg, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE |
  590. SWP_NOREDRAW | SWP_NOZORDER);
  591. pWlxFuncs->WlxSasNotify( pGlobals->hGlobalWlx,
  592. WLX_SAS_TYPE_CTRL_ALT_DEL );
  593. }
  594. else
  595. {
  596. SizeForBranding(hDlg, TRUE);
  597. }
  598. if (IsActiveConsoleSession() &&
  599. NtCurrentPeb()->SessionId != 0 &&
  600. !FastUserSwitchingEnabled())
  601. {
  602. TCHAR szUser[USERNAME_LENGTH + DOMAIN_LENGTH + 2];
  603. //
  604. // we are at temporary session created at console...
  605. //
  606. // check if a user is logged on at console session
  607. bSessionZeroInUse = GetSessionZeroUser(szUser);
  608. if (WinStationRegisterConsoleNotification(SERVERNAME_CURRENT, hDlg, NOTIFY_FOR_ALL_SESSIONS))
  609. iSessionRegistrationCount++;
  610. }
  611. else
  612. {
  613. //
  614. // this is not active console nonzero session.
  615. //
  616. bSessionZeroInUse = FALSE;
  617. }
  618. ComputerInUseMessage(pGlobals, hDlg, bSessionZeroInUse, TRUE, bSmartCard);
  619. CentreWindow(hDlg); //Center?? :)
  620. return( TRUE );
  621. }
  622. case WM_ERASEBKGND:
  623. return PaintBranding(hDlg, (HDC)wParam, 0, FALSE, TRUE, bSessionZeroInUse? COLOR_BTNFACE : COLOR_WINDOW);
  624. case WM_QUERYNEWPALETTE:
  625. return BrandingQueryNewPalete(hDlg);
  626. case WM_PALETTECHANGED:
  627. return BrandingPaletteChanged(hDlg, (HWND)wParam);
  628. case WM_NOTIFY:
  629. {
  630. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  631. int id = (int) wParam;
  632. // See if this is a help-link click
  633. if (id == IDC_HELPLINK)
  634. {
  635. if ((pnmhdr->code == NM_CLICK) || (pnmhdr->code == NM_RETURN))
  636. {
  637. // Save the coords of the welcome window so we can
  638. // position the help window relative to it
  639. GetWindowRect(hDlg, &pGlobals->rcWelcome);
  640. pWlxFuncs->WlxDialogBoxParam( pGlobals->hGlobalWlx,
  641. hDllInstance, MAKEINTRESOURCE(IDD_WELCOMEHELP_DIALOG),
  642. hDlg, HelpDlgProc, (LPARAM) pGlobals);
  643. }
  644. }
  645. return FALSE;
  646. }
  647. case WM_CTLCOLORSTATIC:
  648. {
  649. if (!bSessionZeroInUse)
  650. {
  651. SetBkColor((HDC) wParam, GetSysColor(COLOR_WINDOW));
  652. SetTextColor((HDC) wParam, GetSysColor(COLOR_WINDOWTEXT));
  653. return (INT_PTR) hbrWindow;
  654. }
  655. }
  656. break;
  657. case WM_DESTROY:
  658. {
  659. // if registered for console notification unregister now.
  660. if (iSessionRegistrationCount)
  661. {
  662. WinStationUnRegisterConsoleNotification (SERVERNAME_CURRENT, hDlg);
  663. iSessionRegistrationCount--;
  664. ASSERT(iSessionRegistrationCount == 0);
  665. }
  666. // Save the coords of the welcome window so we can
  667. // position the logon window at the same position
  668. GetWindowRect(hDlg, &pGlobals->rcWelcome);
  669. DeleteObject(hbrWindow);
  670. return FALSE;
  671. }
  672. break;
  673. case WLX_WM_SAS :
  674. if ( wParam == WLX_SAS_TYPE_SC_FIRST_READER_ARRIVED ||
  675. wParam == WLX_SAS_TYPE_SC_LAST_READER_REMOVED)
  676. {
  677. bSmartCard = (wParam == WLX_SAS_TYPE_SC_FIRST_READER_ARRIVED);
  678. SetCadMessage(hDlg, pGlobals, bSmartCard);
  679. SetIcons(hDlg, bSmartCard);
  680. ShowWindow(hDlg, SW_SHOW);
  681. return TRUE;
  682. }
  683. if ( wParam == WLX_SAS_TYPE_SC_REMOVE )
  684. {
  685. return TRUE ;
  686. }
  687. break;
  688. case WM_WTSSESSION_CHANGE:
  689. //
  690. // its possible, that we unregister for notification in wm_destroy and still receive this notification,
  691. // as the notification may already have been sent.
  692. //
  693. ASSERT(iSessionRegistrationCount < 2);
  694. if (iSessionRegistrationCount == 1)
  695. {
  696. if (lParam == 0)
  697. {
  698. //
  699. // we are interested only in logon/logoff messages from session 0.
  700. //
  701. if (wParam == WTS_SESSION_LOGON || wParam == WTS_SESSION_LOGOFF)
  702. {
  703. bSessionZeroInUse = (wParam == WTS_SESSION_LOGON);
  704. ComputerInUseMessage(pGlobals, hDlg, bSessionZeroInUse, FALSE, bSmartCard);
  705. }
  706. }
  707. }
  708. break;
  709. }
  710. // We didn't process this message
  711. return FALSE;
  712. }