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.

538 lines
13 KiB

  1. /* File: \wacker\tdll\banner.h (created 16-Mar-94)
  2. *
  3. * Copyright 1996 by Hilgraeve, Inc -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 14 $
  7. * $Date: 4/16/02 2:36p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <commctrl.h>
  12. #include <term\res.h>
  13. #include "globals.h"
  14. #include "tdll.h"
  15. #include "stdtyp.h"
  16. #include "assert.h"
  17. #include "file_msc.h"
  18. #include "errorbox.h"
  19. #include "banner.h"
  20. #include "misc.h"
  21. #include "upgrddlg.h"
  22. #include "stdtyp.h"
  23. #include <emu\emu.h>
  24. #include "term.hh" // This must be after emu.h
  25. LRESULT CALLBACK BannerProc(HWND, UINT, WPARAM, LPARAM);
  26. STATIC_FUNC void banner_WM_PAINT(HWND hwnd);
  27. STATIC_FUNC void banner_WM_CREATE(HWND hwnd, LPCREATESTRUCT lpstCreate);
  28. #define IDC_PB_UPGRADEINFO 101
  29. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  30. * FUNCTION: bannerRegisterClass
  31. *
  32. * DESCRIPTION:
  33. * This function registers the window class for the banner window.
  34. *
  35. * ARGUEMENTS:
  36. * The task instance handle.
  37. *
  38. * RETURNS:
  39. * The usual TRUE/FALSE from a registration function.
  40. *
  41. */
  42. BOOL bannerRegisterClass(HANDLE hInstance)
  43. {
  44. ATOM bRet = TRUE;
  45. WNDCLASSEX wnd;
  46. memset(&wnd, 0, sizeof(WNDCLASSEX));
  47. wnd.cbSize = sizeof(WNDCLASSEX);
  48. if (GetClassInfoEx(hInstance, BANNER_DISPLAY_CLASS, &wnd) == FALSE)
  49. {
  50. wnd.style = CS_HREDRAW | CS_VREDRAW;
  51. wnd.lpfnWndProc = BannerProc;
  52. wnd.cbClsExtra = 0;
  53. wnd.cbWndExtra = sizeof(HANDLE);
  54. wnd.hInstance = hInstance;
  55. wnd.hIcon = extLoadIcon(MAKEINTRESOURCE(IDI_HYPERTERMINAL));
  56. wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
  57. wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  58. wnd.lpszMenuName = NULL;
  59. wnd.lpszClassName = BANNER_DISPLAY_CLASS;
  60. wnd.hIconSm = extLoadIcon(MAKEINTRESOURCE(IDI_HYPERTERMINAL));
  61. bRet = RegisterClassEx(&wnd);
  62. }
  63. return bRet;
  64. }
  65. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  66. * FUNCTION: bannerCreateBanner
  67. *
  68. * DESCRIPTION:
  69. * This function is called to creat the banner window. The banner window is
  70. * a short lived window that the program can run without.
  71. *
  72. * ARGUEMENTS:
  73. * The task instance handle.
  74. *
  75. * RETURNS:
  76. * The handle of the banner window.
  77. *
  78. */
  79. HWND bannerCreateBanner(HANDLE hInstance, LPTSTR pszTitle)
  80. {
  81. HWND hwndBanner = NULL;
  82. hwndBanner = CreateWindow(BANNER_DISPLAY_CLASS,
  83. pszTitle,
  84. BANNER_WINDOW_STYLE,
  85. 0,
  86. 0,
  87. 100,
  88. 100,
  89. NULL,
  90. NULL,
  91. hInstance,
  92. NULL);
  93. return hwndBanner;
  94. }
  95. #define BANNER_FILE 1
  96. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  97. * FUNCTION: BannerProc
  98. *
  99. * DESCRIPTION:
  100. * This is the window procedure for the initial banner window.
  101. *
  102. * ARGUEMENTS:
  103. * The usual stuff that a window proc gets.
  104. *
  105. * RETURNS:
  106. * All sorts of different stuff.
  107. *
  108. */
  109. LRESULT CALLBACK BannerProc(HWND hwnd, UINT wMsg, WPARAM wPar, LPARAM lPar)
  110. {
  111. HBITMAP hBitmap = (HBITMAP)0;
  112. HWND hwndParent;
  113. #ifdef USE_PRIVATE_EDITION_3_BANNER
  114. HWND hwndButton = 0;
  115. #endif
  116. LPCREATESTRUCT lpstCreate = (LPCREATESTRUCT)lPar;
  117. hwndParent = 0;
  118. switch (wMsg)
  119. {
  120. case WM_CREATE:
  121. banner_WM_CREATE(hwnd, lpstCreate);
  122. break;
  123. case WM_PAINT:
  124. banner_WM_PAINT(hwnd);
  125. break;
  126. #ifdef USE_PRIVATE_EDITION_3_BANNER
  127. case WM_SETFOCUS:
  128. // When we are displaying the "Upgrade" button, it is the only
  129. // control in the banner. So we always want to have the focus
  130. // on it. - cab:12/02/96
  131. //
  132. hwndButton = GetDlgItem(hwnd, IDC_PB_UPGRADEINFO);
  133. assert(hwndButton);
  134. SetFocus(hwndButton);
  135. break;
  136. case WM_COMMAND:
  137. switch(wPar)
  138. {
  139. case IDC_PB_UPGRADEINFO:
  140. DoUpgradeDialog(hwnd);
  141. break;
  142. default:
  143. break;
  144. }
  145. break;
  146. #endif
  147. case WM_CHAR:
  148. case WM_KEYDOWN:
  149. case WM_KILLFOCUS:
  150. case WM_LBUTTONDOWN:
  151. hwndParent = (HWND)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  152. if (hwndParent)
  153. SendMessage(hwnd, WM_CLOSE, 0, 0);
  154. break;
  155. case WM_DESTROY:
  156. hBitmap = (HBITMAP)GetWindowLongPtr(hwnd, 0);
  157. hwndParent = (HWND)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  158. if (hBitmap != (HBITMAP)0)
  159. DeleteObject(hBitmap);
  160. if (hwndParent)
  161. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)0L);
  162. break;
  163. default:
  164. return DefWindowProc(hwnd, wMsg, wPar, lPar);
  165. }
  166. return 0L;
  167. }
  168. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  169. * FUNCTION: utilDrawBitmap
  170. *
  171. * DESCRIPTION:
  172. * This function draws a bitmap in a window.
  173. *
  174. * ARGUMENTS:
  175. * hWnd -- handle of the window to draw in
  176. * hBitmap -- bitmap to be drawn
  177. * xStart -- starting coordinate
  178. * yStart -- starting coordinate
  179. *
  180. * RETURNS:
  181. *
  182. */
  183. VOID FAR PASCAL utilDrawBitmap(HWND hWnd, HDC hDC, HBITMAP hBitmap,
  184. SHORT xStart, SHORT yStart)
  185. {
  186. BITMAP bm;
  187. HDC hdcMem;
  188. POINT ptSize, ptOrg;
  189. if (hWnd && !hDC)
  190. hDC = GetDC(hWnd);
  191. hdcMem = CreateCompatibleDC(hDC);
  192. SelectObject(hdcMem, hBitmap);
  193. SetMapMode(hdcMem, GetMapMode(hDC));
  194. GetObject(hBitmap, sizeof(BITMAP), (LPTSTR)&bm);
  195. // Convert device coordintes into logical coordinates.
  196. //
  197. ptSize.x = bm.bmWidth;
  198. ptSize.y = bm.bmHeight;
  199. DPtoLP(hDC, &ptSize, 1);
  200. ptOrg.x = 0;
  201. ptOrg.y = 0;
  202. DPtoLP(hdcMem, &ptOrg, 1);
  203. BitBlt(hDC, xStart, yStart, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y,
  204. SRCCOPY);
  205. DeleteDC(hdcMem);
  206. if (hWnd && !hDC)
  207. ReleaseDC(hWnd, hDC);
  208. return;
  209. }
  210. // TODO:cab,11/29/96 put this where it belongs
  211. //
  212. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  213. * FUNCTION:
  214. * fontSetWindowFont
  215. *
  216. * DESCRIPTION:
  217. * Changes the font for the given window to the one specified.
  218. *
  219. * ARGUMENTS:
  220. * hwnd - Handle of the window.
  221. * pszFontName - Name of the new font.
  222. * iPointSize - The new font's point size.
  223. *
  224. * RETURNS:
  225. * 0 if successful, -1 if error
  226. *
  227. * AUTHOR: C. Baumgartner, 11/29/96
  228. */
  229. int fontSetWindowFont(HWND hwnd, LPCTSTR pszFontName, int iPointSize)
  230. {
  231. int iPixPerLogicalInch = 0;
  232. HDC hDC = 0;
  233. HFONT hFont = 0;
  234. LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT));
  235. assert(hwnd);
  236. assert(pszFontName);
  237. // Get the pixels per logical inch in the y direction.
  238. //
  239. hDC = GetDC(hwnd);
  240. iPixPerLogicalInch = GetDeviceCaps(hDC, LOGPIXELSY);
  241. ReleaseDC(hwnd, hDC);
  242. // Compute the height of the font in logical units.
  243. // This is simply: (iPointSize * iPixPerLogicalInch) / 72,
  244. // don't ask me to derive that equation, I just got it from
  245. // Charles Petzold's book.
  246. //
  247. lf.lfHeight = -MulDiv(iPointSize, iPixPerLogicalInch, 72);
  248. // Set the font name.
  249. //
  250. //mpt:1-28-98 changed from strcpy so that it will handle dbcs font names
  251. lstrcpy(lf.lfFaceName, pszFontName);
  252. // Create the desired font.
  253. //
  254. hFont = CreateFontIndirect(&lf);
  255. if ( !hFont )
  256. {
  257. assert(hFont);
  258. return -1;
  259. }
  260. // Tell the window what it's new font is.
  261. //
  262. SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0));
  263. return 0;
  264. }
  265. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  266. * FUNCTION:
  267. *
  268. * DESCRIPTION:
  269. *
  270. * ARGUMENTS:
  271. *
  272. * RETURNS:
  273. *
  274. */
  275. STATIC_FUNC void banner_WM_CREATE(HWND hwnd, LPCREATESTRUCT lpstCreate)
  276. {
  277. RECT rc;
  278. HBITMAP hBitmap = (HBITMAP)0;
  279. BITMAP bm;
  280. INT x, y, cx, cy;
  281. #ifdef USE_PRIVATE_EDITION_3_BANNER
  282. TCHAR achUpgradeInfo[100];
  283. TCHAR ach[80];
  284. INT nSize1;
  285. #endif
  286. DWORD ExStyle;
  287. ExStyle = (DWORD)GetWindowLongPtr(hwnd, GWL_EXSTYLE);
  288. #if(WINVER >= 0x0500)
  289. //
  290. // [mhamid]: if it is mirrored then turn off mirroing.
  291. //
  292. if (ExStyle & WS_EX_LAYOUTRTL)
  293. {
  294. SetWindowLongPtr(hwnd, GWL_EXSTYLE, (LONG_PTR)(ExStyle & ~WS_EX_LAYOUTRTL));
  295. }
  296. #endif // WINVER >= 0x0500
  297. if (lpstCreate->hwndParent)
  298. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lpstCreate->hwndParent);
  299. //mpt:03-12-98 Changed the bitmap and avi to use system colors
  300. //hBitmap = LoadBitmap(glblQueryDllHinst(), MAKEINTRESOURCE(IDD_BM_BANNER));
  301. hBitmap = (HBITMAP)LoadImage(glblQueryDllHinst(),
  302. MAKEINTRESOURCE(IDD_BM_BANNER),
  303. IMAGE_BITMAP,
  304. 0,
  305. 0,
  306. LR_CREATEDIBSECTION | LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS);
  307. SetWindowLongPtr(hwnd, 0, (LONG_PTR)hBitmap);
  308. GetObject(hBitmap, sizeof(BITMAP), (LPTSTR)&bm);
  309. SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
  310. AdjustWindowRect(&rc, BANNER_WINDOW_STYLE, FALSE);
  311. cx = rc.right - rc.left;
  312. cy = rc.bottom - rc.top;
  313. x = (GetSystemMetrics(SM_CXSCREEN) - cx) / 2;
  314. y = (GetSystemMetrics(SM_CYSCREEN) - cy) / 2;
  315. MoveWindow(hwnd, x, y, cx, cy, TRUE);
  316. if (lpstCreate->hwndParent)
  317. mscCenterWindowOnWindow(hwnd, lpstCreate->hwndParent);
  318. // Create an "Upgrade Information" button. - cab:11/29/96
  319. //
  320. #ifdef USE_PRIVATE_EDITION_3_BANNER
  321. {
  322. HWND hwndButton = 0;
  323. // Create the button, but don't put any text in it yet. We'll
  324. // do that after we change the font.
  325. //
  326. hwndButton = CreateWindow("button",
  327. "",
  328. WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  329. IDN_UPGRADE_BUTTON_X,
  330. IDN_UPGRADE_BUTTON_Y,
  331. IDN_UPGRADE_BUTTON_W,
  332. IDN_UPGRADE_BUTTON_H,
  333. hwnd,
  334. (HMENU)IDC_PB_UPGRADEINFO,
  335. glblQueryDllHinst(),
  336. NULL);
  337. assert(hwndButton);
  338. // Set the text font in the button to 8 point MS Sans Serif.
  339. // mpt:1-21-98 moved font and size to resources
  340. if (LoadString(glblQueryDllHinst(), IDS_UPGRADE_FONT_SIZE,
  341. ach, sizeof(ach)/sizeof(TCHAR)))
  342. {
  343. nSize1 = atoi(ach);
  344. }
  345. else
  346. {
  347. nSize1 = -8;
  348. }
  349. LoadString(glblQueryDllHinst(), IDS_UPGRADE_FONT, ach, sizeof(ach)/sizeof(TCHAR));
  350. if ( fontSetWindowFont(hwndButton, ach, nSize1) != 0 )
  351. {
  352. assert(0);
  353. }
  354. // Set the button text.
  355. LoadString(glblQueryDllHinst(), IDS_UPGRADE_INFO,
  356. achUpgradeInfo, sizeof(achUpgradeInfo)/sizeof(TCHAR));
  357. SetWindowText(hwndButton, achUpgradeInfo);
  358. }
  359. #endif
  360. #if defined(INCL_SPINNING_GLOBE)
  361. // Create an animation control and play spinning globe.
  362. //
  363. {
  364. HWND hwndAnimate;
  365. //mpt:03-12-98 Changed the bitmap and avi to use system colors
  366. hwndAnimate = Animate_Create(hwnd, 100,
  367. WS_VISIBLE | WS_CHILD | ACS_TRANSPARENT,
  368. glblQueryDllHinst());
  369. MoveWindow(hwndAnimate, 177, 37, 118, 101, TRUE);
  370. Animate_Open(hwndAnimate, MAKEINTRESOURCE(IDR_GLOBE_AVI));
  371. if (!IsTerminalServicesEnabled())
  372. {
  373. Animate_Play(hwndAnimate, 0, -1, 1);
  374. }
  375. }
  376. #endif
  377. }
  378. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  379. * FUNCTION:
  380. *
  381. * DESCRIPTION:
  382. *
  383. * ARGUMENTS:
  384. *
  385. * RETURNS:
  386. *
  387. */
  388. STATIC_FUNC void banner_WM_PAINT(HWND hwnd)
  389. {
  390. HDC hDC;
  391. HBITMAP hBitmap;
  392. PAINTSTRUCT ps;
  393. LOGFONT lf;
  394. HFONT hFont;
  395. hDC = BeginPaint(hwnd, &ps);
  396. hBitmap = (HBITMAP)GetWindowLongPtr(hwnd, 0);
  397. #ifdef USE_PRIVATE_EDITION_3_BANNER
  398. // Don't draw over the button. - cab:11/29/96
  399. //
  400. ExcludeClipRect(hDC, IDN_UPGRADE_BUTTON_X, IDN_UPGRADE_BUTTON_Y, IDN_UPGRADE_BUTTON_X + IDN_UPGRADE_BUTTON_W,
  401. IDN_UPGRADE_BUTTON_Y + IDN_UPGRADE_BUTTON_H);
  402. #endif
  403. if (hBitmap)
  404. utilDrawBitmap((HWND)0, hDC, hBitmap, 0, 0);
  405. // In the HTPE 3 banner, the version # and lot # are now in the
  406. // lower left corner of the bitmap. - cab:11/29/96
  407. //
  408. // Here's a mean trick. The HwndFrame guy doesn't get set until
  409. // long after the banner goes up. Since we don't want the version
  410. // number on the opening banner but do want it in the about portion
  411. // this works. - mrw:3/17/95
  412. //
  413. //if (glblQueryHwndFrame())
  414. {
  415. memset(&lf, 0, sizeof(LOGFONT));
  416. #ifndef NT_EDITION
  417. lf.lfHeight = 14;
  418. #else
  419. lf.lfHeight = 12;
  420. #endif
  421. lf.lfCharSet = ANSI_CHARSET;
  422. //lf.lfWeight = FW_SEMIBOLD;
  423. strcpy(lf.lfFaceName, "Arial");
  424. hFont = CreateFontIndirect(&lf);
  425. if (hFont)
  426. {
  427. hFont = SelectObject(hDC, hFont);
  428. //SetBkColor(hDC, RGB(0,255,0));
  429. SetBkMode( hDC, TRANSPARENT );
  430. #ifndef NT_EDITION
  431. TextOut(hDC, 19, 230, "Build Date", 10);
  432. TextOut(hDC, 19, 242, __DATE__, strlen(__DATE__));
  433. TextOut(hDC, 225, 230, "Copyright� 2001", 15);
  434. TextOut(hDC, 225, 242, "Hilgraeve Inc.", 14);
  435. #else
  436. TextOut(hDC, 19, 260, "Copyright� 2001 Microsoft Corporation. All rights reserved.", 59);
  437. TextOut(hDC, 19, 272, "Portions Copyright� 1995-2001 Hilgraeve, Inc. All Rights reserved.", 66);
  438. #endif
  439. DeleteObject(SelectObject(hDC, hFont));
  440. }
  441. }
  442. EndPaint(hwnd, &ps);
  443. }
  444. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  445. * FUNCTION: bannerUnregisterClass
  446. *
  447. * DESCRIPTION:
  448. * This function unregisters the window class for the banner window.
  449. *
  450. * ARGUEMENTS:
  451. * The task instance handle.
  452. *
  453. * RETURNS:
  454. * The usual TRUE/FALSE from a registration function.
  455. *
  456. */
  457. BOOL bannerUnregisterClass(HANDLE hInstance)
  458. {
  459. return UnregisterClass(BANNER_DISPLAY_CLASS, hInstance);
  460. }