-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainGUI.cpp
191 lines (164 loc) · 5.88 KB
/
MainGUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "stdafx.h"
#include "MainGUI.h"
#include "SetupGUI.h"
#include "DialogGUI.h"
#include "ProgressGUI.h"
#include "ButtonGUI.h"
#include "KeyHandler.h"
#include "ResourceLoader.h"
MainGUI MainGUIObj;
void MainGUI::Init(HWND &hWnd, HINSTANCE &hInst)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(wcex);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = MainGUI::WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = MainObjects.hInst;
wcex.hIcon = LoadIconW(MainObjects.hInst, MAKEINTRESOURCE(IDI_ICON));
wcex.hCursor = LoadCursorW(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"MainWindow";
wcex.hIconSm = LoadIconW(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
RegisterClassExW(&wcex);
hWnd = CreateWindowW(
L"MainWindow",
AppResStringsObjects.AppTitleText.c_str(),
WS_SYSMENU | DS_FIXEDSYS,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL);
if (!hWnd) {
ErrorHandler::InvokeErrorHandler(1, 0, L"Failed to create Main Window", AppResStringsObjects.AppTitleText);
}
EnableMenuItem(GetSystemMenu(hWnd, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
SetWindowLongW(hWnd, GWL_STYLE, GetWindowLongW(hWnd, GWL_STYLE) & ~WS_MINIMIZEBOX);
// Change appearence of the Main Window
DWORD dwStyle = GetWindowLongW(hWnd, GWL_STYLE);
DWORD dwRemove = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
DWORD dwNewStyle = dwStyle & ~dwRemove;
HDC hdcMonitor = GetWindowDC(NULL);
SetWindowLongW(hWnd, GWL_STYLE, dwNewStyle);
// Set position of the main window
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
SetWindowPos(hWnd, NULL, 0, 0, GetDeviceCaps(hdcMonitor, HORZRES), GetDeviceCaps(hdcMonitor, VERTRES), SWP_FRAMECHANGED);
ReleaseDC(NULL, hdcMonitor);
}
void MainGUI::Paint(HWND &hWnd)
{
PAINTSTRUCT ps;
HDC hdc;
BITMAP BkgBitmap;
BITMAP WndBitmap;
int horizontal;
int vertical;
Grass7API::Monitor::GetDesktopResolution(horizontal, vertical);
hdc = BeginPaint(hWnd, &ps);
SetStretchBltMode(hdc, HALFTONE);
// Draw Background Image
HDC hdcBkgMem = CreateCompatibleDC(hdc);
HBITMAP oldBkgBitmap = (HBITMAP)SelectObject(hdcBkgMem, BitmapObjects.hBackground);
GetObjectW(BitmapObjects.hBackground, sizeof(BkgBitmap), &BkgBitmap);
StretchBlt(hdc, 0, 0, horizontal, vertical, hdcBkgMem, 0, 0, BkgBitmap.bmWidth, BkgBitmap.bmHeight, SRCCOPY);
SelectObject(hdcBkgMem, oldBkgBitmap);
DeleteDC(hdcBkgMem);
DeleteObject(oldBkgBitmap);
// Draw Fake Window
GetObjectW(BitmapObjects.hFakeWindow, sizeof(WndBitmap), &WndBitmap);
int xPos = (horizontal - WndBitmap.bmWidth) / 2;
int yPos = (vertical - WndBitmap.bmHeight) / 2;
Grass7API::Paint::PaintTransparentBitmap(hdc, xPos, yPos - 33, BitmapObjects.hFakeWindow, { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA });
// Draw Small Logo
Grass7API::Paint::PaintTransparentBitmap(hdc, xPos + 56, yPos + 26 - 33, BitmapObjects.hSmallLogo, { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA });
// Draw Title Text
Grass7API::Paint::PaintText(hdc, xPos + 56 + 23, yPos + 26 - 33, L"Segoe UI", RGB(0, 0, 0), AppResStringsObjects.TitleBarText.c_str(), 9, 1, TRANSPARENT, FW_LIGHT);
// Paint bottom progress bar text
int hoz, ver;
Grass7API::Monitor::GetDesktopResolution(hoz, ver);
Grass7API::Paint::PaintText(hdc, 37, ver - 42, L"Segoe UI", RGB(255, 255, 255), AppResStringsObjects.ProgressBarText1.c_str(), 9, 1, TRANSPARENT, FW_LIGHT);
Grass7API::Paint::PaintText(hdc, 228, ver - 42, L"Segoe UI", RGB(255, 255, 255), AppResStringsObjects.ProgressBarText2.c_str(), 9, 1, TRANSPARENT, FW_LIGHT);
Grass7API::Paint::PaintText(hdc, 6, ver - 47, L"Segoe UI", RGB(255, 255, 255), L"1", 25, 1, TRANSPARENT, FW_LIGHT);
Grass7API::Paint::PaintText(hdc, 200, ver - 47, L"Segoe UI", RGB(255, 255, 255), L"2", 25, 1, TRANSPARENT, FW_LIGHT);
#ifdef _DEBUG
Grass7API::Paint::PaintText(hdc, 0, 0, L"Segoe UI", RGB(255, 255, 255), L"Debug Build", 9, 1, TRANSPARENT, FW_LIGHT);
#endif
EndPaint(hWnd, &ps);
}
// Main Window Window Procedure
LRESULT CALLBACK MainGUI::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_KEYDOWN:
{
KeyHandler::InvokeKeyHandler(wParam);
}
break;
case WM_LBUTTONDOWN:
{
SetFocus(hWnd);
}
break;
case WM_CLOSE:
{
if (MainObjects.doNotClose) {
return 0;
}
DestroyWindow(MainObjects.hWndDialogWindow);
DestroyWindow(MainObjects.hWndSetupWindow);
DestroyWindow(hWnd);
}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_EXIT:
::DestroyWindow(hWnd);
break;
default:
return DefWindowProcW(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
{
MainGUI::Paint(hWnd);
}
break;
// Calls the function to create the progress bar
case MAINWND_CREATE_PROG_BAR:
ProgressGUI::createProgressBar();
break;
// Calls the function to update the Collecting Information Progress Bar
case MAINWND_UPDATE_COLLECT_INFO_PROG_BAR:
ProgressGUI::updateProgressBar(hWnd, ProgressBarObjects.hProgressCtrlCollectingInfo, ProgressBarObjects.CollectingInfoPercentage);
break;
// Calls the function to update the Installing Progress Bar
case MAINWND_UPDATE_INSTALLING_PROG_BAR:
ProgressGUI::updateProgressBar(hWnd, ProgressBarObjects.hProgressCtrlInstalling, ProgressBarObjects.InstallingPercentage);
break;
// Makes text color to be transparent on the main window
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hWnd, IDC_STATIC)) {
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255, 255, 255));
return (INT_PTR)GetStockObject(NULL_BRUSH);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}