DXGL r642 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r641‎ | r642 | r643 >
Date:01:05, 21 January 2016
Author:admin
Status:new
Tags:
Comment:
Protect forced windowed modes from style manipulation.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/hooks.c (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -241,7 +241,7 @@
242242 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
243243 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
244244 SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
245 - SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
 245+ SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP));
246246 ShowWindow(This->hWnd, SW_MAXIMIZE);
247247 break;
248248 case 3: // Windowed resizable
@@ -248,7 +248,7 @@
249249 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
250250 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
251251 SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
252 - SetWindowLongPtrA(This->hWnd, GWL_STYLE, winstyle | WS_OVERLAPPEDWINDOW);
 252+ SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
253253 ShowWindow(This->hWnd, SW_MAXIMIZE);
254254 break;
255255 }
@@ -634,7 +634,7 @@
635635 winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
636636 winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
637637 SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
638 - SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
 638+ SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP));
639639 ShowWindow(newwnd, SW_NORMAL);
640640 screenx = GetSystemMetrics(SM_CXSCREEN);
641641 screeny = GetSystemMetrics(SM_CYSCREEN);
@@ -650,7 +650,7 @@
651651 winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
652652 winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
653653 SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
654 - SetWindowLongPtrA(newwnd, GWL_STYLE, winstyle | WS_SYSMENU | WS_OVERLAPPEDWINDOW);
 654+ SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
655655 ShowWindow(newwnd, SW_NORMAL);
656656 screenx = GetSystemMetrics(SM_CXSCREEN);
657657 screeny = GetSystemMetrics(SM_CYSCREEN);
Index: ddraw/hooks.c
@@ -320,7 +320,7 @@
321321 winstyle = GetWindowLong(hWnd, GWL_STYLE);
322322 exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
323323 if (winstyle & (WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP)) fixstyle = TRUE;
324 - if (winstyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) fixstyle = TRUE;
 324+ if (exstyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) fixstyle = TRUE;
325325 if (!((r1.left == 0) && (r1.top == 0) && (r2.right == sizes[4]) && (r2.bottom == sizes[5]))) fixstyle = TRUE;
326326 if (fixstyle)
327327 {
@@ -330,12 +330,44 @@
331331 }
332332 }
333333 break;
334 - break;
335334 case 2:
336335 // Fix non-resizable window mode
 336+ if (lpDD7)
 337+ {
 338+ glDirectDraw7_GetSizes(lpDD7, sizes);
 339+ GetClientRect(hWnd, &r2);
 340+ winstyle = GetWindowLong(hWnd, GWL_STYLE);
 341+ exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 342+ if (winstyle & (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP)) fixstyle = TRUE;
 343+ if (!(winstyle & (WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP)))) fixstyle = TRUE;
 344+ if (!(exstyle & WS_EX_APPWINDOW)) fixstyle = TRUE;
 345+ if (!((r2.right == sizes[4]) && (r2.bottom == sizes[5]))) fixstyle = TRUE;
 346+ if (fixstyle)
 347+ {
 348+ SetWindowLongPtrA(hWnd, GWL_EXSTYLE, exstyle | WS_EX_APPWINDOW);
 349+ SetWindowLongPtrA(hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP));
 350+ SetWindowPos(hWnd, NULL, 0, 0, sizes[4], sizes[5], SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 351+ }
 352+ }
337353 break;
338354 case 3:
339355 // Fix resizable window mode
 356+ if (lpDD7)
 357+ {
 358+ glDirectDraw7_GetSizes(lpDD7, sizes);
 359+ GetClientRect(hWnd, &r2);
 360+ winstyle = GetWindowLong(hWnd, GWL_STYLE);
 361+ exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 362+ if (winstyle & (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP)) fixstyle = TRUE;
 363+ if (!(winstyle & WS_OVERLAPPEDWINDOW)) fixstyle = TRUE;
 364+ if (!(exstyle & WS_EX_APPWINDOW)) fixstyle = TRUE;
 365+ if (fixstyle)
 366+ {
 367+ SetWindowLongPtrA(hWnd, GWL_EXSTYLE, exstyle | WS_EX_APPWINDOW);
 368+ SetWindowLongPtrA(hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
 369+ SetWindowPos(hWnd, NULL, 0, 0, sizes[4], sizes[5], SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 370+ }
 371+ }
340372 break;
341373 }
342374 }