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.

286 lines
6.6 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. USES_RES2T
  103. lstrcpy(logFont.lfFaceName, RES2T(IDS_SPLASHFONT));
  104. if ('\0' == logFont.lfFaceName[0])
  105. {
  106. lstrcpy(logFont.lfFaceName, TEXT("Arial"));
  107. }
  108. logFont.lfHeight = - LoadResInt(IDS_SPLASHFONTSIZE, 11);
  109. HFONT hFont = CreateFontIndirect (&logFont);
  110. if (NULL != hFont)
  111. {
  112. SelectObject(hdc, hFont);
  113. }
  114. SelectObject(hdc, hBmp);
  115. ::SetTextColor(hdc, RGB(0, 0, 0)); // black
  116. // The following code assumes the bitmap is
  117. // a certain size, so assert on that here.
  118. // If this assertion doesn't hold the text positions
  119. // have to be adjusted.
  120. ASSERT(bmp.bmWidth == 398);
  121. ASSERT(bmp.bmHeight == 245);
  122. SetBkMode(hdc, TRANSPARENT);
  123. // Do the Copyright message (multiple lines)
  124. TCHAR sz[400]; // must be large enuf for owner+company and copyright text
  125. FLoadString(IDS_COPYRIGHT, sz, CCHMAX(sz));
  126. RECT rc ={
  127. DXP_LOGO_LEFT, DYP_LOGO_COPYRIGHT,
  128. bmp.bmWidth - LogoBorder, bmp.bmHeight - LogoBorder
  129. };
  130. DrawText(hdc, sz, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK);
  131. //#define FINAL
  132. #ifndef FINAL // Don't just delete this - compile with FINAL defined!
  133. {
  134. COLORREF bkColor = SetTextColor(hdc, RGB(0xFF, 0, 0));
  135. HFONT hFontBig = CreateFont(-28, 0, 0, 0, FW_BOLD,
  136. FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_PRECIS,
  137. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  138. DEFAULT_PITCH | FF_DONTCARE,
  139. TEXT("Arial"));
  140. FLoadString(IDS_ABOUT_OTHER, sz, CCHMAX(sz));
  141. if (NULL != hFontBig)
  142. {
  143. HFONT hOldFont = (HFONT)SelectObject (hdc, hFontBig);
  144. SetRect(&rc, 280, 151, bmp.bmWidth, bmp.bmHeight);
  145. DrawText(hdc, sz, lstrlen(sz), &rc,
  146. DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOPREFIX);
  147. SelectObject(hdc, hOldFont);
  148. DeleteObject(hFontBig);
  149. }
  150. SetTextColor(hdc, bkColor);
  151. }
  152. #endif /* FINAL */
  153. #undef FINAL
  154. DeleteDC(hdc);
  155. if (NULL != hFont)
  156. {
  157. DeleteObject(hFont);
  158. }
  159. return(hBmp);
  160. }
  161. VOID UpdateSplashScreen ( VOID );
  162. /* S T A R T S P L A S H S C R E E N */
  163. /*----------------------------------------------------------------------------
  164. %%Function: StartSplashScreen
  165. ----------------------------------------------------------------------------*/
  166. VOID StartSplashScreen(HWND hwndParent)
  167. {
  168. if (NULL != g_pSplashScreen)
  169. {
  170. return;
  171. }
  172. CSplashFrame *pFrame = new CSplashFrame();
  173. g_pSplashScreen = pFrame;
  174. if (NULL != pFrame)
  175. {
  176. if (!g_fHiColor)
  177. {
  178. pFrame->m_hPal = PaletteFromBitmap(_Module.GetModuleInstance(),
  179. MAKEINTRESOURCE(IDB_SPLASH));
  180. }
  181. if (pFrame->Create(hwndParent, g_szEmpty, WS_POPUP | WS_BORDER,
  182. WS_EX_TOOLWINDOW | g_wsLayout, -1000, -1000, 10, 10,
  183. _Module.GetModuleInstance()))
  184. {
  185. CBitmapButton *pButton = new CBitmapButton();
  186. if (NULL != pButton)
  187. {
  188. HBITMAP hBmp = LoadSplashBitmap();
  189. pButton->Create(pFrame->GetWindow(), 0, hBmp, 1);
  190. pFrame->Resize();
  191. pFrame->Layout();
  192. pButton->Layout();
  193. pFrame->MoveEnsureVisible(-1000, -1000);
  194. ShowWindow(pFrame->GetWindow(), SW_SHOW);
  195. UpdateSplashScreen();
  196. pButton->Release();
  197. }
  198. }
  199. }
  200. }
  201. /* S T O P S P L A S H S C R E E N */
  202. /*----------------------------------------------------------------------------
  203. %%Function: StopSplashScreen
  204. ----------------------------------------------------------------------------*/
  205. VOID StopSplashScreen ( VOID )
  206. {
  207. if (NULL != g_pSplashScreen)
  208. {
  209. HWND hwnd = g_pSplashScreen->GetWindow();
  210. if (NULL != hwnd)
  211. {
  212. DestroyWindow(hwnd);
  213. }
  214. g_pSplashScreen->Release();
  215. g_pSplashScreen = NULL;
  216. }
  217. }
  218. /* U P D A T E S P L A S H S C R E E N */
  219. /*----------------------------------------------------------------------------
  220. %%Function: UpdateSplashScreen
  221. ----------------------------------------------------------------------------*/
  222. VOID UpdateSplashScreen ( VOID )
  223. {
  224. if (NULL != g_pSplashScreen)
  225. {
  226. HWND hwnd = g_pSplashScreen->GetWindow();
  227. if (NULL != hwnd)
  228. {
  229. RedrawWindow(hwnd, NULL, NULL, RDW_ALLCHILDREN|RDW_UPDATENOW);
  230. }
  231. }
  232. }