@@ -133,12 +133,12 @@ bool VideoWinAPI::ResizeScreen(const VideoMode& newSize, DisplayMode displayMode
133133 SetWindowLongPtr (screen, GWL_EXSTYLE, exStyle);
134134 displayMode_ = displayMode;
135135
136- const RECT wRect = CalculateWindowRect (displayMode, windowSize);
136+ const auto [wndArea, adjustedSize] = CalculateWindowRect (displayMode, windowSize);
137137
138- // Sett size and position
138+ // Set size and position
139139 UINT flags = SWP_SHOWWINDOW | SWP_DRAWFRAME | SWP_FRAMECHANGED;
140- SetWindowPos (screen, HWND_TOP, wRect .left , wRect .top , wRect. right - wRect. left , wRect. bottom - wRect. top , flags);
141- SetNewSize (windowSize , Extent (windowSize .width , windowSize .height ));
140+ SetWindowPos (screen, HWND_TOP, wndArea .left , wndArea .top , wndArea. getSize (). x , wndArea. getSize (). y , flags);
141+ SetNewSize (adjustedSize , Extent (adjustedSize .width , adjustedSize .height ));
142142
143143 ShowWindow (screen, SW_SHOW);
144144 SetForegroundWindow (screen);
@@ -160,37 +160,49 @@ std::pair<DWORD, DWORD> VideoWinAPI::GetStyleFlags(const DisplayMode mode) const
160160 {
161161 result.first |= WS_OVERLAPPEDWINDOW;
162162 result.second |= WS_EX_WINDOWEDGE;
163+ if (!mode.resizeable )
164+ result.first &= ~WS_THICKFRAME;
163165 }
164166 return result;
165167 }
166168}
167169
168- RECT VideoWinAPI::CalculateWindowRect (const DisplayMode mode, VideoMode size ) const
170+ std::pair<Rect, VideoMode> VideoWinAPI::CalculateWindowRect (const DisplayMode mode, VideoMode requestedSize ) const
169171{
170- RECT wRect;
171- if (mode == DisplayMode::Fullscreen)
172- {
173- wRect.left = 0 ;
174- wRect.top = 0 ;
175- } else
172+ switch (mode.type )
176173 {
177- RECT workArea;
178- SystemParametersInfo (SPI_GETWORKAREA, 0 , &workArea, 0 );
179- const unsigned waWidth = workArea.right - workArea.left ;
180- const unsigned waHeight = workArea.bottom - workArea.top ;
181- size.width = std::min<uint16_t >(size.width , waWidth);
182- size.height = std::min<uint16_t >(size.height , waHeight);
183- wRect.left = (waWidth - size.width ) / 2 ;
184- wRect.top = (waHeight - size.height ) / 2 ;
174+ case DisplayMode::Fullscreen:
175+ {
176+ const auto size = FindClosestVideoMode (requestedSize);
177+ return std::make_pair (Rect (Position::all (0 ), size.width , size.height ), size);
178+ };
179+ case DisplayMode::BorderlessWindow:
180+ {
181+ const auto size = getDesktopSize (requestedSize);
182+ return std::make_pair (Rect (Position::all (0 ), size.width , size.height ), size);
183+ }
184+ case DisplayMode::Windowed:
185+ {
186+ RECT workArea;
187+ SystemParametersInfo (SPI_GETWORKAREA, 0 , &workArea, 0 );
188+ const unsigned waWidth = workArea.right - workArea.left ;
189+ const unsigned waHeight = workArea.bottom - workArea.top ;
190+ const VideoMode size (std::min<uint16_t >(requestedSize.width , waWidth),
191+ std::min<uint16_t >(requestedSize.height , waHeight));
192+ RECT wRect;
193+ wRect.left = (waWidth - size.width ) / 2 ;
194+ wRect.top = (waHeight - size.height ) / 2 ;
195+ wRect.right = wRect.left + size.width ;
196+ wRect.bottom = wRect.top + size.height ;
197+ // Calculate real right/bottom based on the window style
198+ const auto [style, exStyle] = GetStyleFlags (mode);
199+ AdjustWindowRectEx (&wRect, style, false , exStyle);
200+ return std::make_pair (Rect (wRect.left , wRect.top , wRect.right - wRect.left , wRect.bottom - wRect.top ),
201+ size);
202+ }
185203 }
186- wRect.right = wRect.left + size.width ;
187- wRect.bottom = wRect.top + size.height ;
188204
189- const auto [style, exStyle] = GetStyleFlags (mode);
190- // Calculate real right/bottom based on the window style
191- AdjustWindowRectEx (&wRect, style, false , exStyle);
192-
193- return wRect;
205+ BOOST_UNREACHABLE_RETURN (std::make_pair (RECT{0 , 0 , requestedSize.width , requestedSize.height }, requestedSize));
194206}
195207
196208bool VideoWinAPI::RegisterAndCreateWindow (const std::string& title, const VideoMode& wndSize, DisplayMode displayMode)
@@ -215,19 +227,16 @@ bool VideoWinAPI::RegisterAndCreateWindow(const std::string& title, const VideoM
215227 return false ;
216228
217229 // Create window
218- const auto reqWindowSize = (displayMode == DisplayMode::Fullscreen) ? FindClosestVideoMode (wndSize) : wndSize;
219- const RECT wRect = CalculateWindowRect (displayMode, reqWindowSize);
220- const VideoMode adjWindowSize (static_cast <unsigned short >(wRect.right - wRect.left ),
221- static_cast <unsigned short >(wRect.bottom - wRect.top ));
230+ const auto [wndArea, adjustedSize] = CalculateWindowRect (displayMode, wndSize);
222231 const auto [style, exStyle] = GetStyleFlags (displayMode);
223232 screen =
224- CreateWindowExW (exStyle, windowClassName.c_str (), wTitle.c_str (), style, wRect .left , wRect .top ,
225- adjWindowSize. width , adjWindowSize. height , nullptr , nullptr , GetModuleHandle (nullptr ), nullptr );
233+ CreateWindowExW (exStyle, windowClassName.c_str (), wTitle.c_str (), style, wndArea .left , wndArea .top ,
234+ wndArea. getSize (). x , wndArea. getSize (). y , nullptr , nullptr , GetModuleHandle (nullptr ), nullptr );
226235
227236 if (screen == nullptr )
228237 return false ;
229238
230- SetNewSize (adjWindowSize , Extent (adjWindowSize .width , adjWindowSize .height ));
239+ SetNewSize (adjustedSize , Extent (adjustedSize .width , adjustedSize .height ));
231240
232241 SetClipboardViewer (screen);
233242
@@ -312,6 +321,24 @@ bool VideoWinAPI::MakeFullscreen(const VideoMode& resolution)
312321 return true ;
313322}
314323
324+ VideoMode VideoWinAPI::getDesktopSize (const VideoMode fallback) const
325+ {
326+ HMONITOR monitor;
327+ if (screen)
328+ monitor = MonitorFromWindow (screen, MONITOR_DEFAULTTONEAREST);
329+ else
330+ monitor = MonitorFromPoint (POINT{0 , 0 }, MONITOR_DEFAULTTOPRIMARY);
331+
332+ MONITORINFO mi{};
333+ mi.cbSize = sizeof (mi);
334+ if (GetMonitorInfo (monitor, &mi) == TRUE )
335+ {
336+ return VideoMode (static_cast <unsigned short >(mi.rcMonitor .right - mi.rcMonitor .left ),
337+ static_cast <unsigned short >(mi.rcMonitor .bottom - mi.rcMonitor .top ));
338+ } else
339+ return fallback;
340+ }
341+
315342void VideoWinAPI::DestroyScreen ()
316343{
317344 EndDialog (screen, 0 );
0 commit comments