85 {
86
87 std::tstring name = Name;
91
92 WNDCLASSEX wndClass;
93
94
95 wndClass.cbSize = sizeof(WNDCLASSEX);
96 wndClass.style = CS_HREDRAW | CS_VREDRAW;
97 wndClass.lpfnWndProc = wndproc;
98 wndClass.cbClsExtra = 0;
99 wndClass.cbWndExtra = 0;
100 wndClass.hInstance = hinstance;
101 wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
102 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
103 wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
104 wndClass.lpszMenuName = NULL;
105 wndClass.lpszClassName = name.c_str();
106 wndClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
107
108 if (!RegisterClassEx(&wndClass))
109 {
110 std::cout << "Could not register window class!\n";
111 fflush(stdout);
112 exit(1);
113 }
114
115 int screenWidth = GetSystemMetrics(SM_CXSCREEN);
116 int screenHeight = GetSystemMetrics(SM_CYSCREEN);
117
118
120 {
121 DEVMODE dmScreenSettings;
122 memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
123 dmScreenSettings.dmSize = sizeof(dmScreenSettings);
124 dmScreenSettings.dmPelsWidth = screenWidth;
125 dmScreenSettings.dmPelsHeight = screenHeight;
126 dmScreenSettings.dmBitsPerPel = 32;
127 dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
128
129 if ((
width != (uint32_t)screenWidth) && (
height != (uint32_t)screenHeight))
130 {
131 if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
132 {
133 if (MessageBox(NULL, __T("Fullscreen Mode not supported!\n Switch to window mode?"), __T("Error"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
134 {
136 }
137 else
138 {
139 return nullptr;
140 }
141 }
142 }
143
144 }
145
146 DWORD dwExStyle;
147 DWORD dwStyle;
148
150 {
151 dwExStyle = WS_EX_APPWINDOW;
152 dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
153 }
154 else
155 {
156 dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
157 dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
158
159
160 }
161
162 RECT windowRect;
163 windowRect.left = 0L;
164 windowRect.top = 0L;
167
168 AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
169
170 uint32_t x = (GetSystemMetrics(SM_CXSCREEN) - windowRect.right) / 2;
171 uint32_t y = (GetSystemMetrics(SM_CYSCREEN) - windowRect.bottom) / 2;
172
173 window = CreateWindowEx(dwExStyle,
174 name.c_str(),
175 __T(""),
176 dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
177 x,
178 y + 100,
179 windowRect.right - windowRect.left,
180 windowRect.bottom - windowRect.top,
181 NULL,
182 NULL,
183 hinstance,
184 NULL);
185
186
187
188
190 {
191 printf("Could not create window!\n");
192 fflush(stdout);
193 return nullptr;
194
195 }
196
197 ShowWindow(
window, SW_SHOW);
198 SetForegroundWindow(
window);
200
202 }