2012-12-24 10:20:23 -05:00
|
|
|
/*
|
|
|
|
DXWnd/dxwnd.cpp
|
|
|
|
DirectX Hook Module
|
|
|
|
Copyright(C) 2004-2011 SFB7/GHO
|
|
|
|
|
|
|
|
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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// MainFrm.cpp : CMainFrame defines the class behavior.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "dxwndhost.h"
|
|
|
|
|
|
|
|
#include "MainFrm.h"
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#undef THIS_FILE
|
|
|
|
static char THIS_FILE[] = __FILE__;
|
|
|
|
#endif
|
|
|
|
|
2014-04-12 12:40:05 -04:00
|
|
|
#define MULTIMONITOR TRUE
|
|
|
|
|
2012-12-24 10:20:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CMainFrame
|
|
|
|
|
|
|
|
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
|
|
|
|
//{{AFX_MSG_MAP(CMainFrame)
|
|
|
|
ON_WM_CREATE()
|
2013-02-06 11:19:16 -05:00
|
|
|
ON_WM_MOVE()
|
|
|
|
ON_WM_SIZE()
|
2016-11-18 11:48:16 -05:00
|
|
|
ON_WM_CLOSE()
|
2012-12-24 10:20:23 -05:00
|
|
|
//}}AFX_MSG_MAP
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CMainFrame class constructor / destructor
|
2014-04-13 12:39:06 -04:00
|
|
|
HANDLE GlobalLocker;
|
2012-12-24 10:20:23 -05:00
|
|
|
|
|
|
|
CMainFrame::CMainFrame()
|
|
|
|
{
|
|
|
|
// form constructor starts the service thread responsible to mantain a fixed screen settings
|
|
|
|
// see above ....
|
|
|
|
// duplicate activation check
|
2014-04-13 12:39:06 -04:00
|
|
|
GlobalLocker=CreateSemaphore(NULL, 0, 1, "DxWnd LOCKER");
|
|
|
|
if(GlobalLocker==NULL){
|
2014-06-22 12:39:24 -04:00
|
|
|
MessageBoxLang(DXW_STRING_SEMAPHORE, DXW_STRING_WARNING, MB_OK | MB_ICONEXCLAMATION);
|
2012-12-24 10:20:23 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(GetLastError()==ERROR_ALREADY_EXISTS){
|
2014-06-22 12:39:24 -04:00
|
|
|
MessageBoxLang(DXW_STRING_DXWRUNNING, DXW_STRING_WARNING, MB_OK | MB_ICONEXCLAMATION);
|
2012-12-24 10:20:23 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CMainFrame::~CMainFrame()
|
|
|
|
{
|
2013-02-06 11:19:16 -05:00
|
|
|
char val[32];
|
|
|
|
|
2014-04-13 12:39:06 -04:00
|
|
|
// when in icon tray, skip...
|
|
|
|
if (!cx || !cy) return;
|
|
|
|
|
2013-02-06 11:19:16 -05:00
|
|
|
// adjust client win coordinates
|
|
|
|
RECT rect;
|
|
|
|
rect.top = y;
|
|
|
|
rect.bottom = y + cy;
|
|
|
|
rect.left = x;
|
|
|
|
rect.right = x + cx;
|
|
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, 1);
|
2016-04-05 12:45:52 -04:00
|
|
|
|
2013-02-06 11:19:16 -05:00
|
|
|
x = rect.left;
|
|
|
|
y = rect.top;
|
|
|
|
cx = rect.right - rect.left;
|
|
|
|
cy = rect.bottom - rect.top;
|
|
|
|
|
|
|
|
// save window rect
|
|
|
|
sprintf_s(val, sizeof(val), "%i", x);
|
2015-10-21 12:42:12 -04:00
|
|
|
WritePrivateProfileString("window", "posx", val, gInitPath);
|
2013-02-06 11:19:16 -05:00
|
|
|
sprintf_s(val, sizeof(val), "%i", y);
|
2015-10-21 12:42:12 -04:00
|
|
|
WritePrivateProfileString("window", "posy", val, gInitPath);
|
2013-02-06 11:19:16 -05:00
|
|
|
sprintf_s(val, sizeof(val), "%i", cx);
|
2015-10-21 12:42:12 -04:00
|
|
|
WritePrivateProfileString("window", "sizx", val, gInitPath);
|
2013-02-06 11:19:16 -05:00
|
|
|
sprintf_s(val, sizeof(val), "%i", cy);
|
2015-10-21 12:42:12 -04:00
|
|
|
WritePrivateProfileString("window", "sizy", val, gInitPath);
|
2012-12-24 10:20:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
|
|
{
|
|
|
|
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
|
|
|
|
{
|
2016-04-08 12:46:45 -04:00
|
|
|
char InitPath[MAX_PATH];
|
2016-06-26 12:46:13 -04:00
|
|
|
int iMaxX, iMaxY, iMinX, iMinY;
|
2016-04-08 12:46:45 -04:00
|
|
|
GetCurrentDirectory(MAX_PATH, InitPath);
|
|
|
|
strcat_s(InitPath, sizeof(InitPath), "\\dxwnd.ini");
|
|
|
|
cs.x = GetPrivateProfileInt("window", "posx", 50, InitPath);
|
|
|
|
cs.y = GetPrivateProfileInt("window", "posy", 50, InitPath);
|
|
|
|
cs.cx = GetPrivateProfileInt("window", "sizx", 320, InitPath);
|
|
|
|
cs.cy = GetPrivateProfileInt("window", "sizy", 200, InitPath);
|
2013-01-07 11:38:05 -05:00
|
|
|
|
|
|
|
// keep window inside desktop boundaries
|
2014-04-12 12:40:05 -04:00
|
|
|
#ifdef MULTIMONITOR
|
2016-06-26 12:46:13 -04:00
|
|
|
iMinX = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
iMinY = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
|
|
|
|
iMaxX = iMinX + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
iMaxY = iMinY + ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
2014-04-12 12:40:05 -04:00
|
|
|
#else
|
|
|
|
RECT DesktopRect;
|
2013-01-07 11:38:05 -05:00
|
|
|
::GetWindowRect(::GetDesktopWindow(), &DesktopRect);
|
2014-04-12 12:40:05 -04:00
|
|
|
iMaxX = DesktopRect.right;
|
|
|
|
iMaxY = DesktopRect.bottom;
|
|
|
|
#endif
|
2014-04-13 12:39:06 -04:00
|
|
|
if(cs.cx < 320) cs.cx = 320;
|
|
|
|
if(cs.cy < 200) cs.cy = 200;
|
2016-06-26 12:46:13 -04:00
|
|
|
if(cs.x < iMinX) cs.x = iMinX;
|
|
|
|
if(cs.y < iMinY) cs.y = iMinY;
|
2014-04-12 12:40:05 -04:00
|
|
|
if(cs.x+cs.cx > iMaxX) cs.x = iMaxX - cs.cx;
|
|
|
|
if(cs.y+cs.cy > iMaxY) cs.y = iMaxY - cs.cy;
|
2013-01-07 11:38:05 -05:00
|
|
|
|
2012-12-24 10:20:23 -05:00
|
|
|
if( !CFrameWnd::PreCreateWindow(cs) )
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-02-06 11:19:16 -05:00
|
|
|
void CMainFrame::OnMove(int x, int y)
|
|
|
|
{
|
|
|
|
CFrameWnd::OnMove(x, y);
|
2016-04-05 12:45:52 -04:00
|
|
|
WINDOWPLACEMENT wndpl;
|
|
|
|
wndpl.length = sizeof(wndpl);
|
|
|
|
this->GetWindowPlacement(&wndpl);
|
|
|
|
if(wndpl.showCmd != SW_SHOWNORMAL) return;
|
|
|
|
|
2013-02-06 11:19:16 -05:00
|
|
|
this->x=x;
|
|
|
|
this->y=y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMainFrame::OnSize(UINT nType, int cx, int cy)
|
|
|
|
{
|
|
|
|
CFrameWnd::OnSize(nType, cx, cy);
|
2016-04-05 12:45:52 -04:00
|
|
|
WINDOWPLACEMENT wndpl;
|
|
|
|
wndpl.length = sizeof(wndpl);
|
|
|
|
this->GetWindowPlacement(&wndpl);
|
|
|
|
if(wndpl.showCmd != SW_SHOWNORMAL) return;
|
2013-02-06 11:19:16 -05:00
|
|
|
this->cx=cx;
|
|
|
|
this->cy=cy;
|
|
|
|
}
|
2016-11-18 11:48:16 -05:00
|
|
|
|
|
|
|
void CMainFrame::OnClose()
|
|
|
|
{
|
|
|
|
extern BOOL gTransientMode;
|
|
|
|
extern BOOL gQuietMode;
|
|
|
|
extern BOOL gWarnOnExit;
|
|
|
|
if(gTransientMode || gQuietMode) CFrameWnd::OnClose();
|
|
|
|
|
|
|
|
// check for running apps ....
|
|
|
|
if (GetHookStatus(NULL)==DXW_RUNNING){
|
|
|
|
if (MessageBoxLang(DXW_STRING_EXIT_BUSY, DXW_STRING_WARNING, MB_OKCANCEL | MB_ICONQUESTION)!=IDOK) return;
|
|
|
|
CFrameWnd::OnClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gWarnOnExit){
|
2016-11-26 11:48:21 -05:00
|
|
|
if(MessageBoxLang(DXW_STRING_EXIT_OK, DXW_STRING_WARNING, MB_OKCANCEL)==IDOK)
|
|
|
|
CFrameWnd::OnClose();
|
|
|
|
}
|
2016-11-18 11:48:16 -05:00
|
|
|
else
|
|
|
|
CFrameWnd::OnClose();
|
|
|
|
}
|
2013-02-06 11:19:16 -05:00
|
|
|
|
2012-12-24 10:20:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CMainFrame Diagnostic Class
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
void CMainFrame::AssertValid() const
|
|
|
|
{
|
|
|
|
CFrameWnd::AssertValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMainFrame::Dump(CDumpContext& dc) const
|
|
|
|
{
|
|
|
|
CFrameWnd::Dump(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //_DEBUG
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CMainFrame Message Handler
|
|
|
|
|