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.

285 lines
6.3 KiB

  1. // File: splash.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "conf.h"
  5. #include "GenWindow.h"
  6. #include "GenContainers.h"
  7. #include "GenControls.h"
  8. static const int DXP_LOGO_LEFT = 182;
  9. static const int DYP_LOGO_COPYRIGHT = 24;
  10. static const int LogoBorder = 10;
  11. CFrame *g_pSplashScreen = NULL;
  12. HPALETTE PaletteFromBitmap(HINSTANCE hInst, LPCTSTR pszRes)
  13. {
  14. HRSRC hFind = FindResource(hInst, pszRes, RT_BITMAP);
  15. if (NULL == hFind)
  16. {
  17. return(NULL);
  18. }
  19. HGLOBAL hRsrc = LoadResource(_Module.GetModuleInstance(), hFind);
  20. if (NULL == hRsrc)
  21. {
  22. return(NULL);
  23. }
  24. HPALETTE hRet = NULL;
  25. LPVOID pRsrc = LockResource(hRsrc);
  26. if (NULL != pRsrc)
  27. {
  28. BITMAPINFO *pbmi = reinterpret_cast<BITMAPINFO*>(pRsrc);
  29. BITMAPINFOHEADER &bmih = pbmi->bmiHeader;
  30. ASSERT(1 == bmih.biPlanes);
  31. if (8 >= bmih.biBitCount)
  32. {
  33. RGBQUAD *rgb = pbmi->bmiColors;
  34. struct
  35. {
  36. LOGPALETTE pal;
  37. PALETTEENTRY palPalEntry[256];
  38. } myPal;
  39. myPal.pal.palVersion = 0x300;
  40. myPal.pal.palNumEntries = LOWORD(bmih.biClrUsed);
  41. if (0 == myPal.pal.palNumEntries)
  42. {
  43. myPal.pal.palNumEntries = 1 << bmih.biBitCount;
  44. }
  45. ASSERT(myPal.pal.palNumEntries <= 1 << bmih.biBitCount);
  46. for (int i=myPal.pal.palNumEntries-1; i>=0; --i)
  47. {
  48. PALETTEENTRY &pe = myPal.pal.palPalEntry[i];
  49. pe.peRed = rgb[i].rgbRed;
  50. pe.peGreen = rgb[i].rgbGreen;
  51. pe.peBlue = rgb[i].rgbBlue;
  52. pe.peFlags = PC_NOCOLLAPSE;
  53. }
  54. hRet = CreatePalette(&myPal.pal);
  55. }
  56. UnlockResource(hRsrc);
  57. }
  58. FreeResource(hRsrc);
  59. return(hRet);
  60. }
  61. class CSplashFrame : public CFrame
  62. {
  63. public:
  64. CSplashFrame() : m_hPal(NULL) {}
  65. HPALETTE m_hPal;
  66. virtual HPALETTE GetPalette()
  67. {
  68. return(m_hPal);
  69. }
  70. protected:
  71. ~CSplashFrame()
  72. {
  73. if (NULL != m_hPal)
  74. {
  75. DeleteObject(m_hPal);
  76. }
  77. }
  78. } ;
  79. static HBITMAP LoadSplashBitmap()
  80. {
  81. HBITMAP hBmp = (HBITMAP) LoadImage(::GetInstanceHandle(), MAKEINTRESOURCE(IDB_SPLASH),
  82. IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_CREATEDIBSECTION);
  83. if (NULL == hBmp)
  84. {
  85. ERROR_OUT(("Error loading splash screen bitmap"));
  86. return(NULL);
  87. }
  88. BITMAP bmp;
  89. GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bmp);
  90. // Create a DC
  91. HDC hdc = CreateCompatibleDC(NULL);
  92. if (NULL == hdc)
  93. {
  94. return(hBmp);
  95. }
  96. // Use the dialog font but make sure it's the right size
  97. // it better be a scalable truetype font!
  98. LOGFONT logFont;
  99. ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &logFont );
  100. // Look for a string resource which sets the font size
  101. // and set the font size to this value if present
  102. lstrcpy(logFont.lfFaceName, RES2T(IDS_SPLASHFONT));
  103. if ('\0' == logFont.lfFaceName[0])
  104. {
  105. lstrcpy(logFont.lfFaceName, TEXT("Arial"));
  106. }
  107. logFont.lfHeight = - LoadResInt(IDS_SPLASHFONTSIZE, 11);
  108. HFONT hFont = CreateFontIndirect (&logFont);
  109. if (NULL != hFont)
  110. {
  111. SelectObject(hdc, hFont);
  112. }
  113. SelectObject(hdc, hBmp);
  114. ::SetTextColor(hdc, RGB(0, 0, 0)); // black
  115. // The following code assumes the bitmap is
  116. // a certain size, so assert on that here.
  117. // If this assertion doesn't hold the text positions
  118. // have to be adjusted.
  119. ASSERT(bmp.bmWidth == 398);
  120. ASSERT(bmp.bmHeight == 245);
  121. SetBkMode(hdc, TRANSPARENT);
  122. // Do the Copyright message (multiple lines)
  123. TCHAR sz[400]; // must be large enuf for owner+company and copyright text
  124. FLoadString(IDS_COPYRIGHT, sz, CCHMAX(sz));
  125. RECT rc ={
  126. DXP_LOGO_LEFT, DYP_LOGO_COPYRIGHT,
  127. bmp.bmWidth - LogoBorder, bmp.bmHeight - LogoBorder
  128. };
  129. DrawText(hdc, sz, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK);
  130. //#define FINAL
  131. #ifndef FINAL // Don't just delete this - compile with FINAL defined!
  132. {
  133. COLORREF bkColor = SetTextColor(hdc, RGB(0xFF, 0, 0));
  134. HFONT hFontBig = CreateFont(-28, 0, 0, 0, FW_BOLD,
  135. FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_PRECIS,
  136. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  137. DEFAULT_PITCH | FF_DONTCARE,
  138. TEXT("Arial"));
  139. FLoadString(IDS_ABOUT_OTHER, sz, CCHMAX(sz));
  140. if (NULL != hFontBig)
  141. {
  142. HFONT hOldFont = (HFONT)SelectObject (hdc, hFontBig);
  143. SetRect(&rc, 280, 151, bmp.bmWidth, bmp.bmHeight);
  144. DrawText(hdc, sz, lstrlen(sz), &rc,
  145. DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOPREFIX);
  146. SelectObject(hdc, hOldFont);
  147. DeleteObject(hFontBig);
  148. }
  149. SetTextColor(hdc, bkColor);
  150. }
  151. #endif /* FINAL */
  152. #undef FINAL
  153. DeleteDC(hdc);
  154. if (NULL != hFont)
  155. {
  156. DeleteObject(hFont);
  157. }
  158. return(hBmp);
  159. }
  160. VOID UpdateSplashScreen ( VOID );
  161. /* S T A R T S P L A S H S C R E E N */
  162. /*----------------------------------------------------------------------------
  163. %%Function: StartSplashScreen
  164. ----------------------------------------------------------------------------*/
  165. VOID StartSplashScreen(HWND hwndParent)
  166. {
  167. if (NULL != g_pSplashScreen)
  168. {
  169. return;
  170. }
  171. CSplashFrame *pFrame = new CSplashFrame();
  172. g_pSplashScreen = pFrame;
  173. if (NULL != pFrame)
  174. {
  175. if (!g_fHiColor)
  176. {
  177. pFrame->m_hPal = PaletteFromBitmap(_Module.GetModuleInstance(),
  178. MAKEINTRESOURCE(IDB_SPLASH));
  179. }
  180. if (pFrame->Create(hwndParent, g_szEmpty, WS_POPUP | WS_BORDER,
  181. WS_EX_TOOLWINDOW | g_wsLayout, -1000, -1000, 10, 10,
  182. _Module.GetModuleInstance()))
  183. {
  184. CBitmapButton *pButton = new CBitmapButton();
  185. if (NULL != pButton)
  186. {
  187. HBITMAP hBmp = LoadSplashBitmap();
  188. pButton->Create(pFrame->GetWindow(), 0, hBmp, 1);
  189. pFrame->Resize();
  190. pFrame->Layout();
  191. pButton->Layout();
  192. pFrame->MoveEnsureVisible(-1000, -1000);
  193. ShowWindow(pFrame->GetWindow(), SW_SHOW);
  194. UpdateSplashScreen();
  195. pButton->Release();
  196. }
  197. }
  198. }
  199. }
  200. /* S T O P S P L A S H S C R E E N */
  201. /*----------------------------------------------------------------------------
  202. %%Function: StopSplashScreen
  203. ----------------------------------------------------------------------------*/
  204. VOID StopSplashScreen ( VOID )
  205. {
  206. if (NULL != g_pSplashScreen)
  207. {
  208. HWND hwnd = g_pSplashScreen->GetWindow();
  209. if (NULL != hwnd)
  210. {
  211. DestroyWindow(hwnd);
  212. }
  213. g_pSplashScreen->Release();
  214. g_pSplashScreen = NULL;
  215. }
  216. }
  217. /* U P D A T E S P L A S H S C R E E N */
  218. /*----------------------------------------------------------------------------
  219. %%Function: UpdateSplashScreen
  220. ----------------------------------------------------------------------------*/
  221. VOID UpdateSplashScreen ( VOID )
  222. {
  223. if (NULL != g_pSplashScreen)
  224. {
  225. HWND hwnd = g_pSplashScreen->GetWindow();
  226. if (NULL != hwnd)
  227. {
  228. RedrawWindow(hwnd, NULL, NULL, RDW_ALLCHILDREN|RDW_UPDATENOW);
  229. }
  230. }
  231. }