DXGL r821 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r820‎ | r821 | r822 >
Date:16:23, 23 June 2018
Author:admin
Status:new
Tags:
Comment:
Add Windows default window position. Update help file.
Modified paths:
  • /Help/html/config/advanced/defaultwindowposition.htmlbody (modified) (history)
  • /ddraw/dllmain.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/util.c (modified) (history)
  • /ddraw/util.h (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: Help/html/config/advanced/defaultwindowposition.htmlbody
@@ -5,4 +5,13 @@
66 <h3>Centered</h3>
77 <p>Locates the window in the center of the display.</p>
88 <h3>Saved position</h3>
9 -<p>Uses the position stored in &#8220;Remembered window position&#8221; to position the window, using logical window coordinates.</p>
\ No newline at end of file
 9+<p>Uses the position stored in &#8220;Remembered window position&#8221; to position the window, using logical window coordinates.</p>
 10+<h3>Top left</h3>
 11+<p>Locates the window at the top left of the display.</p>
 12+<h3>Windows default</h3>
 13+<p>
 14+ Allows Windows to select the position to place the window.<br />
 15+ <span style="font-size: 8pt;">
 16+ <em>Top left and Windows default options are available in DXGL 0.5.14 and later.</em>
 17+ </span>
 18+</p>
\ No newline at end of file
Index: ddraw/dllmain.cpp
@@ -18,6 +18,7 @@
1919 #include "common.h"
2020 #include "ddraw.h"
2121 #include "hooks.h"
 22+#include "util.h"
2223 ATOM WindowClass = NULL;
2324 CRITICAL_SECTION dll_cs = {NULL,0,0,NULL,NULL,0};
2425 BOOL APIENTRY DllMain( HMODULE hModule,
@@ -42,6 +43,7 @@
4344 ZeroMemory(&hook_cs, sizeof(CRITICAL_SECTION));
4445 DeleteCriticalSection(&dll_cs);
4546 ZeroMemory(&dll_cs, sizeof(CRITICAL_SECTION));
 47+ if (wndclassdxgltempatom) UnregisterDXGLTempWindowClass();
4648 break;
4749 }
4850 return TRUE;
Index: ddraw/glRenderer.cpp
@@ -1687,6 +1687,7 @@
16881688 InitializeCriticalSection(&This->cs);
16891689 This->busy = CreateEvent(NULL,FALSE,FALSE,NULL);
16901690 This->start = CreateEvent(NULL,FALSE,FALSE,NULL);
 1691+ HWND hTempWnd;
16911692 if(fullscreen)
16921693 {
16931694 switch (dxglcfg.fullmode)
@@ -1733,6 +1734,21 @@
17341735 wndrect.bottom -= wndrect.top;
17351736 wndrect.top = 0;
17361737 }
 1738+ else if (dxglcfg.WindowPosition == 3)
 1739+ {
 1740+ if (!wndclassdxgltempatom) RegisterDXGLTempWindowClass();
 1741+ wndrect.left = wndrect.top = 0;
 1742+ wndrect.right = dxglcfg.WindowWidth;
 1743+ wndrect.bottom = dxglcfg.WindowHeight;
 1744+ AdjustWindowRectEx(&wndrect, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX), FALSE,
 1745+ (winstyleex | WS_EX_APPWINDOW));
 1746+ hTempWnd = CreateWindow(wndclassdxgltemp.lpszClassName, _T("DXGL Sizing Window"),
 1747+ (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE),
 1748+ CW_USEDEFAULT, CW_USEDEFAULT, wndrect.right - wndrect.left, wndrect.bottom - wndrect.top, NULL, NULL,
 1749+ GetModuleHandle(NULL), NULL);
 1750+ GetWindowRect(hTempWnd, &wndrect);
 1751+ DestroyWindow(hTempWnd);
 1752+ }
17371753 else
17381754 {
17391755 screenx = GetSystemMetrics(SM_CXSCREEN);
@@ -1772,6 +1788,19 @@
17731789 wndrect.bottom -= wndrect.top;
17741790 wndrect.top = 0;
17751791 }
 1792+ else if (dxglcfg.WindowPosition == 3)
 1793+ {
 1794+ if (!wndclassdxgltempatom) RegisterDXGLTempWindowClass();
 1795+ wndrect.left = wndrect.top = 0;
 1796+ wndrect.right = dxglcfg.WindowWidth;
 1797+ wndrect.bottom = dxglcfg.WindowHeight;
 1798+ AdjustWindowRectEx(&wndrect, (winstyle | WS_OVERLAPPEDWINDOW), FALSE, (winstyleex | WS_EX_APPWINDOW));
 1799+ hTempWnd = CreateWindow(wndclassdxgltemp.lpszClassName, _T("DXGL Sizing Window"),
 1800+ ((winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_POPUP | WS_VISIBLE)), CW_USEDEFAULT, CW_USEDEFAULT,
 1801+ wndrect.right - wndrect.left, wndrect.bottom - wndrect.top, NULL, NULL, GetModuleHandle(NULL), NULL);
 1802+ GetWindowRect(hTempWnd, &wndrect);
 1803+ DestroyWindow(hTempWnd);
 1804+ }
17761805 else
17771806 {
17781807 screenx = GetSystemMetrics(SM_CXSCREEN);
@@ -1809,6 +1838,18 @@
18101839 wndrect.right = dxglcfg.WindowWidth;
18111840 wndrect.bottom = dxglcfg.WindowHeight;
18121841 }
 1842+ else if (dxglcfg.WindowPosition == 3)
 1843+ {
 1844+ if (!wndclassdxgltempatom) RegisterDXGLTempWindowClass();
 1845+ wndrect.left = wndrect.top = 0;
 1846+ wndrect.right = dxglcfg.WindowWidth;
 1847+ wndrect.bottom = dxglcfg.WindowHeight;
 1848+ hTempWnd = CreateWindow(wndclassdxgltemp.lpszClassName, _T("DXGL Sizing Window"),
 1849+ winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP | WS_VISIBLE), CW_USEDEFAULT, CW_USEDEFAULT,
 1850+ wndrect.right - wndrect.left, wndrect.bottom - wndrect.top, NULL, NULL, GetModuleHandle(NULL), NULL);
 1851+ GetWindowRect(hTempWnd, &wndrect);
 1852+ DestroyWindow(hTempWnd);
 1853+ }
18131854 else
18141855 {
18151856 screenx = GetSystemMetrics(SM_CXSCREEN);
@@ -2225,7 +2266,7 @@
22262267 SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
22272268 SetWindowLongPtrA(newwnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_POPUP));
22282269 ShowWindow(newwnd, SW_NORMAL);
2229 - if (dxglcfg.WindowPosition == 1)
 2270+ if ((dxglcfg.WindowPosition == 1) || (dxglcfg.WindowPosition == 3))
22302271 {
22312272 GetWindowRect(newwnd, &wndrect);
22322273 if (GetMenu(newwnd)) hasmenu = TRUE;
@@ -2278,7 +2319,7 @@
22792320 GetWindowPlacement(newwnd, &wndplace);
22802321 if(wndplace.showCmd == SW_SHOWMAXIMIZED) ShowWindow(newwnd, SW_SHOWMAXIMIZED);
22812322 else ShowWindow(newwnd, SW_NORMAL);
2282 - if (dxglcfg.WindowPosition == 1)
 2323+ if ((dxglcfg.WindowPosition == 1) || (dxglcfg.WindowPosition == 3))
22832324 {
22842325 wndrect = wndplace.rcNormalPosition;
22852326 GetWindowRect(newwnd, &wndrect2);
@@ -2362,7 +2403,8 @@
23632404 ShowWindow(newwnd, SW_NORMAL);
23642405 screenx = GetSystemMetrics(SM_CXSCREEN);
23652406 screeny = GetSystemMetrics(SM_CYSCREEN);
2366 - if (dxglcfg.WindowPosition == 1) GetWindowRect(newwnd, &wndrect);
 2407+ if ((dxglcfg.WindowPosition == 1) || (dxglcfg.WindowPosition == 3))
 2408+ GetWindowRect(newwnd, &wndrect);
23672409 else if (dxglcfg.WindowPosition == 2)
23682410 {
23692411 wndrect.left = 0;
Index: ddraw/util.c
@@ -164,4 +164,38 @@
165165 if ((dxglcfg.BltScale == 2) || (dxglcfg.BltScale == 3) || (dxglcfg.BltScale == 4))
166166 return TRUE;
167167 else return FALSE;
168 -}
\ No newline at end of file
 168+}
 169+
 170+WNDCLASSEX wndclassdxgltemp =
 171+{
 172+ sizeof(WNDCLASSEX),
 173+ 0,
 174+ DefWindowProc,
 175+ 0,0,
 176+ NULL,
 177+ NULL,NULL,
 178+ (HBRUSH)COLOR_WINDOW,
 179+ NULL,
 180+ _T("DXGLTempSizingWindowClass"),
 181+ NULL
 182+};
 183+ATOM wndclassdxgltempatom = NULL;
 184+
 185+void RegisterDXGLTempWindowClass()
 186+{
 187+ if (!wndclassdxgltempatom)
 188+ {
 189+ if (!wndclassdxgltemp.hInstance) wndclassdxgltemp.hInstance = GetModuleHandle(NULL);
 190+ if (!wndclassdxgltemp.hCursor) wndclassdxgltemp.hCursor = LoadCursor(NULL, IDC_ARROW);
 191+ wndclassdxgltempatom = RegisterClassEx(&wndclassdxgltemp);
 192+ }
 193+}
 194+
 195+void UnregisterDXGLTempWindowClass()
 196+{
 197+ if (wndclassdxgltempatom)
 198+ {
 199+ UnregisterClass(wndclassdxgltemp.lpszClassName, GetModuleHandle(NULL));
 200+ wndclassdxgltempatom = NULL;
 201+ }
 202+}
Index: ddraw/util.h
@@ -29,6 +29,12 @@
3030 BOOL comp_bltfx(DDBLTFX *a, DDBLTFX *b, DWORD flags);
3131 BOOL IsAlphaCKey();
3232
 33+extern WNDCLASSEX wndclassdxgltemp;
 34+extern ATOM wndclassdxgltempatom;
 35+
 36+void RegisterDXGLTempWindowClass();
 37+void UnregisterDXGLTempWindowClass();
 38+
3339 #ifdef __cplusplus
3440 }
3541 #endif
Index: dxglcfg/dxglcfg.cpp
@@ -2667,7 +2667,6 @@
26682668 DS_3DLOOK | DS_CONTEXTHELP | DS_SHELLFONT | WS_CAPTION | WS_SYSMENU,
26692669 CW_USEDEFAULT, CW_USEDEFAULT, r.right-r.left,r.bottom-r.top,NULL,NULL,
26702670 GetModuleHandle(NULL), NULL);
2671 - error = GetLastError();
26722671 GetWindowRect(hTempWnd, &r);
26732672 SetWindowPos(hWnd, HWND_TOP,r.left,r.top,0,0, SWP_NOSIZE);
26742673 DestroyWindow(hTempWnd);
@@ -3154,6 +3153,8 @@
31553154 SendDlgItemMessage(hTabs[3], IDC_WINDOWPOS, CB_ADDSTRING, 0, (LPARAM)buffer);
31563155 _tcscpy(buffer, _T("Top left"));
31573156 SendDlgItemMessage(hTabs[3], IDC_WINDOWPOS, CB_ADDSTRING, 0, (LPARAM)buffer);
 3157+ _tcscpy(buffer, _T("Windows default"));
 3158+ SendDlgItemMessage(hTabs[3], IDC_WINDOWPOS, CB_ADDSTRING, 0, (LPARAM)buffer);
31583159 SendDlgItemMessage(hTabs[3], IDC_WINDOWPOS, CB_SETCURSEL, cfg->WindowPosition, 0);
31593160 // Remember window position
31603161 if (cfg->RememberWindowPosition) SendDlgItemMessage(hTabs[3], IDC_REMEMBERWINDOWPOS, BM_SETCHECK, BST_CHECKED, 0);