2001-11-19 03:33:36 +03:00
|
|
|
#include "CMSWindowsScreen.h"
|
|
|
|
#include "CThread.h"
|
|
|
|
#include "CLock.h"
|
|
|
|
#include "TMethodJob.h"
|
|
|
|
#include "CLog.h"
|
|
|
|
#include "CString.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include <cstring>
|
2001-11-19 03:33:36 +03:00
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
//
|
|
|
|
// add backwards compatible multihead support (suppress bogus warning)
|
|
|
|
//
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4706) // assignment within conditional
|
|
|
|
#define COMPILE_MULTIMON_STUBS
|
|
|
|
#include <multimon.h>
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
//
|
|
|
|
// CMSWindowsScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
HINSTANCE CMSWindowsScreen::s_instance = NULL;
|
2001-11-25 21:32:41 +03:00
|
|
|
CMSWindowsScreen* CMSWindowsScreen::s_screen = NULL;
|
2001-11-19 03:33:36 +03:00
|
|
|
|
|
|
|
CMSWindowsScreen::CMSWindowsScreen() :
|
2002-06-11 02:06:45 +04:00
|
|
|
m_class(0),
|
|
|
|
m_cursor(NULL),
|
2002-06-19 21:03:29 +04:00
|
|
|
m_x(0), m_y(0),
|
2002-06-11 02:06:45 +04:00
|
|
|
m_w(0), m_h(0),
|
|
|
|
m_thread(0)
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
2001-11-25 21:32:41 +03:00
|
|
|
assert(s_screen == NULL);
|
|
|
|
s_screen = this;
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMSWindowsScreen::~CMSWindowsScreen()
|
|
|
|
{
|
|
|
|
assert(m_class == 0);
|
2001-11-25 21:32:41 +03:00
|
|
|
s_screen = NULL;
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CMSWindowsScreen::init(HINSTANCE instance)
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
s_instance = instance;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::doRun()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
2002-05-22 21:08:37 +04:00
|
|
|
// save thread id for posting quit message
|
2001-11-19 03:33:36 +03:00
|
|
|
m_thread = GetCurrentThreadId();
|
2002-05-22 21:08:37 +04:00
|
|
|
|
|
|
|
// event loop
|
2001-11-19 03:33:36 +03:00
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
MSG msg;
|
|
|
|
getEvent(&msg);
|
|
|
|
|
|
|
|
// handle quit message
|
|
|
|
if (msg.message == WM_QUIT) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// dispatch message
|
2001-11-25 21:32:41 +03:00
|
|
|
if (!onPreTranslate(&msg)) {
|
2001-11-19 03:33:36 +03:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::doStop()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
PostThreadMessage(m_thread, WM_QUIT, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::openDisplay()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
assert(s_instance != NULL);
|
|
|
|
assert(m_class == 0);
|
|
|
|
|
|
|
|
// create a transparent cursor
|
|
|
|
int cw = GetSystemMetrics(SM_CXCURSOR);
|
|
|
|
int ch = GetSystemMetrics(SM_CYCURSOR);
|
2001-11-25 21:32:41 +03:00
|
|
|
UInt8* cursorAND = new UInt8[ch * ((cw + 31) >> 2)];
|
|
|
|
UInt8* cursorXOR = new UInt8[ch * ((cw + 31) >> 2)];
|
|
|
|
memset(cursorAND, 0xff, ch * ((cw + 31) >> 2));
|
|
|
|
memset(cursorXOR, 0x00, ch * ((cw + 31) >> 2));
|
|
|
|
m_cursor = CreateCursor(s_instance, 0, 0, cw, ch, cursorAND, cursorXOR);
|
|
|
|
delete[] cursorXOR;
|
|
|
|
delete[] cursorAND;
|
2001-11-19 03:33:36 +03:00
|
|
|
|
|
|
|
// register a window class
|
|
|
|
WNDCLASSEX classInfo;
|
|
|
|
classInfo.cbSize = sizeof(classInfo);
|
|
|
|
classInfo.style = CS_DBLCLKS | CS_NOCLOSE;
|
|
|
|
classInfo.lpfnWndProc = &CMSWindowsScreen::wndProc;
|
|
|
|
classInfo.cbClsExtra = 0;
|
|
|
|
classInfo.cbWndExtra = 0;
|
|
|
|
classInfo.hInstance = s_instance;
|
|
|
|
classInfo.hIcon = NULL;
|
|
|
|
classInfo.hCursor = m_cursor;
|
|
|
|
classInfo.hbrBackground = NULL;
|
|
|
|
classInfo.lpszMenuName = NULL;
|
|
|
|
classInfo.lpszClassName = "Synergy";
|
|
|
|
classInfo.hIconSm = NULL;
|
|
|
|
m_class = RegisterClassEx(&classInfo);
|
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
// get screen shape
|
|
|
|
updateScreenShape();
|
2001-11-19 03:33:36 +03:00
|
|
|
|
|
|
|
// let subclass prep display
|
|
|
|
onOpenDisplay();
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::closeDisplay()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
assert(s_instance != NULL);
|
|
|
|
assert(m_class != 0);
|
|
|
|
|
|
|
|
// let subclass close down display
|
|
|
|
onCloseDisplay();
|
|
|
|
|
|
|
|
// unregister the window class
|
|
|
|
UnregisterClass((LPCTSTR)m_class, s_instance);
|
|
|
|
m_class = 0;
|
|
|
|
|
|
|
|
// delete resources
|
|
|
|
DestroyCursor(m_cursor);
|
|
|
|
m_cursor = NULL;
|
|
|
|
|
|
|
|
log((CLOG_DEBUG "closed display"));
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
HINSTANCE
|
|
|
|
CMSWindowsScreen::getInstance()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
ATOM
|
|
|
|
CMSWindowsScreen::getClass() const
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
return m_class;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-19 21:03:29 +04:00
|
|
|
CMSWindowsScreen::updateScreenShape()
|
2002-05-24 21:54:28 +04:00
|
|
|
{
|
2002-06-19 21:03:29 +04:00
|
|
|
m_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
m_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
|
|
|
m_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
|
|
|
log((CLOG_INFO "screen shape: %d,%d %dx%d", m_x, m_y, m_w, m_h));
|
2002-05-24 21:54:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-19 21:03:29 +04:00
|
|
|
CMSWindowsScreen::getScreenShape(
|
|
|
|
SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
assert(m_class != 0);
|
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
x = m_x;
|
|
|
|
y = m_y;
|
|
|
|
w = m_w;
|
|
|
|
h = m_h;
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
HDESK
|
|
|
|
CMSWindowsScreen::openInputDesktop() const
|
2002-06-09 01:48:00 +04:00
|
|
|
{
|
|
|
|
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
|
|
|
DESKTOP_CREATEWINDOW |
|
|
|
|
DESKTOP_HOOKCONTROL |
|
|
|
|
GENERIC_WRITE);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
CString
|
2002-06-17 17:31:21 +04:00
|
|
|
CMSWindowsScreen::getDesktopName(HDESK desk) const
|
2002-06-09 01:48:00 +04:00
|
|
|
{
|
|
|
|
if (desk == NULL) {
|
|
|
|
return CString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DWORD size;
|
|
|
|
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
|
|
|
|
TCHAR* name = new TCHAR[size / sizeof(TCHAR) + 1];
|
|
|
|
GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
|
|
|
|
CString result(name);
|
|
|
|
delete[] name;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
bool
|
2002-06-17 17:31:21 +04:00
|
|
|
CMSWindowsScreen::isCurrentDesktop(HDESK desk) const
|
2002-06-09 01:48:00 +04:00
|
|
|
{
|
|
|
|
return CStringUtil::CaselessCmp::equal(getDesktopName(desk),
|
|
|
|
getCurrentDesktopName());
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CMSWindowsScreen::getEvent(MSG* msg) const
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
// wait for an event in a cancellable way
|
2002-06-14 22:08:20 +04:00
|
|
|
CThread::waitForEvent();
|
2001-11-19 03:33:36 +03:00
|
|
|
GetMessage(msg, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
LRESULT CALLBACK
|
2002-06-17 17:31:21 +04:00
|
|
|
CMSWindowsScreen::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
2001-11-25 21:32:41 +03:00
|
|
|
assert(s_screen != NULL);
|
|
|
|
return s_screen->onEvent(hwnd, msg, wParam, lParam);
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|