Skip to content

Commit

Permalink
Fixed crash on minimize.
Browse files Browse the repository at this point in the history
Reassert confined mouse cursor on full-screen window activation.
Maximize button enables full-screen mode.

git-svn-id: http://zigserv/svn/Projects/trunk/wcdx@436 41632dc1-7a16-0410-8441-a1f66f767317
  • Loading branch information
Bekenn committed Apr 11, 2018
1 parent 44b45ac commit e398925
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/wcdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,12 @@ LRESULT CALLBACK Wcdx::FrameWindowProc(HWND hwnd, UINT message, WPARAM wParam, L
return 0;
break;

case WM_SIZING:
case WM_SYSCOMMAND:
if (wcdx->OnSysCommand(wParam, LOWORD(lParam), HIWORD(lParam)))
return 0;
break;

case WM_SIZING:
wcdx->OnSizing(wParam, reinterpret_cast<RECT*>(lParam));
return TRUE;

Expand Down Expand Up @@ -565,7 +570,7 @@ LRESULT CALLBACK Wcdx::ContentWindowProc(HWND hwnd, UINT message, WPARAM wParam,

void Wcdx::OnSize(DWORD resizeType, WORD clientWidth, WORD clientHeight)
{
RECT contentRect;
RECT contentRect;
GetContentRect(contentRect);
::MoveWindow(contentWindow, contentRect.left, contentRect.top, contentRect.right - contentRect.left, contentRect.bottom - contentRect.top, FALSE);
::PostMessage(frameWindow, WM_APP_RENDER, 0, 0);
Expand All @@ -574,7 +579,10 @@ void Wcdx::OnSize(DWORD resizeType, WORD clientWidth, WORD clientHeight)
void Wcdx::OnActivate(WORD state, BOOL minimized, HWND other)
{
if (state != WA_INACTIVE)
{
::SetFocus(contentWindow);
ConfineCursor();
}
}

void Wcdx::OnNCDestroy()
Expand All @@ -594,6 +602,17 @@ bool Wcdx::OnSysKeyDown(DWORD vkey, WORD repeatCount, BYTE scode, BYTE flags)
return false;
}

bool Wcdx::OnSysCommand(WORD type, SHORT x, SHORT y)
{
if (type == SC_MAXIMIZE)
{
SetFullScreen(true);
return true;
}

return false;
}

void Wcdx::OnSizing(DWORD windowEdge, RECT* dragRect)
{
RECT client = { 0, 0, 0, 0 };
Expand Down Expand Up @@ -741,10 +760,6 @@ void Wcdx::SetFullScreen(bool enabled)
monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top,
SWP_FRAMECHANGED | SWP_NOCOPYBITS | SWP_SHOWWINDOW);

RECT contentRect;
::GetWindowRect(contentWindow, &contentRect);
::ClipCursor(&contentRect);

fullScreen = true;
}
else
Expand All @@ -758,11 +773,10 @@ void Wcdx::SetFullScreen(bool enabled)
frameRect.bottom - frameRect.top,
SWP_FRAMECHANGED | SWP_NOCOPYBITS | SWP_SHOWWINDOW);

::ClipCursor(nullptr);

fullScreen = false;
}

ConfineCursor();
::PostMessage(frameWindow, WM_APP_RENDER, 0, 0);
}

Expand All @@ -786,6 +800,18 @@ void Wcdx::GetContentRect(RECT& contentRect)
}
}

void Wcdx::ConfineCursor()
{
if (fullScreen)
{
RECT contentRect;
::GetWindowRect(contentWindow, &contentRect);
::ClipCursor(&contentRect);
}
else
::ClipCursor(nullptr);
}

void ConvertTo(LONG& x, LONG& y, const SIZE& size)
{
x = ((x * size.cx) / Wcdx::ContentWidth);
Expand All @@ -794,8 +820,8 @@ void ConvertTo(LONG& x, LONG& y, const SIZE& size)

void ConvertFrom(LONG& x, LONG& y, const SIZE& size)
{
x = (x * Wcdx::ContentWidth) / size.cx;
y = (y * Wcdx::ContentHeight) / size.cy;
x = size.cx == 0 ? 0 : (x * Wcdx::ContentWidth) / size.cx;
y = size.cy == 0 ? 0 : (y * Wcdx::ContentHeight) / size.cy;
}

HRESULT GetSavedGamePath(LPCWSTR subdir, LPWSTR path)
Expand Down
2 changes: 2 additions & 0 deletions src/wcdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Wcdx : public IWcdx
void OnActivate(WORD state, BOOL minimized, HWND other);
void OnNCDestroy();
bool OnSysKeyDown(DWORD vkey, WORD repeatCount, BYTE scode, BYTE flags);
bool OnSysCommand(WORD type, SHORT x, SHORT y);
void OnSizing(DWORD windowEdge, RECT* dragRect);
void OnRender();

Expand All @@ -66,6 +67,7 @@ class Wcdx : public IWcdx
HRESULT CreateIntermediateSurface();
void SetFullScreen(bool enabled);
void GetContentRect(RECT& contentRect);
void ConfineCursor();

private:
ULONG refCount;
Expand Down

0 comments on commit e398925

Please sign in to comment.