summaryrefslogtreecommitdiff
path: root/src/SourceWin32.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/SourceWin32.cxx')
-rw-r--r--src/SourceWin32.cxx214
1 files changed, 141 insertions, 73 deletions
diff --git a/src/SourceWin32.cxx b/src/SourceWin32.cxx
index 25ac45b..620bb01 100644
--- a/src/SourceWin32.cxx
+++ b/src/SourceWin32.cxx
@@ -5,7 +5,13 @@ D_DEBUG_DOMAIN( PluggIt_SourceWin32, "PluggIt/SourceWin32", "PluggIt Source Win3
#include "ScreenHooks.h"
-const UINT specIpcCode = RegisterWindowMessage("HOOK.MESSAGE.CODE");
+// Constants
+const UINT RFB_SCREEN_UPDATE = RegisterWindowMessage("WinVNC.Update.DrawRect");
+const UINT RFB_COPYRECT_UPDATE = RegisterWindowMessage("WinVNC.Update.CopyRect");
+const UINT RFB_MOUSE_UPDATE = RegisterWindowMessage("WinVNC.Update.Mouse");
+const char szDesktopSink[] = "WinVNC desktop sink";
+
+typedef BOOL (*SetHooksFn)(DWORD thread_id,UINT UpdateMsg,UINT CopyMsg,UINT MouseMsg,BOOL ddihook);
class SourceWin32 extends Source, Runnable
@@ -41,6 +47,9 @@ class SourceWin32 extends Source, Runnable
private pthread_cond_t m_cond;
+ SetHooksFn SetHooks;
+
+
public class Config extends Source::Config {
friend class SourceWin32;
@@ -168,48 +177,6 @@ class SourceWin32 extends Source, Runnable
pthread_cond_init( &m_cond, NULL );
- if (!m_using_driver) {
- HWND w;
-
- WNDCLASSEX wndClass;
-
- ZeroMemory( &wndClass, sizeof(wndClass) );
-
- wndClass.cbSize = sizeof(wndClass);
- wndClass.style = CS_HREDRAW | CS_VREDRAW;
- wndClass.lpfnWndProc = MsgWndProc;
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hInstance = GetModuleHandle(NULL);
- wndClass.hIcon = NULL;
- wndClass.hIconSm = NULL;
- wndClass.hCursor = LoadCursor( NULL, IDC_UPARROW );
- wndClass.hbrBackground = (HBRUSH) GetStockObject( NULL_BRUSH );
- wndClass.lpszMenuName = NULL;
- wndClass.lpszClassName = "MsgWindow";
-
- if (!RegisterClassEx( &wndClass ))
- throw new Exception( "RegisterClassEx() failed!" );
-
-
- w = CreateWindowEx( 0,
- "MsgWindow",
- "MsgWindow",
- WS_POPUP,// | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 1,
- 1,
- NULL,
- NULL,
- GetModuleHandle(NULL),
- this );
-
- if (!setHook( w ))
- throw new Exception( "Failed to set hooks!" );
- }
-
-
/* Create the thread object. */
m_thread = new Thread( this, "SourceWin32" );
@@ -318,19 +285,19 @@ class SourceWin32 extends Source, Runnable
long long last_time = direct_clock_get_abs_millis();
while (!m_thread->isInterrupted()) {
- if (((const Config&)m_config).m_updating) {
+/* if (((const Config&)m_config).m_updating) {
usleep( 100000 );
queueUpdate( 0, 0, m_size.w - 1, m_size.h - 1 );
pthread_mutex_lock( &m_lock );
}
- else {
+ else*/ {
pthread_mutex_lock( &m_lock );
if (m_updates.num_regions() == 0)
- usleep( 10000 );
- //pthread_cond_wait( &m_cond, &m_lock );
+ //usleep( 10000 );
+ pthread_cond_wait( &m_cond, &m_lock );
}
if (direct_clock_get_abs_millis() - last_time > 2000) {
@@ -339,7 +306,7 @@ class SourceWin32 extends Source, Runnable
m_size.w - 1,
m_size.h - 1 );
- m_updates.addRegion( region );
+ //m_updates.addRegion( region );
last_time = direct_clock_get_abs_millis();
}
@@ -378,9 +345,9 @@ class SourceWin32 extends Source, Runnable
m_updates.addRegion( damage );
- pthread_mutex_unlock( &m_lock );
-
pthread_cond_signal( &m_cond );
+
+ pthread_mutex_unlock( &m_lock );
}
private bool flushUpdates( vector<DFBRectangle_C> &rects ) {
@@ -600,37 +567,49 @@ class SourceWin32 extends Source, Runnable
/**********************************************************************************************************************/
- static LRESULT CALLBACK MsgWndProc( HWND hwnd, // handle to window
- UINT uMsg, // message identifier
- WPARAM wParam, // first message parameter
- LPARAM lParam ) // second message parameter
+ static LRESULT CALLBACK DesktopWndProc( HWND hwnd, // handle to window
+ UINT uMsg, // message identifier
+ WPARAM wParam, // first message parameter
+ LPARAM lParam ) // second message parameter
{
- static SourceWin32 *thiz;
- CREATESTRUCT *create;
+ PCOPYDATASTRUCT CDS;
+ SourceWin32 *thiz = (SourceWin32*)GetWindowLong(hwnd, GWL_USERDATA);
switch (uMsg) {
- case WM_CREATE:
- create = reinterpret_cast<LPCREATESTRUCT>( lParam );
- thiz = reinterpret_cast<SourceWin32 *>( create->lpCreateParams );
- break;
-
case WM_DESTROY:
PostQuitMessage( 0 );
break;
- default:
- if (uMsg == specIpcCode) {
- int x1 = wParam >> 16;
- int y1 = wParam & 0xffff;
- int x2 = lParam >> 16;
- int y2 = lParam & 0xffff;
+ case WM_COPYDATA:
+ CDS = (PCOPYDATASTRUCT) lParam;
+
+ if (CDS->dwData==112233) {
+ DWORD mysize = CDS->cbData;
+ char mytext[1024];
+ char *myptr;
+ char split[4][6];
+
+ strcpy( mytext, (LPCSTR) CDS->lpData );
- if (x1 < x2 && y1 < y2)
- thiz->queueUpdate( x1, y1, x2 - 1, y2 - 1 );
+ myptr = mytext;
+
+ for (int j =0; j<(mysize/20);j++) {
+ for (int i=0;i<4;i++) {
+ strcpy(split[i]," ");
+ strncpy(split[i],myptr,4);
+ myptr = myptr+5;
+ }
+
+ thiz->queueUpdate( atoi(split[0]),
+ atoi(split[1]),
+ atoi(split[2]) - 1,
+ atoi(split[3]) - 1 );
+ }
- break;
}
+ break;
+ default:
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
@@ -638,13 +617,102 @@ class SourceWin32 extends Source, Runnable
}
public virtual int MainLoop() {
+
+ if (!m_using_driver) {
+ HMODULE hModule;
+ char szCurrentDir[MAX_PATH];
+
+ if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH)) {
+ char* p = strrchr(szCurrentDir, '\\');
+ if (p == NULL) return 0;
+ *p = '\0';
+ strcat (szCurrentDir,"\\vnchooks.dll");
+ }
+
+ hModule = LoadLibrary( szCurrentDir );
+ if (!hModule)
+ throw new Exception( "Failed to load vnchooks.dll!" );
+
+ SetHooks = (SetHooksFn) GetProcAddress( hModule, "SetHooks" );
+
+
+
+
+
+ HWND w;
+
+ WNDCLASSEX wndClass;
+
+ ZeroMemory( &wndClass, sizeof(wndClass) );
+
+ wndClass.cbSize = sizeof(wndClass);
+ wndClass.style = 0;
+ wndClass.lpfnWndProc = DesktopWndProc;
+ wndClass.cbClsExtra = 0;
+ wndClass.cbWndExtra = 0;
+ wndClass.hInstance = GetModuleHandle(NULL);
+ wndClass.hIcon = NULL;
+ wndClass.hIconSm = NULL;
+ wndClass.hCursor = NULL;
+ wndClass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
+ wndClass.lpszMenuName = NULL;
+ wndClass.lpszClassName = szDesktopSink;
+
+ if (!RegisterClassEx( &wndClass ))
+ throw new Exception( "RegisterClassEx() failed!" );
+
+
+ w = CreateWindowEx( 0,
+ szDesktopSink,
+ "WinVNC",
+ WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ 400, 200,
+ NULL,
+ NULL,
+ GetModuleHandle(NULL),
+ NULL );
+ if (!w)
+ throw new Exception( "Failed to create hook window!" );
+
+ // Set the "this" pointer for the window
+ SetWindowLong( w, GWL_USERDATA, (long)this);
+
+ if (!SetHooks(
+ GetCurrentThreadId(),
+ RFB_SCREEN_UPDATE,
+ RFB_COPYRECT_UPDATE,
+ RFB_MOUSE_UPDATE, false
+ ))
+ throw new Exception( "Failed to set hooks!" );
+ }
+
+
MSG msg;
- while (GetMessage( &msg, 0, 0, 0 )) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
+ printf( " -> RFB_SCREEN_UPDATE = %u\n", RFB_SCREEN_UPDATE );
+ printf( " -> RFB_COPYRECT_UPDATE = %u\n", RFB_COPYRECT_UPDATE );
+
+ while (WaitMessage()/*GetMessage( &msg, 0, 0, 0 )*/) {
+ printf( " -> Dispatching event (id %u)...\n", msg.message );
+
+ if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
+ if (msg.message == RFB_SCREEN_UPDATE) {
+ queueUpdate( (SHORT)LOWORD(msg.wParam),
+ (SHORT)HIWORD(msg.wParam),
+ (SHORT)LOWORD(msg.lParam) - 1,
+ (SHORT)HIWORD(msg.lParam) - 1 );
+ }
+ else {
+ TranslateMessage( &msg );
+ DispatchMessage( &msg );
+ }
+ }
}
+ printf( " -> EXIT!\n" );
+
return 0;
}
};