Repository navigation
Expand file tree
/
Copy pathMainGUI.cpp
More file actions
210 lines (177 loc) · 5.94 KB
/
Copy pathMainGUI.cpp
File metadata and controls
210 lines (177 loc) · 5.94 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "stdafx.h"
#include "MainGUI.h"
#include "ButtonGUI.h"
#include "KeyHandler.h"
#include "ChangelogGUI.h"
MainGUI MainGUIObjects;
BOOL MainGUI::Init()
{
NONCLIENTMETRICSW ncm;
ZeroMemory(&ncm, sizeof(NONCLIENTMETRICSW));
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, FALSE);
MainObjects.hfDefault = CreateFontIndirectW(&ncm.lfMessageFont);
MainGUIObjects.szTitle.append(L"About " + BrandingStringsObjects.GenericBrandingText);
MainGUI::PopulateVersionText();
MainGUIObjects.FirstLine = 0;
MainGUIObjects.LastLine = (int)MainGUIObjects.VersionText.size() - 1;
MainGUIObjects.wSizeX = 474;
MainGUIObjects.wSizeY = 412;
MainObjects.hWndMainWindow = CreateWindowExW(
WS_EX_DLGMODALFRAME,
L"gr7About",
MainGUIObjects.szTitle.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
MainGUIObjects.wSizeX, MainGUIObjects.wSizeY,
nullptr,
nullptr,
MainObjects.hInst,
nullptr
);
if (!MainObjects.hWndMainWindow) {
MessageBoxW(nullptr, L"Failed to create the Main Window", AppResStringsObjects.ErrorTitleText.c_str(), MB_ICONERROR | MB_OK);
return 1;
}
DWORD dwStyle = GetWindowLongW(MainObjects.hWndMainWindow, GWL_STYLE);
DWORD dwRemove = WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
DWORD dwNewStyle = dwStyle & ~dwRemove;
SetWindowLongW(MainObjects.hWndMainWindow, GWL_STYLE, dwNewStyle);
MainGUIObjects.hWndStaticBar = CreateWindowW(L"STATIC", nullptr, SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE, 15, 83, 426, 2, MainObjects.hWndMainWindow, (HMENU)IDC_STATIC, MainObjects.hInst, nullptr);
if (!MainGUIObjects.hWndStaticBar) {
MessageBoxW(nullptr, L"The static bar failed to be created", AppResStringsObjects.ErrorTitleText.c_str(), MB_ICONERROR | MB_OK);
return 1;
}
if (ButtonGUI::InitOKBtn()) {
return 1;
}
if (ButtonGUI::InitChangelogBtn()) {
return 1;
}
ShowWindow(MainObjects.hWndMainWindow, SW_SHOW);
UpdateWindow(MainObjects.hWndMainWindow);
return 0;
}
LRESULT CALLBACK MainGUI::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (uMsg)
{
case WM_KEYDOWN:
{
KeyHandler::InvokeKeyHandler(wParam);
}
break;
case WM_LBUTTONDOWN:
{
SetFocus(hWnd);
}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_OKBTN:
DestroyWindow(hWnd);
break;
case ID_CHANGELOGBTN:
{
if (!IsWindow(MainObjects.hWndChangelogWindow))
ChangelogGUI::Launch();
}
break;
default:
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
BITMAP Bitmap;
COLORREF color;
HDC hdcMem;
HBITMAP oldBitmap;
RECT rchWnd;
int xPos, yPos, yPosSpacing, nSize, yPosOffset, i;
{
hdc = BeginPaint(hWnd, &ps);
// paint bitmap
hdcMem = CreateCompatibleDC(hdc);
oldBitmap = (HBITMAP)SelectObject(hdcMem, BitmapObjects.hBanner);
GetObjectW(BitmapObjects.hBanner, sizeof(Bitmap), &Bitmap);
BitBlt(hdc, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, oldBitmap);
DeleteDC(hdcMem);
DeleteObject(oldBitmap);
// Text painting options
xPos = 53;
yPos = 100;
yPosSpacing = 16;
color = RGB(0, 0, 0);
nSize = 8;
yPosOffset = 0;
GetClientRect(hWnd, &rchWnd);
for (i = MainGUIObjects.FirstLine; i <= MainGUIObjects.LastLine; i++)
{
Grass7API::Paint::PaintText(hdc, xPos, yPos + yPosOffset, L"Tahoma", color, MainGUIObjects.VersionText[i].c_str(), nSize, 1, TRANSPARENT, FW_LIGHT, &rchWnd);
yPosOffset = yPosOffset + yPosSpacing;
}
Grass7API::Paint::PaintText(hdc, xPos, yPos + 159, L"Tahoma", color, L"Name and Organization:", nSize, 1, TRANSPARENT, FW_LIGHT, &rchWnd);
Grass7API::Paint::PaintText(hdc, xPos + 15, yPos + 159 + 19, L"Tahoma", color, MainGUIObjects.RegisteredOwner.c_str(), nSize, 1, TRANSPARENT, FW_LIGHT, &rchWnd);
Grass7API::Paint::PaintText(hdc, xPos + 15, yPos + 159 + 19 + 17, L"Tahoma", color, MainGUIObjects.RegisteredOrganization.c_str(), nSize, 1, TRANSPARENT, FW_LIGHT, &rchWnd);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
BOOL MainGUI::Register()
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = MainGUI::WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = MainObjects.hInst;
wcex.hIcon = nullptr;
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wcex.hbrBackground = CreateSolidBrush(RGB(240, 240, 240));
wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"gr7About";
wcex.hIconSm = nullptr;
if (!RegisterClassExW(&wcex))
{
MessageBoxW(nullptr, L"Failed to register gr7About window class", AppResStringsObjects.ErrorTitleText.c_str(), MB_ICONERROR | MB_OK);
return 1;
}
return 0;
}
void MainGUI::PopulateVersionText()
{
// Init variables
std::wstring BuildString(MAX_PATH, 0);
std::wstring CurrentBuild(MAX_PATH, 0);
std::wstring RegisteredOwner(MAX_PATH, 0);
std::wstring RegisteredOrganization(MAX_PATH, 0);
// Load system information strings
Grass7API::SystemInfo::GetBuildString(&BuildString[0], (int)BuildString.size());
Grass7API::SystemInfo::GetCurrentBuild(&CurrentBuild[0], (int)CurrentBuild.size());
Grass7API::SystemInfo::GetRegisteredOwner(&RegisteredOwner[0], (int)RegisteredOwner.size());
Grass7API::SystemInfo::GetRegisteredOrganization(&RegisteredOrganization[0], (int)RegisteredOrganization.size());
// Set registered system owner/organization strings
MainGUIObjects.RegisteredOwner = RegisteredOwner;
MainGUIObjects.RegisteredOrganization = RegisteredOrganization;
std::wstring szBuildInfo = L"Build ";
szBuildInfo.append(BuildString);
// Put strings into VersionText array
MainGUIObjects.VersionText.push_back(BrandingStringsObjects.ShortBrandingText);
MainGUIObjects.VersionText.push_back(szBuildInfo);
MainGUIObjects.VersionText.push_back(BrandingStringsObjects.CopyrightBrandingText);
}