DXGL r641 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r640‎ | r641 | r642 >
Date:02:09, 19 January 2016
Author:admin
Status:new
Tags:
Comment:
Support borderless window "fullscreen" mode.
Add a fix that should among other things hopefully fix ZSNES's shrinking windows among other things.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/hooks.c (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -223,12 +223,18 @@
224224 {
225225 switch (dxglcfg.fullmode)
226226 {
227 - case 0:
 227+ case 0: // Fullscreen
 228+ winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
 229+ winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
 230+ SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 231+ SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_POPUP) & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER));
 232+ ShowWindow(This->hWnd, SW_MAXIMIZE);
 233+ break;
228234 case 1: // Fullscreen
229235 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
230236 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
231237 SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
232 - SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_POPUP | WS_SYSMENU) & ~(WS_CAPTION | WS_THICKFRAME));
 238+ SetWindowLongPtrA(This->hWnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
233239 ShowWindow(This->hWnd, SW_MAXIMIZE);
234240 break;
235241 case 2: // Windowed
@@ -610,14 +616,20 @@
611617 {
612618 switch (dxglcfg.fullmode)
613619 {
614 - case 0:
615 - case 1: // Fullscreen
 620+ case 0: // Fullscreen
616621 winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
617622 winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
618623 SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
619 - SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_POPUP | WS_SYSMENU) & ~(WS_CAPTION | WS_THICKFRAME));
 624+ SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_POPUP) & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER));
620625 ShowWindow(newwnd, SW_MAXIMIZE);
621626 break;
 627+ case 1: // Borderless Fullscreen
 628+ winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
 629+ winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
 630+ SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 631+ SetWindowLongPtrA(newwnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
 632+ ShowWindow(newwnd, SW_MAXIMIZE);
 633+ break;
622634 case 2: // Windowed
623635 winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
624636 winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
Index: ddraw/hooks.c
@@ -23,6 +23,7 @@
2424 // temporary references to C++ C-linked stuff
2525 void glDirectDraw7_UnrestoreDisplayMode(LPDIRECTDRAW7 lpDD7);
2626 void glDirectDraw7_SetWindowSize(LPDIRECTDRAW7 lpDD7, DWORD dwWidth, DWORD dwHeight);
 27+void glDirectDraw7_GetSizes(LPDIRECTDRAW7 lpDD7, LONG *sizes);
2728 extern DXGLCFG dxglcfg;
2829
2930 const TCHAR *wndprop = _T("DXGLWndProc");
@@ -252,6 +253,11 @@
253254 {
254255 WNDPROC parentproc;
255256 HWND_HOOK *wndhook;
 257+ STYLESTRUCT *style;
 258+ RECT r1, r2;
 259+ LONG sizes[6];
 260+ BOOL fixstyle = FALSE;
 261+ LONG winstyle, exstyle;
256262 LPDIRECTDRAW7 lpDD7;
257263 wndhook = GetWndHook(hWnd);
258264 if (!wndhook)
@@ -276,6 +282,64 @@
277283 }
278284 }
279285 break;
 286+ case WM_STYLECHANGED:
 287+ style = lParam;
 288+ if (style->styleNew == style->styleOld) break;
 289+ if (wParam == GWL_STYLE)
 290+ {
 291+ switch (dxglcfg.fullmode)
 292+ {
 293+ case 0:
 294+ // Fix fullscreen mode
 295+ if (lpDD7)
 296+ {
 297+ glDirectDraw7_GetSizes(lpDD7, sizes);
 298+ GetWindowRect(hWnd, &r1);
 299+ GetClientRect(hWnd, &r2);
 300+ winstyle = GetWindowLong(hWnd, GWL_STYLE);
 301+ exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 302+ if (!(winstyle & WS_POPUP)) fixstyle = TRUE;
 303+ if (winstyle & (WS_CAPTION | WS_THICKFRAME | WS_BORDER)) fixstyle = TRUE;
 304+ if (winstyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) fixstyle = TRUE;
 305+ if (!((r1.left == 0) && (r1.top == 0) && (r2.right == sizes[4]) && (r2.bottom == sizes[5]))) fixstyle = TRUE;
 306+ if (fixstyle)
 307+ {
 308+ SetWindowLongPtrA(hWnd, GWL_EXSTYLE, exstyle & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 309+ SetWindowLongPtrA(hWnd, GWL_STYLE, (winstyle | WS_POPUP) & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER));
 310+ SetWindowPos(hWnd, NULL, 0, 0, sizes[4], sizes[5], SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 311+ }
 312+ }
 313+ break;
 314+ case 1:
 315+ // Fix borderless mode
 316+ if (lpDD7)
 317+ {
 318+ glDirectDraw7_GetSizes(lpDD7, sizes);
 319+ GetWindowRect(hWnd, &r1);
 320+ GetClientRect(hWnd, &r2);
 321+ winstyle = GetWindowLong(hWnd, GWL_STYLE);
 322+ exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 323+ if (winstyle & (WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP)) fixstyle = TRUE;
 324+ if (winstyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) fixstyle = TRUE;
 325+ if (!((r1.left == 0) && (r1.top == 0) && (r2.right == sizes[4]) && (r2.bottom == sizes[5]))) fixstyle = TRUE;
 326+ if (fixstyle)
 327+ {
 328+ SetWindowLongPtrA(hWnd, GWL_EXSTYLE, exstyle & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 329+ SetWindowLongPtrA(hWnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
 330+ SetWindowPos(hWnd, NULL, 0, 0, sizes[4], sizes[5], SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 331+ }
 332+ }
 333+ break;
 334+ break;
 335+ case 2:
 336+ // Fix non-resizable window mode
 337+ break;
 338+ case 3:
 339+ // Fix resizable window mode
 340+ break;
 341+ }
 342+ }
 343+ break;
280344 case WM_SYSCOMMAND:
281345 if (wParam == SC_RESTORE)
282346 {
@@ -290,6 +354,7 @@
291355 if (lpDD7) glDirectDraw7_SetWindowSize(lpDD7, LOWORD(lParam), HIWORD(lParam));
292356 }
293357 }
 358+ break;
294359 }
295360 return CallWindowProc(parentproc, hWnd, uMsg, wParam, lParam);
296361 }