Skip to content

Commit

Permalink
Update how CreateWindow() handles popup window
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Apr 16, 2024
1 parent d1fbd84 commit 606800c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 6999
#define BUILD_NUMBER 7000
20 changes: 3 additions & 17 deletions GDI/User32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,10 @@ HWND WINAPI user_CreateWindowExT(D CreateWindowExT, DWORD dwExStyle, T lpClassNa
return nullptr;
}

// Handle popup window type
if ((dwStyle & WS_POPUP) && (dwStyle & WS_VISIBLE) && !(dwStyle & WS_CLIPSIBLINGS) && !hWndParent)
// Handle popup window type (some games forget to initialize the nWidth and nHeight values)
if ((dwStyle & WS_POPUP) && !(nWidth & CW_USEDEFAULT) && (nWidth > 20000 || nHeight > 20000))
{
DWORD dwNewStyle = dwStyle;

// Remove popup style
dwNewStyle = dwStyle & ~WS_POPUP;

HWND hwnd = CreateWindowExT(dwExStyle, lpClassName, lpWindowName, dwNewStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);

if (hwnd)
{
LOG_LIMIT(100, __FUNCTION__ << " Removed WS_POPUP window style! " << hwnd);

SetWindowLong(hwnd, GWL_STYLE, dwNewStyle);

return hwnd;
}
Utils::GetScreenSize(hWndParent, nWidth, nHeight);
}

return CreateWindowExT(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
Expand Down
2 changes: 1 addition & 1 deletion Utils/Fullscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void Utils::GetScreenSize(HWND hwnd, LONG &screenWidth, LONG &screenHeight)
screenHeight = info.rcMonitor.bottom - info.rcMonitor.top;
}

void Utils::GetScreenSize(HWND hwnd, DWORD &screenWidth, DWORD &screenHeight)
void Utils::GetScreenSize(HWND hwnd, int &screenWidth, int &screenHeight)
{
LONG Width, Height;
GetScreenSize(hwnd, Width, Height);
Expand Down
2 changes: 1 addition & 1 deletion Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Utils
bool SetWndProcFilter(HWND hWnd);
bool RestoreWndProcFilter(HWND hWnd);
void GetScreenSize(HWND hwnd, LONG &screenWidth, LONG &screenHeight);
void GetScreenSize(HWND hwnd, DWORD &screenWidth, DWORD &screenHeight);
void GetScreenSize(HWND hwnd, int &screenWidth, int &screenHeight);
void GetDesktopRect(HWND hWnd, RECT& screenRect);
DWORD GetVideoRam(UINT AdapterNo); // Adapters start numbering from '1', based on "Win32_VideoController" WMI class and "DeviceID" property.
}
Expand Down
12 changes: 6 additions & 6 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ HRESULT m_IDirectDrawX::GetDisplayMode2(LPDDSURFACEDESC2 lpDDSurfaceDesc2)
else
{
HWND hWnd = GetHwnd();
Utils::GetScreenSize(hWnd, lpDDSurfaceDesc2->dwWidth, lpDDSurfaceDesc2->dwHeight);
Utils::GetScreenSize(hWnd, (LONG&)lpDDSurfaceDesc2->dwWidth, (LONG&)lpDDSurfaceDesc2->dwHeight);
lpDDSurfaceDesc2->dwRefreshRate = Utils::GetRefreshRate(hWnd);
displayModeBits = GetDisplayBPP(hWnd);
}
Expand Down Expand Up @@ -1901,7 +1901,7 @@ HRESULT m_IDirectDrawX::SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBP
{
ScaleDDLastWidth = dwWidth;
ScaleDDLastHeight = dwHeight;
Utils::GetScreenSize(nullptr, ScaleDDCurrentWidth, ScaleDDCurrentHeight);
Utils::GetScreenSize(nullptr, (LONG&)ScaleDDCurrentWidth, (LONG&)ScaleDDCurrentHeight);
dwWidth = ScaleDDCurrentWidth;
dwHeight = ScaleDDCurrentHeight;
ScaleDDWidthRatio = (float)ScaleDDCurrentWidth / (float)ScaleDDLastWidth;
Expand Down Expand Up @@ -2366,7 +2366,7 @@ void m_IDirectDrawX::InitDdraw(DWORD DirectXVersion)
hFocusWindow = nullptr;

// Display resolution
Utils::GetScreenSize(GetHwnd(), InitWidth, InitHeight);
Utils::GetScreenSize(GetHwnd(), (LONG&)InitWidth, (LONG&)InitHeight);
if (Config.DdrawUseNativeResolution)
{
Device.Width = InitWidth;
Expand Down Expand Up @@ -2866,7 +2866,7 @@ HRESULT m_IDirectDrawX::CreateD3D9Device()

// Get current resolution and rect
DWORD CurrentWidth, CurrentHeight;
Utils::GetScreenSize(hWnd, CurrentWidth, CurrentHeight);
Utils::GetScreenSize(hWnd, (LONG&)CurrentWidth, (LONG&)CurrentHeight);

// Get width and height
DWORD BackBufferWidth = 0;
Expand Down Expand Up @@ -3046,7 +3046,7 @@ HRESULT m_IDirectDrawX::CreateD3D9Device()
{
// Get new resolution
DWORD NewWidth = presParams.BackBufferWidth, NewHeight = presParams.BackBufferHeight;
Utils::GetScreenSize(hWnd, NewWidth, NewHeight);
Utils::GetScreenSize(hWnd, (LONG&)NewWidth, (LONG&)NewHeight);

// Send display change message
if ((SetResolution || NewWidth != CurrentWidth || NewHeight != CurrentHeight) && NewWidth && NewHeight)
Expand Down Expand Up @@ -3122,7 +3122,7 @@ HRESULT m_IDirectDrawX::CreateVertexBuffer(DWORD Width, DWORD Height)
DWORD BackBufferHeight = (displayflag) ? displayHeight : Height;
if (!BackBufferWidth || !BackBufferHeight)
{
Utils::GetScreenSize(GetHwnd(), BackBufferWidth, BackBufferHeight);
Utils::GetScreenSize(GetHwnd(), (LONG&)BackBufferWidth, (LONG&)BackBufferHeight);
}

// Calculate width and height with original aspect ratio
Expand Down

0 comments on commit 606800c

Please sign in to comment.