2013-01-04 11:41:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2012 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-04 15:41:37 +00:00
|
|
|
#include "stdafx.h"
|
2013-01-04 11:41:51 +00:00
|
|
|
#include "GSWndDX.h"
|
|
|
|
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2013-01-04 11:41:51 +00:00
|
|
|
GSWndDX::GSWndDX()
|
|
|
|
: m_hWnd(NULL)
|
|
|
|
, m_frame(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSWndDX::~GSWndDX()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK GSWndDX::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2013-01-04 15:41:37 +00:00
|
|
|
GSWndDX* wnd = NULL;
|
2013-01-04 11:41:51 +00:00
|
|
|
|
|
|
|
if(message == WM_NCCREATE)
|
|
|
|
{
|
2013-01-04 15:41:37 +00:00
|
|
|
wnd = (GSWndDX*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
2013-01-04 11:41:51 +00:00
|
|
|
|
|
|
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)wnd);
|
|
|
|
|
|
|
|
wnd->m_hWnd = hWnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-04 15:41:37 +00:00
|
|
|
wnd = (GSWndDX*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
2013-01-04 11:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(wnd == NULL)
|
|
|
|
{
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return wnd->OnMessage(message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT GSWndDX::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_CLOSE:
|
|
|
|
Hide();
|
|
|
|
// DestroyWindow(m_hWnd);
|
|
|
|
return 0;
|
|
|
|
case WM_DESTROY:
|
|
|
|
// This kills the emulator when GS is closed, which *really* isn't desired behavior,
|
|
|
|
// especially in STGS mode (worked in MTGS mode since it only quit the thread, but even
|
|
|
|
// that wasn't needed).
|
|
|
|
//PostQuitMessage(0);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc((HWND)m_hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSWndDX::Create(const string& title, int w, int h)
|
|
|
|
{
|
2017-02-22 21:54:51 +00:00
|
|
|
if(m_hWnd)
|
|
|
|
throw GSDXRecoverableError();
|
2013-01-04 11:41:51 +00:00
|
|
|
|
2013-06-16 02:48:16 +00:00
|
|
|
m_managed = true;
|
|
|
|
|
2013-01-04 11:41:51 +00:00
|
|
|
WNDCLASS wc;
|
|
|
|
|
|
|
|
memset(&wc, 0, sizeof(wc));
|
|
|
|
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.hInstance = theApp.GetModuleHandle();
|
|
|
|
// TODO: wc.hIcon = ;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
2013-01-04 15:41:37 +00:00
|
|
|
wc.lpszClassName = "GSWndDX";
|
2013-01-04 11:41:51 +00:00
|
|
|
|
|
|
|
if(!GetClassInfo(wc.hInstance, wc.lpszClassName, &wc))
|
|
|
|
{
|
|
|
|
if(!RegisterClass(&wc))
|
|
|
|
{
|
2017-02-22 21:54:51 +00:00
|
|
|
throw GSDXRecoverableError();
|
2013-01-04 11:41:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW | WS_BORDER;
|
|
|
|
|
|
|
|
GSVector4i r;
|
|
|
|
|
|
|
|
GetWindowRect(GetDesktopWindow(), r);
|
|
|
|
|
|
|
|
bool remote = !!GetSystemMetrics(SM_REMOTESESSION);
|
|
|
|
|
|
|
|
if(w <= 0 || h <= 0 || remote)
|
|
|
|
{
|
|
|
|
w = r.width() / 3;
|
|
|
|
h = r.width() / 4;
|
|
|
|
|
|
|
|
if(!remote)
|
|
|
|
{
|
|
|
|
w *= 2;
|
|
|
|
h *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.left = (r.left + r.right - w) / 2;
|
|
|
|
r.top = (r.top + r.bottom - h) / 2;
|
|
|
|
r.right = r.left + w;
|
|
|
|
r.bottom = r.top + h;
|
|
|
|
|
|
|
|
AdjustWindowRect(r, style, FALSE);
|
|
|
|
|
|
|
|
m_hWnd = CreateWindow(wc.lpszClassName, title.c_str(), style, r.left, r.top, r.width(), r.height(), NULL, NULL, wc.hInstance, (LPVOID)this);
|
|
|
|
|
2017-02-22 21:54:51 +00:00
|
|
|
if (!m_hWnd)
|
|
|
|
throw GSDXRecoverableError();
|
|
|
|
|
|
|
|
return true;
|
2013-01-04 11:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GSWndDX::Attach(void* handle, bool managed)
|
|
|
|
{
|
|
|
|
// TODO: subclass
|
|
|
|
|
|
|
|
m_hWnd = (HWND)handle;
|
|
|
|
m_managed = managed;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWndDX::Detach()
|
|
|
|
{
|
|
|
|
if(m_hWnd && m_managed)
|
|
|
|
{
|
|
|
|
// close the window, since it's under GSdx care. It's not taking messages anyway, and
|
|
|
|
// that means its big, ugly, and in the way.
|
|
|
|
|
|
|
|
DestroyWindow(m_hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_hWnd = NULL;
|
|
|
|
m_managed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4i GSWndDX::GetClientRect()
|
|
|
|
{
|
|
|
|
GSVector4i r;
|
|
|
|
|
|
|
|
::GetClientRect(m_hWnd, r);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns FALSE if the window has no title, or if th window title is under the strict
|
|
|
|
// management of the emulator.
|
|
|
|
|
|
|
|
bool GSWndDX::SetWindowText(const char* title)
|
|
|
|
{
|
|
|
|
if(!m_managed) return false;
|
|
|
|
|
|
|
|
::SetWindowText(m_hWnd, title);
|
|
|
|
|
|
|
|
return m_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWndDX::Show()
|
|
|
|
{
|
|
|
|
if(!m_managed) return;
|
|
|
|
|
|
|
|
SetForegroundWindow(m_hWnd);
|
|
|
|
ShowWindow(m_hWnd, SW_SHOWNORMAL);
|
|
|
|
UpdateWindow(m_hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWndDX::Hide()
|
|
|
|
{
|
|
|
|
if(!m_managed) return;
|
|
|
|
|
|
|
|
ShowWindow(m_hWnd, SW_HIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWndDX::HideFrame()
|
|
|
|
{
|
|
|
|
if(!m_managed) return;
|
|
|
|
|
|
|
|
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & ~(WS_CAPTION|WS_THICKFRAME));
|
|
|
|
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
SetMenu(m_hWnd, NULL);
|
|
|
|
|
|
|
|
m_frame = false;
|
|
|
|
}
|
|
|
|
#endif
|