DXGL r708 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r707‎ | r708 | r709 >
Date:05:45, 30 May 2017
Author:admin
Status:new
Tags:
Comment:
Allow only one instance of the DXGL Config dialog.
Modified paths:
  • /dxglcfg/dxglcfg.c (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: dxglcfg/dxglcfg.c
@@ -1688,6 +1688,8 @@
16891689 INITCOMMONCONTROLSEX icc;
16901690 HMODULE comctl32;
16911691 BOOL(WINAPI *iccex)(LPINITCOMMONCONTROLSEX lpInitCtrls);
 1692+ HANDLE hMutex;
 1693+ HWND hWnd;
16921694 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
16931695 GetVersionEx(&osver);
16941696 CoInitialize(NULL);
@@ -1722,7 +1724,18 @@
17231725 // Message for when transitioning to the new config UI
17241726 /*MessageBox(NULL, _T("This version of DXGL Config is deprecated and no longer supported. Some options may no longer work correctly."),
17251727 _T("Notice"), MB_OK | MB_ICONWARNING);*/
 1728+ hMutex = CreateMutex(NULL, TRUE, _T("DXGLConfigMutex"));
 1729+ if (GetLastError() == ERROR_ALREADY_EXISTS)
 1730+ {
 1731+ // Find DXGL Config window
 1732+ hWnd = FindWindow(NULL, _T("DXGL Config"));
 1733+ // Focus DXGL Config window
 1734+ if (hWnd) SetForegroundWindow(hWnd);
 1735+ return 0;
 1736+ }
17261737 DialogBox(hInstance,MAKEINTRESOURCE(IDD_DXGLCFG),0,(DLGPROC)DXGLCfgCallback);
 1738+ ReleaseMutex(hMutex);
 1739+ CloseHandle(hMutex);
17271740 #ifdef _DEBUG
17281741 _CrtDumpMemoryLeaks();
17291742 #endif
Index: dxglcfg2/dxglcfg2.c
@@ -1968,6 +1968,8 @@
19691969 INITCOMMONCONTROLSEX icc;
19701970 HMODULE comctl32;
19711971 BOOL(WINAPI *iccex)(LPINITCOMMONCONTROLSEX lpInitCtrls);
 1972+ HANDLE hMutex;
 1973+ HWND hWnd;
19721974 osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
19731975 GetVersionEx(&osver);
19741976 CoInitialize(NULL);
@@ -1999,7 +2001,18 @@
20002002 GetModuleFileName(NULL,hlppath,MAX_PATH);
20012003 GetDirFromPath(hlppath);
20022004 _tcscat(hlppath,_T("\\dxgl.chm"));
 2005+ hMutex = CreateMutex(NULL, TRUE, _T("DXGLConfigMutex"));
 2006+ if (GetLastError() == ERROR_ALREADY_EXISTS)
 2007+ {
 2008+ // Find DXGL Config window
 2009+ hWnd = FindWindow(NULL, _T("DXGL Config (Experimental)"));
 2010+ // Focus DXGL Config window
 2011+ if (hWnd) SetForegroundWindow(hWnd);
 2012+ return 0;
 2013+ }
20032014 DialogBox(hInstance,MAKEINTRESOURCE(IDD_DXGLCFG),0,(DLGPROC)DXGLCfgCallback);
 2015+ ReleaseMutex(hMutex);
 2016+ CloseHandle(hMutex);
20042017 #ifdef _DEBUG
20052018 _CrtDumpMemoryLeaks();
20062019 #endif