SplashScreen.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "StdH.h"
  13. #include "resource.h"
  14. #define NAME "Splash"
  15. static HBITMAP _hbmSplash = NULL;
  16. static BITMAP _bmSplash;
  17. static HBITMAP _hbmSplashMask = NULL;
  18. static BITMAP _bmSplashMask;
  19. static HWND hwnd = NULL;
  20. static long FAR PASCAL SplashWindowProc( HWND hWnd, UINT message,
  21. WPARAM wParam, LPARAM lParam )
  22. {
  23. switch( message ) {
  24. case WM_PAINT: {
  25. PAINTSTRUCT ps;
  26. BeginPaint(hWnd, &ps);
  27. HDC hdcMem = CreateCompatibleDC(ps.hdc);
  28. SelectObject(hdcMem, _hbmSplashMask);
  29. BitBlt(ps.hdc, 0, 0, _bmSplash.bmWidth, _bmSplash.bmHeight, hdcMem, 0, 0,
  30. SRCAND);
  31. SelectObject(hdcMem, _hbmSplash);
  32. BitBlt(ps.hdc, 0, 0, _bmSplash.bmWidth, _bmSplash.bmHeight, hdcMem, 0, 0,
  33. SRCPAINT);
  34. DeleteDC(hdcMem);
  35. EndPaint(hWnd, &ps);
  36. return 0;
  37. } break;
  38. case WM_ERASEBKGND: return 1; break;
  39. }
  40. return DefWindowProc(hWnd, message, wParam, lParam);
  41. }
  42. void ShowSplashScreen(HINSTANCE hInstance)
  43. {
  44. _hbmSplash = LoadBitmapA(hInstance, (char*)IDB_SPLASH);
  45. if (_hbmSplash==NULL) {
  46. return;
  47. }
  48. _hbmSplashMask = LoadBitmapA(hInstance, (char*)IDB_SPLASHMASK);
  49. if (_hbmSplashMask==NULL) {
  50. return;
  51. }
  52. GetObject(_hbmSplash, sizeof(BITMAP), (LPSTR) &_bmSplash);
  53. GetObject(_hbmSplashMask, sizeof(BITMAP), (LPSTR) &_bmSplashMask);
  54. if (_bmSplashMask.bmWidth != _bmSplash.bmWidth
  55. ||_bmSplashMask.bmHeight != _bmSplash.bmHeight) {
  56. return;
  57. }
  58. int iScreenX = ::GetSystemMetrics(SM_CXSCREEN); // screen size
  59. int iScreenY = ::GetSystemMetrics(SM_CYSCREEN);
  60. WNDCLASSA wc;
  61. wc.style = CS_HREDRAW | CS_VREDRAW;
  62. wc.lpfnWndProc = SplashWindowProc;
  63. wc.cbClsExtra = 0;
  64. wc.cbWndExtra = 0;
  65. wc.hInstance = hInstance;
  66. wc.hIcon = LoadIcon( hInstance, (LPCTSTR)IDR_MAINFRAME );
  67. wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  68. wc.hbrBackground = NULL;
  69. wc.lpszMenuName = NAME;
  70. wc.lpszClassName = NAME;
  71. RegisterClassA(&wc);
  72. /*
  73. * create a window
  74. */
  75. hwnd = CreateWindowExA(
  76. WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW,
  77. NAME,
  78. "SeriousSam loading...", // title
  79. WS_POPUP,
  80. iScreenX/2-_bmSplash.bmWidth/2,
  81. iScreenY/2-_bmSplash.bmHeight/2,
  82. _bmSplash.bmWidth,_bmSplash.bmHeight, // window size
  83. NULL,
  84. NULL,
  85. hInstance,
  86. NULL);
  87. if(!hwnd) {
  88. return;
  89. }
  90. ShowWindow( hwnd, SW_SHOW);
  91. RECT rect;
  92. GetClientRect(hwnd, &rect);
  93. InvalidateRect(hwnd, &rect, TRUE);
  94. UpdateWindow(hwnd);
  95. }
  96. void HideSplashScreen(void)
  97. {
  98. if (hwnd==NULL) {
  99. return;
  100. }
  101. DestroyWindow(hwnd);
  102. DeleteObject(_hbmSplash);
  103. DeleteObject(_hbmSplashMask);
  104. }