Torque3D Documentation / _generateds / win32SplashScreen.cpp

win32SplashScreen.cpp

Engine/source/windowManager/win32/win32SplashScreen.cpp

More...

Public Defines

define
_WIN32_WINNT() 0x0500
define
IDI_ICON1() 103

Public Variables

Public Functions

CloseSplashWindow(HINSTANCE hinst)
HWND
CreateSplashWindow(HINSTANCE hinst)
RegisterWindowClass(HINSTANCE hinst)
SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash)

Detailed Description

Public Defines

_WIN32_WINNT() 0x0500
IDI_ICON1() 103

Public Variables

const TCHAR * c_szSplashClass 
HBITMAP gSplashImage 
HWND gSplashWnd 
HWND gSplashWndOwner 

Public Functions

CloseSplashWindow(HINSTANCE hinst)

CreateSplashWindow(HINSTANCE hinst)

RegisterWindowClass(HINSTANCE hinst)

SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash)

UnregisterSplashWindowClass(HINSTANCE hinst)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#define _WIN32_WINNT 0x0500
 25#include <windows.h>
 26#include <tchar.h>
 27
 28#include "platform/platform.h"
 29#include "console/console.h"
 30
 31// from Torque.rc
 32#define IDI_ICON1 103
 33
 34// Window Class name
 35static const TCHAR* c_szSplashClass = L"Torque3DSplashWindow";
 36
 37static HWND gSplashWndOwner = NULL;
 38static HWND gSplashWnd = NULL;
 39static HBITMAP gSplashImage = NULL;
 40
 41// Registers a window class for the splash and splash owner windows.
 42static void RegisterWindowClass(HINSTANCE hinst)
 43
 44{
 45   WNDCLASS wc = { 0 };
 46   wc.lpfnWndProc = DefWindowProc;
 47   wc.hInstance = hinst;
 48   wc.hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON1));
 49   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 50   wc.lpszClassName = c_szSplashClass;
 51   RegisterClass(&wc);
 52}
 53
 54static void UnregisterSplashWindowClass(HINSTANCE hinst)
 55{
 56   WNDCLASSEX classInfo;
 57   if (GetClassInfoEx(hinst,c_szSplashClass,&classInfo))
 58      UnregisterClass(c_szSplashClass,hinst);
 59}
 60
 61// Creates the splash owner window and the splash window.
 62static HWND CreateSplashWindow(HINSTANCE hinst)
 63
 64{
 65   RegisterWindowClass(hinst);
 66
 67   gSplashWndOwner = CreateWindow(c_szSplashClass, NULL, WS_POPUP,
 68      0, 0, 0, 0, NULL, NULL, hinst, NULL);
 69
 70   return CreateWindowEx(WS_EX_LAYERED, c_szSplashClass, NULL, WS_POPUP | WS_VISIBLE,
 71      0, 0, 0, 0, gSplashWndOwner, NULL, hinst, NULL);
 72}
 73
 74// Calls UpdateLayeredWindow to set a bitmap (with alpha) as the content of the splash window.
 75static void SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash)
 76
 77{
 78   // get the size of the bitmap
 79   BITMAP bm;
 80   GetObject(hbmpSplash, sizeof(bm), &bm);
 81   SIZE sizeSplash = { bm.bmWidth, bm.bmHeight };
 82
 83   // get the primary monitor's info
 84   POINT ptZero = { 0 };
 85   HMONITOR hmonPrimary = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
 86   MONITORINFO monitorinfo = { 0 };
 87   monitorinfo.cbSize = sizeof(monitorinfo);
 88   GetMonitorInfo(hmonPrimary, &monitorinfo);
 89
 90   // center the splash screen in the middle of the primary work area
 91   const RECT & rcWork = monitorinfo.rcWork;
 92   POINT ptOrigin;
 93   ptOrigin.x = rcWork.left + (rcWork.right - rcWork.left - sizeSplash.cx) / 2;
 94   ptOrigin.y = rcWork.top + (rcWork.bottom - rcWork.top - sizeSplash.cy) / 2;
 95
 96   // create a memory DC holding the splash bitmap
 97   HDC hdcScreen = GetDC(NULL);
 98   HDC hdcMem = CreateCompatibleDC(hdcScreen);
 99   HBITMAP hbmpOld = (HBITMAP) SelectObject(hdcMem, hbmpSplash);
100
101   // paint the window (in the right location) with the alpha-blended bitmap
102   UpdateLayeredWindow(hwndSplash, hdcScreen, &ptOrigin, &sizeSplash,
103      hdcMem, &ptZero, RGB(0, 0, 0), NULL, ULW_OPAQUE);
104
105   // delete temporary objects
106   SelectObject(hdcMem, hbmpOld);
107   DeleteDC(hdcMem);
108   ReleaseDC(NULL, hdcScreen);
109}
110
111void CloseSplashWindow(HINSTANCE hinst)
112{
113   if (gSplashWndOwner)
114   {
115      //ShowWindow(gSplashWnd, 0);  
116      DestroyWindow(gSplashWndOwner);
117      UnregisterSplashWindowClass(hinst);
118   }
119
120   gSplashWndOwner = NULL;
121   gSplashWnd = NULL;
122   
123}
124
125#ifndef TORQUE_SDL
126
127bool Platform::closeSplashWindow()
128{
129   CloseSplashWindow(GetModuleHandle(NULL));
130
131   return true;
132}
133
134bool Platform::displaySplashWindow( String path )
135{
136   if(path.isEmpty())
137      return false;
138
139#ifdef UNICODE
140   const UTF16 *lFileName = path.utf16();
141#else
142   const UTF8  *lFileName = path.c_str();
143#endif
144
145   gSplashImage = (HBITMAP) ::LoadImage(0, lFileName, 
146      IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
147
148   if (!gSplashImage)
149      return false;
150
151   gSplashWnd = CreateSplashWindow(GetModuleHandle(NULL));
152
153   if (!gSplashWnd)
154      return false;
155
156   SetSplashImage(gSplashWnd, gSplashImage);
157
158   return true;
159}
160
161#endif
162