SplashScreen.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // SplashScreen.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "SplashScreen.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. ///////////////////////////////////////////////////////////////////////
  29. //
  30. // SplashScreenClass
  31. //
  32. ///////////////////////////////////////////////////////////////////////
  33. SplashScreenClass::SplashScreenClass (void)
  34. : m_Size (0, 0),
  35. m_hFont (NULL),
  36. m_hBitmap (NULL),
  37. m_hMemDC (NULL)
  38. {
  39. return ;
  40. }
  41. ///////////////////////////////////////////////////////////////////////
  42. //
  43. // ~SplashScreenClass
  44. //
  45. ///////////////////////////////////////////////////////////////////////
  46. SplashScreenClass::~SplashScreenClass (void)
  47. {
  48. return ;
  49. }
  50. BEGIN_MESSAGE_MAP(SplashScreenClass, CWnd)
  51. //{{AFX_MSG_MAP(SplashScreenClass)
  52. ON_WM_CREATE()
  53. ON_WM_PAINT()
  54. ON_WM_DESTROY()
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. ///////////////////////////////////////////////////////////////////////
  58. //
  59. // OnCreate
  60. //
  61. ///////////////////////////////////////////////////////////////////////
  62. int
  63. SplashScreenClass::OnCreate (LPCREATESTRUCT lpCreateStruct)
  64. {
  65. if (CWnd::OnCreate(lpCreateStruct) == -1)
  66. return -1;
  67. //
  68. // Load the splash background from the resource section
  69. //
  70. m_hBitmap = (HBITMAP)::LoadImage ( ::AfxGetResourceHandle (),
  71. MAKEINTRESOURCE (IDB_SPLASH),
  72. IMAGE_BITMAP,
  73. 0,
  74. 0,
  75. LR_CREATEDIBSECTION);
  76. //
  77. // Get the dimensions of the BMP
  78. //
  79. BITMAP bmp_info = { 0 };
  80. if (::GetObject (m_hBitmap, sizeof (BITMAP), &bmp_info) != 0) {
  81. //
  82. // Resize the window so the BMP compeletely fills the window
  83. //
  84. m_Size.cx = bmp_info.bmWidth;
  85. m_Size.cy = bmp_info.bmHeight;
  86. SetWindowPos ( NULL,
  87. (::GetSystemMetrics (SM_CXSCREEN) >> 1) - (m_Size.cx >> 1),
  88. (::GetSystemMetrics (SM_CYSCREEN) >> 1) - (m_Size.cy >> 1),
  89. m_Size.cx,
  90. m_Size.cy,
  91. SWP_NOZORDER);
  92. //
  93. // Create a memory DC (for drawing) and the font object we will use
  94. //
  95. m_hMemDC = ::CreateCompatibleDC (NULL);
  96. m_hFont = ::CreateFont (-::MulDiv (7, GetDeviceCaps(m_hMemDC, LOGPIXELSY), 72),
  97. 0,
  98. 0,
  99. 0,
  100. FW_REGULAR,
  101. FALSE,
  102. FALSE,
  103. FALSE,
  104. ANSI_CHARSET,
  105. OUT_DEFAULT_PRECIS,
  106. CLIP_DEFAULT_PRECIS,
  107. DEFAULT_QUALITY,
  108. DEFAULT_PITCH,
  109. "Small Fonts");
  110. }
  111. SetForegroundWindow ();
  112. return 0;
  113. }
  114. ///////////////////////////////////////////////////////////////////////
  115. //
  116. // OnPaint
  117. //
  118. ///////////////////////////////////////////////////////////////////////
  119. void
  120. SplashScreenClass::OnPaint (void)
  121. {
  122. CPaintDC dc (this);
  123. if (m_hMemDC != NULL && m_hBitmap != NULL) {
  124. //
  125. // Paint the BMP into the window
  126. //
  127. HBITMAP old_bmp = (HBITMAP)::SelectObject (m_hMemDC, m_hBitmap);
  128. ::BitBlt ((HDC)dc, 0, 0, m_Size.cx, m_Size.cy, m_hMemDC, 0, 0, SRCCOPY);
  129. ::SelectObject (m_hMemDC, old_bmp);
  130. //
  131. // Update the status text in the window
  132. //
  133. Paint_Status_Text (dc);
  134. }
  135. return ;
  136. }
  137. ///////////////////////////////////////////////////////////////////////
  138. //
  139. // Set_Status_Text
  140. //
  141. ///////////////////////////////////////////////////////////////////////
  142. void
  143. SplashScreenClass::Set_Status_Text (LPCTSTR text)
  144. {
  145. m_StatusText = text;
  146. //
  147. // Repaint the status text area of the window
  148. //
  149. HDC hdc = ::GetDC (m_hWnd);
  150. Paint_Status_Text (hdc);
  151. ::ReleaseDC (m_hWnd, hdc);
  152. return ;
  153. }
  154. ///////////////////////////////////////////////////////////////////////
  155. //
  156. // Paint_Status_Text
  157. //
  158. ///////////////////////////////////////////////////////////////////////
  159. void
  160. SplashScreenClass::Paint_Status_Text (HDC hdc)
  161. {
  162. if (m_StatusText.GetLength () > 0) {
  163. //
  164. // Select the correct font, pen, and brush into the DC
  165. //
  166. HFONT old_font = (HFONT)::SelectObject (hdc, m_hFont);
  167. HPEN old_pen = (HPEN)::SelectObject (hdc, ::GetStockObject (WHITE_PEN));
  168. HBRUSH old_brush = (HBRUSH)::SelectObject (hdc, ::GetStockObject (BLACK_BRUSH));
  169. ::SetTextColor (hdc, RGB (255, 255, 255));
  170. ::SetBkColor (hdc, RGB (128, 128, 128));
  171. //
  172. // Draw the status text in its correct position
  173. //
  174. RECT rect;
  175. rect.left = 15;
  176. rect.right = m_Size.cx - 15;
  177. rect.top = 224;
  178. rect.bottom = 238;
  179. //::DrawText (hdc, m_StatusText, m_StatusText.GetLength (), &rect, DT_LEFT | DT_BOTTOM);
  180. ::ExtTextOut (hdc, 15, 225, ETO_OPAQUE, &rect, m_StatusText, m_StatusText.GetLength (), NULL);
  181. // Restore the original settings
  182. ::SelectObject (hdc, old_brush);
  183. ::SelectObject (hdc, old_pen);
  184. ::SelectObject (hdc, old_font);
  185. }
  186. return ;
  187. }
  188. ///////////////////////////////////////////////////////////////////////
  189. //
  190. // OnDestroy
  191. //
  192. ///////////////////////////////////////////////////////////////////////
  193. void
  194. SplashScreenClass::OnDestroy (void)
  195. {
  196. if (m_hMemDC != NULL) {
  197. ::DeleteDC (m_hMemDC);
  198. m_hMemDC = NULL;
  199. }
  200. if (m_hBitmap != NULL) {
  201. ::DeleteObject (m_hBitmap);
  202. m_hBitmap = NULL;
  203. }
  204. if (m_hFont != NULL) {
  205. ::DeleteObject (m_hFont);
  206. m_hFont = NULL;
  207. }
  208. CWnd::OnDestroy ();
  209. //
  210. // Its assumed this window is operating on a separate thread...
  211. //
  212. ::PostQuitMessage (0);
  213. return ;
  214. }
  215. ///////////////////////////////////////////////////////////////////////
  216. //
  217. // WindowProc
  218. //
  219. ///////////////////////////////////////////////////////////////////////
  220. LRESULT
  221. SplashScreenClass::WindowProc
  222. (
  223. UINT message,
  224. WPARAM wParam,
  225. LPARAM lParam
  226. )
  227. {
  228. if (message == WM_USER+102) {
  229. Set_Status_Text ((LPCTSTR)lParam);
  230. } else if (message == WM_USER+101) {
  231. DestroyWindow ();
  232. return 1L;
  233. }
  234. return CWnd::WindowProc (message, wParam, lParam);
  235. }
  236. ///////////////////////////////////////////////////////////////////////
  237. //
  238. // PostNcDestroy
  239. //
  240. ///////////////////////////////////////////////////////////////////////
  241. void
  242. SplashScreenClass::PostNcDestroy (void)
  243. {
  244. CWnd::PostNcDestroy ();
  245. // Hehe... :)
  246. delete this;
  247. return ;
  248. }