feat(Windows64): safely exit game & get monitors size that has the game window instead of primary

This commit is contained in:
2026-08-12 18:18:41 -04:00
parent bd0cc59a54
commit 82783c0812
5 changed files with 75 additions and 91 deletions
@@ -76,7 +76,6 @@ DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]=
//-------------------------------------------------------------------------------------
BOOL g_bWidescreen = TRUE;
int g_iScreenWidth = 1920;
int g_iScreenHeight = 1080;
@@ -313,8 +312,6 @@ ID3D11Texture2D* g_pDepthStencilBuffer = NULL;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
@@ -332,11 +329,35 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_ENTERSIZEMOVE:
SetTimer(hWnd, 1, USER_TIMER_MINIMUM, NULL);
break;
case WM_EXITSIZEMOVE:
KillTimer(hWnd, 1);
break;
case WM_ERASEBKGND:
return 1;
case WM_TIMER:
if (wParam == 1)
{
// Tick UI
ui.tick();
ui.render();
RenderManager.Present();
ui.CheckMenuDisplayed();
// Tick Managers
app.UpdateTime();
InputManager.Tick();
StorageManager.Tick();
RenderManager.Tick();
// Tick Music
Minecraft *pMinecraft=Minecraft::GetInstance();
pMinecraft->soundEngine->tick(NULL, 0.0f);
pMinecraft->soundEngine->playMusicTick();
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
@@ -467,17 +488,31 @@ HRESULT InitDevice()
{
HRESULT hr = S_OK;
//str1k3r - use screen size instead of window size
g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
//str1k3r - stop hardcoding size and just use the screens actual size
UINT width = g_iScreenWidth;
//str1k3r - use screen size instead of window size & detect if its widescreen or not
#ifndef _DEBUG
HMONITOR hMonitor = MonitorFromWindow(g_hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo = { sizeof(MONITORINFO) };
if (GetMonitorInfo(hMonitor, &monitorInfo))
{
g_iScreenWidth = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left;
g_iScreenHeight = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top;
}
else
{
g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
}
g_bWidescreen = (g_iScreenHeight > 0 && ((double)g_iScreenWidth / g_iScreenHeight) >= 1.59) ? TRUE : FALSE;
#endif
//str1k3r - stop hardcoding size and just use the screens actual size
UINT width = g_iScreenWidth;
UINT height = g_iScreenHeight;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
app.DebugPrintf("Screen Width: %d, Screen Height: %d\n", width, height);
app.DebugPrintf("Screen Width: %d, Screen Height: %d, Widescreen: %s\n", width, height, g_bWidescreen ? "TRUE" : "FALSE");
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
@@ -1177,10 +1212,11 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
// A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset
Vec3::resetPool();
}
//str1k3r - Safely exit the game
app.ExitGame();
// Free resources, unregister custom classes, and exit.
// app.Uninit();
g_pd3dDevice->Release();
return (int)msg.wParam;
}
#ifdef MEMORY_TRACKING