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.

178 lines
4.2 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. #include "header.h"
  3. #include "hhctrl.h"
  4. #include "cpaldc.h"
  5. #ifdef _DEBUG
  6. #undef THIS_FILE
  7. static const char THIS_FILE[] = __FILE__;
  8. #endif
  9. const char g_wcSplash[] = "Splash";
  10. const int CB_BORDER = 2; // Width of the border we draw around splash window
  11. const int SHADOW_WIDTH = 6; // Shadow border
  12. const int SHADOW_HEIGHT = 6;
  13. #define IDSPLASH_TIMER 9999
  14. static BITMAP bmpSplash;
  15. LRESULT SplashWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  16. void CHtmlHelpControl::CreateSplash(void)
  17. {
  18. ASSERT(m_ptblItems);
  19. if (!m_ptblItems || m_ptblItems->CountStrings() < 1)
  20. return;
  21. char szBitmap[MAX_PATH];
  22. // If current video display supports more then 256 colors, then check
  23. // for an alternate image in Item3. Note that this requires
  24. // the author to specify a timeout value for Item2.
  25. if (m_ptblItems->CountStrings() > 2) {
  26. HDC hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
  27. if( hdc && GetDeviceCaps(hdc, BITSPIXEL) > 8) {
  28. if (!ConvertToCacheFile(m_ptblItems->GetPointer(1), szBitmap))
  29. return;
  30. else
  31. goto GotImageFile;
  32. }
  33. if( hdc )
  34. DeleteDC( hdc );
  35. }
  36. if (!ConvertToCacheFile(m_ptblItems->GetPointer(1), szBitmap))
  37. return;
  38. GotImageFile:
  39. if (stristr(szBitmap, ".gif")) {
  40. if (!LoadGif(szBitmap, &g_hbmpSplash, &g_hpalSplash, this))
  41. return;
  42. }
  43. // REVIEW: If we are on a 256-color system, read the color information
  44. // and create a palette
  45. else {
  46. g_hbmpSplash = (HBITMAP) LoadImage(_Module.GetResourceInstance(), szBitmap, IMAGE_BITMAP, 0, 0,
  47. LR_LOADFROMFILE);
  48. }
  49. if (!g_hbmpSplash) {
  50. // BUGBUG: nag the help author
  51. return;
  52. }
  53. GetObject(g_hbmpSplash, sizeof(bmpSplash), &bmpSplash);
  54. if (!g_fRegisteredSpash) {
  55. WNDCLASS wc;
  56. ZERO_STRUCTURE(wc);
  57. wc.lpfnWndProc = SplashWndProc;
  58. wc.hInstance = _Module.GetModuleInstance();
  59. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  60. wc.lpszClassName = g_wcSplash;
  61. if (!RegisterClass(&wc))
  62. return; // REVIEW: should we notify the help author?
  63. g_fRegisteredSpash = TRUE;
  64. }
  65. RECT rc;
  66. // Find the parent window so the splash screen is centered over the parent
  67. {
  68. HWND hwndParent = GetParent(m_hwnd);
  69. #if defined(_DEBUG)
  70. char szClass[256];
  71. #endif
  72. while (GetWindowLong(hwndParent, GWL_STYLE) & WS_CHILD) {
  73. HWND hwnd = GetParent(hwndParent);
  74. if (IsValidWindow(hwnd)) {
  75. hwndParent = hwnd;
  76. #if defined(_DEBUG)
  77. GetClassName(hwndParent, szClass, sizeof(szClass));
  78. #endif
  79. }
  80. else
  81. break;
  82. }
  83. GetWindowRect(hwndParent, &rc);
  84. }
  85. g_hwndSplash = CreateWindowEx(WS_EX_TOPMOST, g_wcSplash, "",
  86. WS_POPUP | WS_VISIBLE,
  87. rc.left +
  88. RECT_WIDTH(rc) / 2 - (bmpSplash.bmWidth / 2),
  89. rc.top +
  90. RECT_HEIGHT(rc) / 2 - (bmpSplash.bmHeight / 2),
  91. bmpSplash.bmWidth + CB_BORDER * 2 + SHADOW_WIDTH,
  92. bmpSplash.bmHeight + CB_BORDER * 2 + SHADOW_HEIGHT,
  93. NULL, NULL, _Module.GetModuleInstance(), NULL);
  94. if (!g_hwndSplash)
  95. return;
  96. // Default to 3 seconds before deleting the splash window
  97. SetTimer(g_hwndSplash, IDSPLASH_TIMER,
  98. m_ptblItems->CountStrings() > 1 ?
  99. (UINT) Atoi(m_ptblItems->GetPointer(2)) : 2500, NULL);
  100. }
  101. LRESULT SplashWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  102. {
  103. switch (msg) {
  104. case WM_CREATE:
  105. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)
  106. ((CREATESTRUCT*) lParam)->lpCreateParams);
  107. return 0;
  108. case WM_ERASEBKGND:
  109. {
  110. HDC hdc = (HDC) wParam;
  111. PaintShadowBackground(hwnd, hdc);
  112. CPalDC cdc(g_hbmpSplash, g_hpalSplash);
  113. HPALETTE hpalOld;
  114. if (g_hpalSplash) {
  115. hpalOld = SelectPalette(hdc, g_hpalSplash, FALSE);
  116. RealizePalette(hdc);
  117. }
  118. BitBlt(hdc, CB_BORDER, CB_BORDER, bmpSplash.bmWidth,
  119. bmpSplash.bmHeight, cdc.m_hdc, 0, 0, SRCCOPY);
  120. if (g_hpalSplash)
  121. SelectPalette(hdc, hpalOld, FALSE);
  122. }
  123. return TRUE;
  124. case WM_TIMER:
  125. if (wParam == IDSPLASH_TIMER) {
  126. KillTimer(hwnd, IDSPLASH_TIMER);
  127. DestroyWindow(hwnd);
  128. g_hwndSplash = NULL;
  129. }
  130. return 0;
  131. case WM_LBUTTONDOWN:
  132. DestroyWindow(hwnd);
  133. g_hwndSplash = NULL;
  134. return 0;
  135. case WM_RBUTTONDOWN:
  136. DestroyWindow(hwnd);
  137. g_hwndSplash = NULL;
  138. // DisplayCredits();
  139. return 0;
  140. default:
  141. return (DefWindowProc(hwnd, msg, wParam, lParam));
  142. }
  143. return 0;
  144. }