Skip to content

Commit

Permalink
Improved window handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ata4 committed Nov 17, 2015
1 parent 8ab432e commit 92aebb9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
4 changes: 1 addition & 3 deletions ddraw/DirectDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ HRESULT WINAPI DirectDraw::RestoreDisplayMode() {
HRESULT WINAPI DirectDraw::SetCooperativeLevel(HWND hWnd, DWORD dwFlags) {
TRACE("DirectDraw::SetCooperativeLevel");

if (dwFlags & DDSCL_FULLSCREEN) {
m_context.setFullscreen(true);
}
m_context.setFullscreen(dwFlags & DDSCL_FULLSCREEN);

return DD_OK;
}
Expand Down
70 changes: 56 additions & 14 deletions glrage/ContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,42 @@ void ContextImpl::detach() {
}

LRESULT ContextImpl::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
// Printscreen on Windows with OpenGL doesn't work in fullscreen, so hook the
// key and implement screenshot saving to files.
// For some reason, VK_SNAPSHOT doesn't generate WM_KEYDOWN events but only
// WM_KEYUP. Works just as well, though.
if (msg == WM_KEYUP && wParam == VK_SNAPSHOT) {
m_screenshot.schedule();
return TRUE;
}

// toggle fullscreen if alt + return is pressed
if (msg == WM_SYSKEYDOWN && wParam == VK_RETURN && lParam & 1 << 29 && !(lParam & 1 << 30)) {
toggleFullscreen();
return TRUE;
switch (msg) {
// Printscreen on Windows with OpenGL doesn't work in fullscreen, so hook the
// key and implement screenshot saving to files.
// For some reason, VK_SNAPSHOT doesn't generate WM_KEYDOWN events but only
// WM_KEYUP. Works just as well, though.
case WM_KEYUP:
if (wParam == VK_SNAPSHOT) {
m_screenshot.schedule();
return TRUE;
}
break;

// toggle fullscreen if alt + return is pressed
case WM_SYSKEYDOWN:
if (wParam == VK_RETURN && lParam & 1 << 29 && !(lParam & 1 << 30)) {
toggleFullscreen();
return TRUE;
}
break;

// force default handling for some window messages when in windowed mode,
// especially important for Tomb Raider
case WM_MOVE:
case WM_MOVING:
case WM_SIZE:
case WM_NCPAINT:
case WM_SETCURSOR:
case WM_GETMINMAXINFO:
case WM_ERASEBKGND:
if (!m_fullscreen) {
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
}
break;
}

return m_windowProc(hwnd, msg, wParam, lParam);
return CallWindowProc(m_windowProc, hwnd, msg, wParam, lParam);
}

BOOL ContextImpl::enumWindowsProc(HWND hwnd) {
Expand All @@ -198,12 +218,32 @@ bool ContextImpl::isFullscreen() {
}

void ContextImpl::setFullscreen(bool fullscreen) {
if (m_fullscreen == fullscreen) {
return;
}

m_fullscreen = fullscreen;

if (!m_hwnd) {
return;
}

// change window style
LONG style = GetWindowLong(m_hwnd, GWL_STYLE);
LONG styleEx = GetWindowLong(m_hwnd, GWL_EXSTYLE);

if (m_fullscreen) {
style &= ~STYLE_WINDOW;
styleEx &= ~STYLE_WINDOW_EX;
} else {
style |= STYLE_WINDOW;
styleEx |= STYLE_WINDOW_EX;
}

SetWindowLong(m_hwnd, GWL_STYLE, style);
SetWindowLong(m_hwnd, GWL_EXSTYLE, styleEx);

// change window size
int32_t width;
int32_t height;

Expand All @@ -215,6 +255,8 @@ void ContextImpl::setFullscreen(bool fullscreen) {
height = m_height;
}

ShowCursor(!m_fullscreen);

setWindowSize(width, height);
}

Expand Down
9 changes: 6 additions & 3 deletions glrage/ContextImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class ContextImpl : public Context {
HWND getHWnd();

private:
// private methods
void fixWindowRatio(WPARAM edge, LPRECT prect);
void error(const std::string& message);
// constants
static const LONG STYLE_WINDOW = WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPED | WS_SYSMENU;
static const LONG STYLE_WINDOW_EX = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE;

// config object
Config m_config;
Expand Down Expand Up @@ -74,6 +74,9 @@ class ContextImpl : public Context {
// DirectDraw display mode dimension
uint32_t m_width;
uint32_t m_height;

// private methods
void error(const std::string& message);
};

}

0 comments on commit 92aebb9

Please sign in to comment.