Skip to content

Commit

Permalink
Change order of windows messages
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 6, 2024
1 parent ba71776 commit 95eb9e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 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 7361
#define BUILD_NUMBER 7362
56 changes: 19 additions & 37 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace {
// Default resolution
DWORD DefaultWidth;
DWORD DefaultHeight;
RECT LastWindowLocation;
RECT LastWindowRect;

// Exclusive mode settings
bool ExclusiveMode;
Expand Down Expand Up @@ -2376,7 +2376,7 @@ void m_IDirectDrawX::InitInterface(DWORD DirectXVersion)
DefaultWidth = 0;
DefaultHeight = 0;
Utils::GetScreenSize(nullptr, (LONG&)DefaultWidth, (LONG&)DefaultHeight);
LastWindowLocation = {};
LastWindowRect = {};

// Release DC
if (DisplayMode.hWnd && DisplayMode.DC)
Expand Down Expand Up @@ -3141,7 +3141,7 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
RECT LastClientRect = {};
if (hWnd)
{
GetWindowRect(hWnd, &LastWindowLocation);
GetWindowRect(hWnd, &LastWindowRect);
GetClientRect(hWnd, &LastClientRect);
}

Expand Down Expand Up @@ -3337,13 +3337,13 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)

// Check for window position change
bool bWindowMove =
LastWindowLocation.left != NewWindowRect.left ||
LastWindowLocation.top != NewWindowRect.top;
LastWindowRect.left != NewWindowRect.left ||
LastWindowRect.top != NewWindowRect.top;
bool bWindowSize =
(LONG)presParams.BackBufferWidth != NewClientRect.right ||
(LONG)presParams.BackBufferHeight != NewClientRect.bottom ||
NewClientRect.right != LastClientRect.right ||
NewClientRect.bottom != LastClientRect.bottom;
LastClientRect.right != NewClientRect.right ||
LastClientRect.bottom != NewClientRect.bottom;

// Post window messages
if (bWindowMove || bWindowSize)
Expand All @@ -3353,28 +3353,22 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
static WINDOWPOS winpos;
winpos = { hWnd, WindowInsert, NewWindowRect.left, NewWindowRect.top, NewWindowRect.right - NewWindowRect.left, NewWindowRect.bottom - NewWindowRect.top, WM_NULL };
static NCCALCSIZE_PARAMS NCCalc;
NCCalc = { { NewWindowRect, LastWindowLocation, LastWindowLocation }, &winpos };
NCCalc = { { NewWindowRect, LastWindowRect, LastWindowRect }, &winpos };

// Window placement
WINDOWPLACEMENT wp = {};
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp);
UINT SizeFlag = wp.showCmd == SW_SHOWMAXIMIZED ? SIZE_MAXIMIZED : wp.showCmd == SW_SHOWMINIMIZED ? SIZE_MINIMIZED : SIZE_RESTORED;

// Pre-populate MINMAXINFO
static MINMAXINFO minmaxInfo;
minmaxInfo = {};
minmaxInfo.ptMinTrackSize.x = 200; // Minimum width
minmaxInfo.ptMinTrackSize.y = 320; // Minimum height
minmaxInfo.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK); // Maximum width
minmaxInfo.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK); // Maximum height

// Send window position-related messages
PostMessage(hWnd, WM_ENTERSIZEMOVE, 0, 0);
PostMessage(hWnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmaxInfo);
// Notify window position
PostMessage(hWnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)&winpos);
PostMessage(hWnd, WM_NCCALCSIZE, TRUE, (LPARAM)&NCCalc);
PostMessage(hWnd, WM_NCPAINT, TRUE, NULL);
PostMessage(hWnd, WM_ERASEBKGND, TRUE, NULL);
PostMessage(hWnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos);

// Check and notify position change
// Notify window move
if (bWindowMove)
{
POINT ClientPoint = { NewClientRect.left, NewClientRect.top };
Expand All @@ -3387,26 +3381,14 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
{
PostMessage(hWnd, WM_SIZE, SizeFlag, MAKELPARAM(NewClientRect.right, NewClientRect.bottom));
}

// Adjust client area and finalize position change
PostMessage(hWnd, WM_NCCALCSIZE, TRUE, (LPARAM)&NCCalc);
PostMessage(hWnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos);

// Repaint non-client and client areas
PostMessage(hWnd, WM_NCPAINT, TRUE, NULL);
PostMessage(hWnd, WM_ERASEBKGND, TRUE, NULL);
PostMessage(hWnd, WM_PAINT, 0, 0);

// End move/size operation
PostMessage(hWnd, WM_EXITSIZEMOVE, 0, 0);
}

// Window focus and activate app
if (LastHWnd != hFocusWindow)
{
PostMessage(hWnd, WM_IME_SETCONTEXT, TRUE, ISC_SHOWUIALL);
PostMessage(hWnd, WM_SETFOCUS, NULL, NULL);
PostMessage(hWnd, WM_SYNCPAINT, NULL, NULL);
PostMessage(hWnd, WM_SYNCPAINT, (WPARAM)32, NULL);
}
}

Expand Down Expand Up @@ -4904,15 +4886,15 @@ HRESULT m_IDirectDrawX::Present(RECT* pSourceRect, RECT* pDestRect)
// Redraw window if it has moved from its last location
HWND hWnd = GetHwnd();
RECT ClientRect = {};
if (presParams.Windowed && !ExclusiveMode && !IsIconic(hWnd) && GetWindowRect(hWnd, &ClientRect) && LastWindowLocation.right > 0 && LastWindowLocation.bottom > 0)
if (presParams.Windowed && !ExclusiveMode && !IsIconic(hWnd) && GetWindowRect(hWnd, &ClientRect) && LastWindowRect.right > 0 && LastWindowRect.bottom > 0)
{
if (ClientRect.left != LastWindowLocation.left || ClientRect.top != LastWindowLocation.top ||
ClientRect.right != LastWindowLocation.right || ClientRect.bottom != LastWindowLocation.bottom)
if (ClientRect.left != LastWindowRect.left || ClientRect.top != LastWindowRect.top ||
ClientRect.right != LastWindowRect.right || ClientRect.bottom != LastWindowRect.bottom)
{
RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
}
LastWindowLocation = ClientRect;
LastWindowRect = ClientRect;

// Store new click time after frame draw is complete
QueryPerformanceCounter(&Counter.LastPresentTime);
Expand Down

0 comments on commit 95eb9e7

Please sign in to comment.