TerraForge3D  2.3.1
3D Terrain And Landscape Generator
SplashScreen.cpp
1#ifdef TERR3D_WIN32
2
3#include <SplashScreen.h>
4#include <resource.h>
5#include <windows.h>
6#include <stdlib.h>
7#include <time.h>
8#include <string.h>
9#include <tchar.h>
10#include <iostream>
11#include <string>
12
13#define _CRT_SECURE_NO_WARNINGS
14
15namespace SplashScreen
16{
17
18
19HBITMAP hBitmap = NULL;
20HINSTANCE hInstance;
21HWND splashWindow;
22HANDLE splashWindowThread;
23static bool isRunning;
24
25// For Future Use
26static char splashMessage[256];
27static int splashMessageLength;
28static int commandPtr;
29
30
31
32LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
33{
34 int wmId, wmEvent;
35
36 if (!isRunning)
37 {
38 DeleteObject(hBitmap);
39 PostQuitMessage(0);
40 return 0;
41 }
42
43 switch (message)
44 {
45 case WM_CREATE:
46 srand(time(NULL));
47
48 if(rand()%2==0)
49 {
50 hBitmap = (HBITMAP)LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(SPLASH1));
51 }
52
53 else
54 {
55 hBitmap = (HBITMAP)LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(SPLASH2));
56 }
57
58 break;
59
60 case WM_PAINT:
61 PAINTSTRUCT ps;
62 HDC hdc;
63 BITMAP bitmap;
64 HDC hdcMem;
65 HGDIOBJ oldBitmap;
66 hdc = BeginPaint(hwnd, &ps);
67 hdcMem = CreateCompatibleDC(hdc);
68 oldBitmap = SelectObject(hdcMem, hBitmap);
69 GetObject(hBitmap, sizeof(bitmap), &bitmap);
70 BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
71 SelectObject(hdcMem, oldBitmap);
72 DeleteDC(hdcMem);
73 /*
74 TextOutA(
75 hdc,
76 10,
77 305,
78 splashMessage,
79 splashMessageLength
80 );
81 */
82 EndPaint(hwnd, &ps);
83 break;
84
85 case WM_DESTROY:
86 DeleteObject(hBitmap);
87 PostQuitMessage(0);
88 break;
89
90 default:
91 return DefWindowProc(hwnd, message, wParam, lParam);
92 }
93
94 return 0;
95}
96
97void SetSplashMessage(std::string message)
98{
99 strcpy_s(splashMessage, message.c_str());
100 splashMessageLength = message.size();
101}
102
103void ShowSplashScreen()
104{
105 std::cout << "Hsadgbshdy\n";
106 commandPtr = 1;
107}
108
109void HideSplashScreen()
110{
111 commandPtr = 2;
112}
113
114DWORD WINAPI SetUpSplashWindow(LPVOID par)
115{
116 WNDCLASSEX wc;
117 HWND hwnd;
118 MSG Msg;
119 std::string classname = "SplashWindowClass";
120 //Step 1: Registering the Window Class
121 wc.cbSize = sizeof(WNDCLASSEX);
122 wc.style = 0;
123 wc.lpfnWndProc = WndProc;
124 wc.cbClsExtra = 0;
125 wc.cbWndExtra = 0;
126 wc.hInstance = hInstance;
127 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
128 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
129 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
130 wc.lpszMenuName = NULL;
131 wc.lpszClassName = (LPCWSTR)classname.c_str();
132 wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
133
134 if (!RegisterClassEx(&wc))
135 {
136 //MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
137 return 0;
138 }
139
140 // Step 2: Creating the Window
141 hwnd = CreateWindowEx(
142 0,
143 (LPCWSTR)classname.c_str(),
144 L"The title of my window",
145 ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU),
146 GetSystemMetrics(SM_CXSCREEN) / 2 - 300,
147 GetSystemMetrics(SM_CYSCREEN) / 2 - 225,
148 600,
149 450,
150 NULL, NULL, hInstance, NULL);
151
152 if (hwnd == NULL)
153 {
154 //MessageBox(NULL, L"Window Creation Failed!", L"Error!",
155 //MB_ICONEXCLAMATION | MB_OK);
156 return 0;
157 }
158
159 ShowScrollBar(hwnd, SB_BOTH, FALSE);
160 ShowWindow(hwnd, TRUE);
161 UpdateWindow(hwnd);
162 splashWindow = hwnd;
163
164 // Step 3: The Message Loop
165 while (GetMessage(&Msg, NULL, 0, 0) && isRunning)
166 {
167 TranslateMessage(&Msg);
168 DispatchMessage(&Msg);
169 }
170
171 return 0;
172}
173
174void Init(HINSTANCE hIn)
175{
176 isRunning = true;
177 commandPtr = 0;
178 hInstance = hIn;
179 memset(splashMessage, 0, 256);
180 memcpy(splashMessage, (char *)"Loading...\0", 11);
181 splashMessageLength = 10;
182 splashWindowThread = CreateThread(NULL, 0, SetUpSplashWindow, (void *)0, 0, 0);
183}
184void Destory()
185{
186 isRunning = false;
187 DestroyWindow(splashWindow);
188 CloseWindow(splashWindow);
189 CloseHandle(splashWindowThread);
190}
191
192}
193
194#endif