DXGL r575 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r574‎ | r575 | r576 >
Date:18:59, 21 December 2014
Author:admin
Status:new
Tags:
Comment:
Fix crashes with Alt-tab handling.
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderWindow.cpp (modified) (history)
  • /ddraw/hooks.c (added) (history)
  • /ddraw/hooks.h (added) (history)
  • /dxglcfg2 (modified) (history)

Diff [purge]

Index: dxglcfg2
Property changes on: dxglcfg2
___________________________________________________________________
Added: svn:global-ignores
## -0,0 +1 ##
 1+Debug No MSVCRT
Index: ddraw/ddraw.vcxproj
@@ -285,6 +285,7 @@
286286 <ClInclude Include="glRenderer.h" />
287287 <ClInclude Include="glRenderWindow.h" />
288288 <ClInclude Include="glUtil.h" />
 289+ <ClInclude Include="hooks.h" />
289290 <ClInclude Include="include\d3d.h" />
290291 <ClInclude Include="include\d3dcaps.h" />
291292 <ClInclude Include="include\d3dtypes.h" />
@@ -366,6 +367,14 @@
367368 <ClCompile Include="glRenderer.cpp" />
368369 <ClCompile Include="glRenderWindow.cpp" />
369370 <ClCompile Include="glUtil.cpp" />
 371+ <ClCompile Include="hooks.c">
 372+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
 373+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
 374+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
 375+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
 376+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
 377+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
 378+ </ClCompile>
370379 <ClCompile Include="matrix.c">
371380 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
372381 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
Index: ddraw/ddraw.vcxproj.filters
@@ -143,6 +143,9 @@
144144 <ClInclude Include="glDirectDrawGammaControl.h">
145145 <Filter>Header Files</Filter>
146146 </ClInclude>
 147+ <ClInclude Include="hooks.h">
 148+ <Filter>Header Files</Filter>
 149+ </ClInclude>
147150 </ItemGroup>
148151 <ItemGroup>
149152 <ClCompile Include="ddraw.cpp">
@@ -241,6 +244,9 @@
242245 <ClCompile Include="glDirectDrawGammaControl.cpp">
243246 <Filter>Source Files</Filter>
244247 </ClCompile>
 248+ <ClCompile Include="hooks.c">
 249+ <Filter>Source Files</Filter>
 250+ </ClCompile>
245251 </ItemGroup>
246252 <ItemGroup>
247253 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirectDraw.cpp
@@ -31,6 +31,7 @@
3232 #include "glDirectDrawPalette.h"
3333 #include "glRenderer.h"
3434 #include "../common/version.h"
 35+#include "hooks.h"
3536
3637 const DDDEVICEIDENTIFIER2 devid_default = {
3738 "ddraw.dll",
@@ -1436,6 +1437,7 @@
14371438 SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
14381439 }
14391440 }*/ // Currently breaks The Settlers IV
 1441+ if (this->hWnd && fullscreen) UninstallDXGLFullscreenHook(this->hWnd);
14401442 this->hWnd = hWnd;
14411443 if (!winstyle && !winstyleex)
14421444 {
@@ -1511,6 +1513,7 @@
15121514 internalrefresh = primaryrefresh = screenrefresh = devmode.dmDisplayFrequency;
15131515 primarybpp = bpp;
15141516 InitGL(x,y,bpp,fullscreen,internalrefresh,hWnd,this,devwnd);
 1517+ if (fullscreen) InstallDXGLFullscreenHook(hWnd);
15151518 cooplevel = dwFlags;
15161519 TRACE_EXIT(23,DD_OK);
15171520 return DD_OK;
Index: ddraw/glRenderWindow.cpp
@@ -27,36 +27,6 @@
2828 bool hotkeyregistered = false;
2929 #endif
3030
31 -const TCHAR *wndprop = _T("DXGLWndProc");
32 -
33 -LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
34 -void InstallDXGLHook(HWND hWnd)
35 -{
36 - if (GetProp(hWnd, wndprop)) return;
37 - SetProp(hWnd, wndprop, (HANDLE)GetWindowLongPtr(hWnd, GWLP_WNDPROC));
38 - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)DXGLWndHookProc);
39 -}
40 -void UninstallDXGLHook(HWND hWnd)
41 -{
42 - if (!GetProp(hWnd, wndprop)) return;
43 - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)GetProp(hWnd, wndprop));
44 - RemoveProp(hWnd, wndprop);
45 -}
46 -LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
47 -{
48 - WNDPROC parentproc = (WNDPROC)GetProp(hWnd, wndprop);
49 - switch (uMsg)
50 - {
51 - case WM_DESTROY:
52 - UninstallDXGLHook(hWnd);
53 - break;
54 - case WM_ACTIVATEAPP:
55 - if (!wParam) ShowWindow(hWnd, SW_MINIMIZE);
56 - break;
57 - }
58 - return parentproc(hWnd,uMsg,wParam,lParam);
59 -}
60 -
6131 void WaitForObjectAndMessages(HANDLE object)
6232 {
6333 MSG Msg;
@@ -128,7 +98,6 @@
12999 hWnd = CreateWindowA("DirectDrawDeviceWnd",windowname,WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
130100 rectRender.bottom - rectRender.top,hParentWnd,NULL,wndclass.hInstance,this);
131101 SetWindowPos(hWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
132 - if (fullscreen) InstallDXGLHook(hParentWnd);
133102 }
134103 else
135104 {
@@ -230,7 +199,6 @@
231200 }
232201 else return SendMessage(hParent,msg,wParam,lParam);
233202 case WM_CLOSE:
234 - if (fullscreen) UninstallDXGLHook(hParentWnd);
235203 DestroyWindow(hWnd);
236204 return 0;
237205 case WM_DESTROY:
Index: ddraw/hooks.c
@@ -0,0 +1,49 @@
 2+// DXGL
 3+// Copyright (C) 2014 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include "hooks.h"
 21+
 22+const TCHAR *wndprop = _T("DXGLWndProc");
 23+
 24+void InstallDXGLFullscreenHook(HWND hWnd)
 25+{
 26+ HANDLE wndproc = GetWindowLongPtr(hWnd, GWLP_WNDPROC);
 27+ if (GetProp(hWnd, wndprop)) return;
 28+ SetProp(hWnd, wndprop, wndproc);
 29+ SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)DXGLWndHookProc);
 30+}
 31+void UninstallDXGLFullscreenHook(HWND hWnd)
 32+{
 33+ if (!GetProp(hWnd, wndprop)) return;
 34+ SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)GetProp(hWnd, wndprop));
 35+ RemoveProp(hWnd, wndprop);
 36+}
 37+LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 38+{
 39+ WNDPROC parentproc = (WNDPROC)GetProp(hWnd, wndprop);
 40+ switch (uMsg)
 41+ {
 42+ case WM_DESTROY:
 43+ UninstallDXGLFullscreenHook(hWnd);
 44+ break;
 45+ case WM_ACTIVATEAPP:
 46+ if (!wParam) ShowWindow(hWnd, SW_MINIMIZE);
 47+ break;
 48+ }
 49+ return CallWindowProc(parentproc, hWnd, uMsg, wParam, lParam);
 50+}
Index: ddraw/hooks.h
@@ -0,0 +1,32 @@
 2+// DXGL
 3+// Copyright (C) 2014 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+#pragma once
 19+#ifndef __HOOKS_H
 20+#define __HOOKS_H
 21+#ifdef __cplusplus
 22+extern "C" {
 23+#endif
 24+
 25+LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 26+void InstallDXGLFullscreenHook(HWND hWnd);
 27+void UninstallDXGLFullscreenHook(HWND hWnd);
 28+
 29+#ifdef __cplusplus
 30+}
 31+#endif
 32+
 33+#endif //__HOOKS_H
\ No newline at end of file