/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ClientDLL/clipper.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/seamlessrdp/ClientDLL/clipper.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 938 by astrand, Fri Jul 1 07:01:00 2005 UTC revision 992 by astrand, Sun Aug 28 12:56:38 2005 UTC
# Line 6  Line 6 
6    
7  #include "clipper.h"  #include "clipper.h"
8    
9  BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)  BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
10  {  {
11      UNREFERENCED_PARAMETER(lpvReserved);      UNREFERENCED_PARAMETER( lpvReserved );
12      UNREFERENCED_PARAMETER(hinstDLL);      UNREFERENCED_PARAMETER( hinstDLL );
13        
14      switch (fdwReason) {      switch ( fdwReason ) {
15      case DLL_PROCESS_ATTACH:          case DLL_PROCESS_ATTACH:
16          break;          break;
17            
18      case DLL_THREAD_ATTACH:          case DLL_THREAD_ATTACH:
19          break;          break;
20            
21      case DLL_THREAD_DETACH:          case DLL_THREAD_DETACH:
22          break;          break;
23            
24      case DLL_PROCESS_DETACH:          case DLL_PROCESS_DETACH:
25          break;          break;
26            
27      default:          default:
28          break;          break;
29      }      }
30      return TRUE;      return TRUE;
31  }  }
32    
33  void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event,  void WINAPI VirtualChannelOpenEvent( DWORD openHandle, UINT event,
34                                      LPVOID pdata, UINT32 dataLength,                                       LPVOID pdata, UINT32 dataLength,
35                                      UINT32 totalLength, UINT32 dataFlags)                                       UINT32 totalLength, UINT32 dataFlags )
36  {  {
37      LPDWORD pdwControlCode = (LPDWORD) pdata;      LPDWORD pdwControlCode = ( LPDWORD ) pdata;
38      CHAR ourData[1600];      CHAR ourData[ 1600 ];
39      UINT ui = 0;      UINT ui = 0;
40        
41      UNREFERENCED_PARAMETER(openHandle);      UNREFERENCED_PARAMETER( openHandle );
42      UNREFERENCED_PARAMETER(dataFlags);      UNREFERENCED_PARAMETER( dataFlags );
43        
44      ZeroMemory(ourData, sizeof(ourData));      ZeroMemory( ourData, sizeof( ourData ) );
45        
46      //copy the send string (with the same lenth of the data)      //copy the send string (with the same lenth of the data)
47      strncpy(ourData, (LPSTR) pdata, dataLength / sizeof(char));      strncpy( ourData, ( LPSTR ) pdata, dataLength / sizeof( char ) );
48        
49      if (OUTPUT_DEBUG_INFO == 1) {      if ( OUTPUT_DEBUG_INFO == 1 ) {
50          OutputDebugString          OutputDebugString
51          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Virtual channel data received");          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Virtual channel data received" );
52          OutputDebugString(ourData);          OutputDebugString( ourData );
53      }      }
54        
55      if (dataLength == totalLength) {      if ( dataLength == totalLength ) {
56          switch (event) {          switch ( event ) {
57          case CHANNEL_EVENT_DATA_RECEIVED: {              case CHANNEL_EVENT_DATA_RECEIVED: {
58                  CTokenizer tok(_T((LPSTR) ourData), _T(";"));                  CTokenizer tok( _T( ( LPSTR ) ourData ), _T( ";" ) );
59                  CStdString cs;                  CStdString cs;
60                    
61                  CWindowData *wid = new CWindowData("");                  CWindowData *wid = new CWindowData( "" );
62                  CStdString messageType;                  CStdString messageType;
63                  int mixMaxType = 0;                  int mixMaxType = 0;
64                    
65                  while (tok.Next(cs)) {                  while ( tok.Next( cs ) ) {
66                      CStdString msg;                      CStdString msg;
67                      CTokenizer msgTok(cs, _T("="));                      CTokenizer msgTok( cs, _T( "=" ) );
68                        
69                      msgTok.Next(msg);                      msgTok.Next( msg );
70                        
71                      if (strcmp(msg, "MSG") == 0) {                      if ( strcmp( msg, "MSG" ) == 0 ) {
72                          msgTok.Next(msg);                          msgTok.Next( msg );
73                          messageType = msg;                          messageType = msg;
74                      }                      }
75                        
76                      if (strcmp(msg, "ID") == 0) {                      if ( strcmp( msg, "ID" ) == 0 ) {
77                          msgTok.Next(msg);                          msgTok.Next( msg );
78                          wid->SetId(msg);                          wid->SetId( msg );
79                      } else if (strcmp(msg, "TITLE") == 0) {                      } else if ( strcmp( msg, "TITLE" ) == 0 ) {
80                          msgTok.Next(msg);                          msgTok.Next( msg );
81                          wid->SetTitle(msg);                          wid->SetTitle( msg );
82                      } else if (strcmp(msg, "POS") == 0) {                      } else if ( strcmp( msg, "POS" ) == 0 ) {
83                          msgTok.Next(msg);                          msgTok.Next( msg );
84                            
85                          CStdString pos;                          CStdString pos;
86                          CTokenizer posTok(msg, _T("~"));                          CTokenizer posTok( msg, _T( "~" ) );
87                            
88                          posTok.Next(pos);                          posTok.Next( pos );
89                            
90                            
91                          // check bounds, coords can be negative if window top left point is moved off the screen.                          // check bounds, coords can be negative if window top left point is moved off the screen.
92                          // we don't care about that since the window can't be see so just use zero.                          // we don't care about that since the window can't be see so just use zero.
93                            
94                          if (strchr(pos, '-') == NULL) {                          if ( strchr( pos, '-' ) == NULL ) {
95                              wid->SetX1(atoi(pos));                              wid->SetX1( atoi( pos ) );
96                          } else {                          } else {
97                              wid->SetX1(0);                              wid->SetX1( 0 );
98                          }                          }
99                            
100                          posTok.Next(pos);                          posTok.Next( pos );
101                            
102                          if (strchr(pos, '-') == NULL) {                          if ( strchr( pos, '-' ) == NULL ) {
103                              wid->SetY1(atoi(pos));                              wid->SetY1( atoi( pos ) );
104                          } else {                          } else {
105                              wid->SetY1(0);                              wid->SetY1( 0 );
106                          }                          }
107                            
108                          posTok.Next(pos);                          posTok.Next( pos );
109                            
110                          if (strchr(pos, '-') == NULL) {                          if ( strchr( pos, '-' ) == NULL ) {
111                              wid->SetX2(atoi(pos));                              wid->SetX2( atoi( pos ) );
112                          } else {                          } else {
113                              wid->SetX2(0);                              wid->SetX2( 0 );
114                          }                          }
115                            
116                          posTok.Next(pos);                          posTok.Next( pos );
117                            
118                          if (strchr(pos, '-') == NULL) {                          if ( strchr( pos, '-' ) == NULL ) {
119                              wid->SetY2(atoi(pos));                              wid->SetY2( atoi( pos ) );
120                          } else {                          } else {
121                              wid->SetY2(0);                              wid->SetY2( 0 );
122                          }                          }
123                      } else if (strcmp(msg, "TYPE") == 0) {                      } else if ( strcmp( msg, "TYPE" ) == 0 ) {
124                          msgTok.Next(msg);                          msgTok.Next( msg );
125                          mixMaxType = atoi(msg);                          mixMaxType = atoi( msg );
126                      }                      }
127                  }                  }
128                    
129                  if (strcmp(messageType, "HSHELL_WINDOWCREATED") == 0) {                  if ( strcmp( messageType, "HSHELL_WINDOWCREATED" ) == 0 ) {
130                      if (OUTPUT_DEBUG_INFO == 1) {                      if ( OUTPUT_DEBUG_INFO == 1 ) {
131                          OutputDebugString                          OutputDebugString
132                          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HSHELL_WINDOWCREATED window title is:");                          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HSHELL_WINDOWCREATED window title is:" );
133                          OutputDebugString(wid->GetTitle());                          OutputDebugString( wid->GetTitle() );
134                      }                      }
135                        
136                      CStdString s = wid->GetId();                      CStdString s = wid->GetId();
137                      char *ptr;                      char *ptr;
138                      int length = s.GetLength();                      int length = s.GetLength();
139                      ptr = s.GetBufferSetLength(length);                      ptr = s.GetBufferSetLength( length );
140                        
141                      hash_insert(ptr, wid, &m_ht);                      hash_insert( ptr, wid, &m_ht );
142                        
143                      CreateAndShowWindow(wid);                      CreateAndShowWindow( wid );
144                        
145                      DoClipping(1);                      DoClipping( 1 );
146                  } else if (strcmp(messageType, "HSHELL_WINDOWDESTROYED") == 0) {                  } else if ( strcmp( messageType, "HSHELL_WINDOWDESTROYED" ) == 0 ) {
147                      if (OUTPUT_DEBUG_INFO == 1) {                      if ( OUTPUT_DEBUG_INFO == 1 ) {
148                          OutputDebugString                          OutputDebugString
149                          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HSHELL_WINDOWDISTROYED window title is:");                          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HSHELL_WINDOWDISTROYED window title is:" );
150                          OutputDebugString(wid->GetTitle());                          OutputDebugString( wid->GetTitle() );
151                      }                      }
152                        
153                      CStdString s = wid->GetId();                      CStdString s = wid->GetId();
154                      char *ptr;                      char *ptr;
155                      int length = s.GetLength();                      int length = s.GetLength();
156                      ptr = s.GetBufferSetLength(length);                      ptr = s.GetBufferSetLength( length );
157                        
158                      CWindowData *oldWinData =                      CWindowData *oldWinData =
159                          (CWindowData *) hash_del(ptr, &m_ht);                          ( CWindowData * ) hash_del( ptr, &m_ht );
160                            
161                      DestroyTaskbarWindow(oldWinData);                      DestroyTaskbarWindow( oldWinData );
162                        
163                      delete oldWinData;                      delete oldWinData;
164                        
165                      DoClipping(1);                      DoClipping( 1 );
166                  } else if (strcmp(messageType, "HCBT_MINMAX") == 0) {                  } else if ( strcmp( messageType, "HCBT_MINMAX" ) == 0 ) {
167                      if (OUTPUT_DEBUG_INFO == 1) {                      if ( OUTPUT_DEBUG_INFO == 1 ) {
168                          OutputDebugString                          OutputDebugString
169                          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HCBT_MINMAX");                          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HCBT_MINMAX" );
170                      }                      }
171                        
172                        
173                      //TODO                      //TODO
174                        
175                  } else if (strcmp(messageType, "HCBT_MOVESIZE") == 0) {                  } else if ( strcmp( messageType, "HCBT_MOVESIZE" ) == 0 ) {
176                      if (OUTPUT_DEBUG_INFO == 1) {                      if ( OUTPUT_DEBUG_INFO == 1 ) {
177                          OutputDebugString                          OutputDebugString
178                          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HCBT_MOVESIZE window title is:");                          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type HCBT_MOVESIZE window title is:" );
179                          OutputDebugString(wid->GetTitle());                          OutputDebugString( wid->GetTitle() );
180                      }                      }
181                        
182                      CStdString s = wid->GetId();                      CStdString s = wid->GetId();
183                      char *ptr;                      char *ptr;
184                      int length = s.GetLength();                      int length = s.GetLength();
185                      ptr = s.GetBufferSetLength(length);                      ptr = s.GetBufferSetLength( length );
186                        
187                      CWindowData *movedWinData =                      CWindowData *movedWinData =
188                          (CWindowData *) hash_lookup(ptr, &m_ht);                          ( CWindowData * ) hash_lookup( ptr, &m_ht );
189                            
190                      if (movedWinData != NULL) {                      if ( movedWinData != NULL ) {
191                          movedWinData->SetX1(wid->GetX1());                          movedWinData->SetX1( wid->GetX1() );
192                          movedWinData->SetX2(wid->GetX2());                          movedWinData->SetX2( wid->GetX2() );
193                          movedWinData->SetY1(wid->GetY1());                          movedWinData->SetY1( wid->GetY1() );
194                          movedWinData->SetY2(wid->GetY2());                          movedWinData->SetY2( wid->GetY2() );
195                            
196                          DoClipping(1);                          DoClipping( 1 );
197                      }                      }
198                        
199                      delete wid;                      delete wid;
200                  } else if (strcmp(messageType, "CALLWNDPROC_WM_MOVING") == 0) {                  } else if ( strcmp( messageType, "CALLWNDPROC_WM_MOVING" ) == 0 ) {
201                      if (OUTPUT_DEBUG_INFO == 1) {                      if ( OUTPUT_DEBUG_INFO == 1 ) {
202                          OutputDebugString                          OutputDebugString
203                          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type CALLWNDPROC_WM_MOVING window title is:");                          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Message was of type CALLWNDPROC_WM_MOVING window title is:" );
204                          OutputDebugString(wid->GetTitle());                          OutputDebugString( wid->GetTitle() );
205                      }                      }
206                        
207                      CStdString s = wid->GetId();                      CStdString s = wid->GetId();
208                      char *ptr;                      char *ptr;
209                      int length = s.GetLength();                      int length = s.GetLength();
210                      ptr = s.GetBufferSetLength(length);                      ptr = s.GetBufferSetLength( length );
211                        
212                      CWindowData *movedWinData =                      CWindowData *movedWinData =
213                          (CWindowData *) hash_lookup(ptr, &m_ht);                          ( CWindowData * ) hash_lookup( ptr, &m_ht );
214                            
215                      if (movedWinData != NULL) {                      if ( movedWinData != NULL ) {
216                          movedWinData->SetX1(wid->GetX1());                          movedWinData->SetX1( wid->GetX1() );
217                          movedWinData->SetX2(wid->GetX2());                          movedWinData->SetX2( wid->GetX2() );
218                          movedWinData->SetY1(wid->GetY1());                          movedWinData->SetY1( wid->GetY1() );
219                          movedWinData->SetY2(wid->GetY2());                          movedWinData->SetY2( wid->GetY2() );
220                            
221                          ////might be too much of an overhead forcing the redraw here. Might be better to do 'DoClipping(0)' instead?                          ////might be too much of an overhead forcing the redraw here. Might be better to do 'DoClipping(0)' instead?
222                          DoClipping(1);                          DoClipping( 1 );
223                      }                      }
224                        
225                      delete wid;                      delete wid;
226                  }                  }
227              }              }
228              break;              break;
229                
230          case CHANNEL_EVENT_WRITE_COMPLETE: {}              case CHANNEL_EVENT_WRITE_COMPLETE: {}
231              break;              break;
232                
233          case CHANNEL_EVENT_WRITE_CANCELLED: {}              case CHANNEL_EVENT_WRITE_CANCELLED: {}
234              break;              break;
235                
236          default: {}              default: {}
237              break;              break;
238          }          }
239      } else {}      } else {}
240  }  }
241    
242    
243  VOID VCAPITYPE VirtualChannelInitEventProc(LPVOID pInitHandle, UINT event,  VOID VCAPITYPE VirtualChannelInitEventProc( LPVOID pInitHandle, UINT event,
244          LPVOID pData, UINT dataLength)          LPVOID pData, UINT dataLength )
245  {  {
246      UINT ui;      UINT ui;
247        
248      UNREFERENCED_PARAMETER(pInitHandle);      UNREFERENCED_PARAMETER( pInitHandle );
249      UNREFERENCED_PARAMETER(dataLength);      UNREFERENCED_PARAMETER( dataLength );
250        
251      switch (event) {      switch ( event ) {
252      case CHANNEL_EVENT_INITIALIZED: {}          case CHANNEL_EVENT_INITIALIZED: {}
253          break;          break;
254            
255      case CHANNEL_EVENT_CONNECTED: {          case CHANNEL_EVENT_CONNECTED: {
256              //              //
257              // open channel              // open channel
258              //              //
259              ui = gpEntryPoints->pVirtualChannelOpen(gphChannel,              ui = gpEntryPoints->pVirtualChannelOpen( gphChannel,
260                                                      &gdwOpenChannel,                      &gdwOpenChannel,
261                                                      CHANNELNAME,                      CHANNELNAME,
262                                                      (PCHANNEL_OPEN_EVENT_FN)                      ( PCHANNEL_OPEN_EVENT_FN )
263                                                      VirtualChannelOpenEvent);                      VirtualChannelOpenEvent );
264                        
265              if (ui == CHANNEL_RC_OK) {}              if ( ui == CHANNEL_RC_OK ) {}
266              else {              else {
267                  MessageBox(NULL, TEXT("Open of RDP virtual channel failed"),                  MessageBox( NULL, TEXT( "Open of RDP virtual channel failed" ),
268                             TEXT("TS Window Clipper"), MB_OK);                              TEXT( "TS Window Clipper" ), MB_OK );
269              }              }
270                
271              if (ui != CHANNEL_RC_OK) {              if ( ui != CHANNEL_RC_OK ) {
272                  return;                  return ;
273              }              }
274          }          }
275          break;          break;
276            
277      case CHANNEL_EVENT_V1_CONNECTED: {          case CHANNEL_EVENT_V1_CONNECTED: {
278              MessageBox(NULL,              MessageBox( NULL,
279                         TEXT                          TEXT
280                         ("Connecting to a non Windows 2000 Terminal Server"),                          ( "Connecting to a non Windows 2000 Terminal Server" ),
281                         TEXT("TS Window Clipper"), MB_OK);                          TEXT( "TS Window Clipper" ), MB_OK );
282          }          }
283          break;          break;
284            
285      case CHANNEL_EVENT_DISCONNECTED: {}          case CHANNEL_EVENT_DISCONNECTED: {}
286          break;          break;
287            
288      case CHANNEL_EVENT_TERMINATED: {          case CHANNEL_EVENT_TERMINATED: {
289              //              //
290              // free the entry points table              // free the entry points table
291              //              //
292              LocalFree((HLOCAL) gpEntryPoints);              LocalFree( ( HLOCAL ) gpEntryPoints );
293          }          }
294          break;          break;
295            
296      default: {}          default: {}
297          break;          break;
298      }      }
299  }  }
300    
301  BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)  BOOL VCAPITYPE VirtualChannelEntry( PCHANNEL_ENTRY_POINTS pEntryPoints )
302  {  {
303      CHANNEL_DEF cd;      CHANNEL_DEF cd;
304      UINT uRet;      UINT uRet;
305        
306      size_t s = 10;      size_t s = 10;
307      hash_construct_table(&m_ht, s);      hash_construct_table( &m_ht, s );
308        
309      //      //
310      // allocate memory      // allocate memory
311      //      //
312      gpEntryPoints =      gpEntryPoints =
313          (PCHANNEL_ENTRY_POINTS) LocalAlloc(LPTR, pEntryPoints->cbSize);          ( PCHANNEL_ENTRY_POINTS ) LocalAlloc( LPTR, pEntryPoints->cbSize );
314            
315      memcpy(gpEntryPoints, pEntryPoints, pEntryPoints->cbSize);      memcpy( gpEntryPoints, pEntryPoints, pEntryPoints->cbSize );
316        
317      //      //
318      // initialize CHANNEL_DEF structure      // initialize CHANNEL_DEF structure
319      //      //
320      ZeroMemory(&cd, sizeof(CHANNEL_DEF));      ZeroMemory( &cd, sizeof( CHANNEL_DEF ) );
321      strcpy(cd.name, CHANNELNAME);       // ANSI ONLY      strcpy( cd.name, CHANNELNAME );       // ANSI ONLY
322        
323      //      //
324      // register channel      // register channel
325      //      //
326      uRet =      uRet =
327          gpEntryPoints->pVirtualChannelInit((LPVOID *) & gphChannel,          gpEntryPoints->pVirtualChannelInit( ( LPVOID * ) & gphChannel,
328                                             (PCHANNEL_DEF) & cd, 1,                                              ( PCHANNEL_DEF ) & cd, 1,
329                                             VIRTUAL_CHANNEL_VERSION_WIN2000,                                              VIRTUAL_CHANNEL_VERSION_WIN2000,
330                                             (PCHANNEL_INIT_EVENT_FN)                                              ( PCHANNEL_INIT_EVENT_FN )
331                                             VirtualChannelInitEventProc);                                              VirtualChannelInitEventProc );
332                                                
333      if (uRet == CHANNEL_RC_OK) {      if ( uRet == CHANNEL_RC_OK ) {
334          if (ALWAYS__CLIP) {          if ( ALWAYS__CLIP ) {
335              DoClipping(1);              DoClipping( 1 );
336          }          }
337      } else {      } else {
338          MessageBox(NULL, TEXT("RDP Virtual channel Init Failed"),          MessageBox( NULL, TEXT( "RDP Virtual channel Init Failed" ),
339                     TEXT("TS Window Clipper"), MB_OK);                      TEXT( "TS Window Clipper" ), MB_OK );
340      }      }
341        
342      if (uRet != CHANNEL_RC_OK) {      if ( uRet != CHANNEL_RC_OK ) {
343          return FALSE;          return FALSE;
344      }      }
345        
346      //      //
347      // make sure channel was initialized      // make sure channel was initialized
348      //      //
349      if (cd.options != CHANNEL_OPTION_INITIALIZED) {      if ( cd.options != CHANNEL_OPTION_INITIALIZED ) {
350          return FALSE;          return FALSE;
351      }      }
352        
353      return TRUE;      return TRUE;
354  }  }
355    
# Line 367  typedef struct _WindowFromProcessOrThrea Line 367  typedef struct _WindowFromProcessOrThrea
367  Wnd4PTID;  Wnd4PTID;
368    
369  // Callback procedure  // Callback procedure
370  BOOL CALLBACK PrivateEnumWindowsProc(HWND hwnd, LPARAM lParam)  BOOL CALLBACK PrivateEnumWindowsProc( HWND hwnd, LPARAM lParam )
371  {  {
372      DWORD procId;      DWORD procId;
373      DWORD threadId;      DWORD threadId;
374      Wnd4PTID *tmp = (Wnd4PTID *) lParam;      Wnd4PTID *tmp = ( Wnd4PTID * ) lParam;
375      // get the process/thread id of current window      // get the process/thread id of current window
376      threadId = GetWindowThreadProcessId(hwnd, &procId);      threadId = GetWindowThreadProcessId( hwnd, &procId );
377      // check if the process/thread id equal to the one passed by lParam?      // check if the process/thread id equal to the one passed by lParam?
378      if (threadId == tmp->threadId || procId == tmp->procId) {      if ( threadId == tmp->threadId || procId == tmp->procId ) {
379          // check if the window is a main window          // check if the window is a main window
380          // because there lots of windows belong to the same process/thread          // because there lots of windows belong to the same process/thread
381          LONG dwStyle = GetWindowLong(hwnd, GWL_STYLE);          LONG dwStyle = GetWindowLong( hwnd, GWL_STYLE );
382          if (dwStyle & WS_SYSMENU) {          if ( dwStyle & WS_SYSMENU ) {
383              tmp->hWnd = hwnd;              tmp->hWnd = hwnd;
384              return FALSE;       // break the enumeration              return FALSE;       // break the enumeration
385          }          }
# Line 388  BOOL CALLBACK PrivateEnumWindowsProc(HWN Line 388  BOOL CALLBACK PrivateEnumWindowsProc(HWN
388  }  }
389    
390  // Enumarate all the MainWindow of the system  // Enumarate all the MainWindow of the system
391  HWND FindProcessMainWindow(DWORD procId)  HWND FindProcessMainWindow( DWORD procId )
392  {  {
393      Wnd4PTID tempWnd4ID;      Wnd4PTID tempWnd4ID;
394      tempWnd4ID.procId = procId;      tempWnd4ID.procId = procId;
395      if (!EnumWindows      if ( !EnumWindows
396              ((WNDENUMPROC) PrivateEnumWindowsProc, (LPARAM) & tempWnd4ID)) {              ( ( WNDENUMPROC ) PrivateEnumWindowsProc, ( LPARAM ) & tempWnd4ID ) ) {
397                
398          if (OUTPUT_DEBUG_INFO == 1) {          if ( OUTPUT_DEBUG_INFO == 1 ) {
399              OutputDebugString              OutputDebugString
400              ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Found main process window");              ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Found main process window" );
401          }          }
402            
403          return tempWnd4ID.hWnd;          return tempWnd4ID.hWnd;
404      }      }
405        
406        
407      if (OUTPUT_DEBUG_INFO == 1) {      if ( OUTPUT_DEBUG_INFO == 1 ) {
408          OutputDebugString          OutputDebugString
409          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Could not find main process window");          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Could not find main process window" );
410      }      }
411        
412      return NULL;      return NULL;
413  }  }
414    
415    
416  void DoClipping(int forceRedraw)  void DoClipping( int forceRedraw )
417  {  {
418      //if main window handle is null, try to get it      //if main window handle is null, try to get it
419      if (m_mainWindowHandle == NULL) {      if ( m_mainWindowHandle == NULL ) {
420          m_mainWindowHandle = FindProcessMainWindow(GetCurrentProcessId());          m_mainWindowHandle = FindProcessMainWindow( GetCurrentProcessId() );
421            
422          //hide the window from taskbar and put at the back of the z order          //hide the window from taskbar and put at the back of the z order
423          if (HIDE_TSAC_WINDOW == 1) {          if ( HIDE_TSAC_WINDOW == 1 ) {
424              ShowWindow(m_mainWindowHandle, SW_HIDE);              ShowWindow( m_mainWindowHandle, SW_HIDE );
425              SetWindowLongPtr(m_mainWindowHandle, GWL_EXSTYLE,              SetWindowLongPtr( m_mainWindowHandle, GWL_EXSTYLE,
426                               GetWindowLong(m_mainWindowHandle,                                GetWindowLong( m_mainWindowHandle,
427                                             GWL_EXSTYLE) | WS_EX_TOOLWINDOW);                                               GWL_EXSTYLE ) | WS_EX_TOOLWINDOW );
428              ShowWindow(m_mainWindowHandle, SW_SHOW);              ShowWindow( m_mainWindowHandle, SW_SHOW );
429          }          }
430            
431          SetWindowPos(m_mainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0,          SetWindowPos( m_mainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0,
432                       SWP_NOMOVE | SWP_NOSIZE);                        SWP_NOMOVE | SWP_NOSIZE );
433      }      }
434        
435      //if we have the handle, lets use it for the clipping      //if we have the handle, lets use it for the clipping
436      if (m_mainWindowHandle != NULL) {      if ( m_mainWindowHandle != NULL ) {
437          RECT wRect;          RECT wRect;
438          GetWindowRect(m_mainWindowHandle, &wRect);          GetWindowRect( m_mainWindowHandle, &wRect );
439            
440          if (OUTPUT_DEBUG_INFO == 1) {          if ( OUTPUT_DEBUG_INFO == 1 ) {
441              OutputDebugString              OutputDebugString
442              ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Restarting clipping...");              ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Restarting clipping..." );
443          }          }
444            
445          m_regionResult = NULL;          m_regionResult = NULL;
446            
447          if (OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1) {          if ( OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1 ) {
448              OutputDebugString              OutputDebugString
449              ("-----------------------------------------------------------------------------");              ( "-----------------------------------------------------------------------------" );
450              OutputDebugString              OutputDebugString
451              ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> starting printing of window table");              ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> starting printing of window table" );
452          }          }
453            
454          //enumerate though hashtable          //enumerate though hashtable
455          if (&m_ht != NULL) {          if ( &m_ht != NULL ) {
456              hash_enumerate(&m_ht, CreateRegionFromWindowData);              hash_enumerate( &m_ht, CreateRegionFromWindowData );
457          }          }
458            
459          if (OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1) {          if ( OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1 ) {
460              OutputDebugString              OutputDebugString
461              ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> finished printing of window table");              ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> finished printing of window table" );
462              OutputDebugString              OutputDebugString
463              ("-----------------------------------------------------------------------------");              ( "-----------------------------------------------------------------------------" );
464          }          }
465            
466          if (m_regionResult == NULL) {          if ( m_regionResult == NULL ) {
467              if (ALWAYS__CLIP) {              if ( ALWAYS__CLIP ) {
468                  m_regionResult = CreateRectRgn(0, 0, 0, 0);                  m_regionResult = CreateRectRgn( 0, 0, 0, 0 );
469              } else {              } else {
470                  m_regionResult =                  m_regionResult =
471                      CreateRectRgn(0, 0, wRect.right, wRect.bottom);                      CreateRectRgn( 0, 0, wRect.right, wRect.bottom );
472              }              }
473          }          }
474            
475          SetWindowRgn(m_mainWindowHandle, (HRGN__ *) m_regionResult, TRUE);          SetWindowRgn( m_mainWindowHandle, ( HRGN__ * ) m_regionResult, TRUE );
476            
477          if (forceRedraw == 1) {          if ( forceRedraw == 1 ) {
478              // invalidate the window and force it to redraw              // invalidate the window and force it to redraw
479              RedrawWindow(m_mainWindowHandle, NULL, NULL,              RedrawWindow( m_mainWindowHandle, NULL, NULL,
480                           RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);                            RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN );
481          }          }
482      } else {      } else {
483          if (OUTPUT_DEBUG_INFO == 1) {          if ( OUTPUT_DEBUG_INFO == 1 ) {
484              OutputDebugString              OutputDebugString
485              ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Coulf not find window to clip");              ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Coulf not find window to clip" );
486          }          }
487      }      }
488  }  }
489    
490  void CreateRegionFromWindowData(char *key, void *value)  void CreateRegionFromWindowData( char *key, void *value )
491  {  {
492      CWindowData *wd;      CWindowData * wd;
493      wd = (CWindowData *) value;      wd = ( CWindowData * ) value;
494      int x1 = 0, x2 = 0, y1 = 0, y2 = 0;      int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
495        
496      char strB[5];      char strB[ 5 ];
497      char strT[5];      char strT[ 5 ];
498      char strL[5];      char strL[ 5 ];
499      char strR[5];      char strR[ 5 ];
500        
501      if (m_regionResult == NULL) {      if ( m_regionResult == NULL ) {
502          m_regionResult = CreateRectRgn(0, 0, 0, 0);          m_regionResult = CreateRectRgn( 0, 0, 0, 0 );
503      }      }
504        
505      if (OUTPUT_DEBUG_INFO == 1 && OUTPUT_WINDOW_TABLE_DEBUG_INFO != 1) {      if ( OUTPUT_DEBUG_INFO == 1 && OUTPUT_WINDOW_TABLE_DEBUG_INFO != 1 ) {
506          OutputDebugString          OutputDebugString
507          ("TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Adding this window to cliping region");          ( "TS WINDOW CLIPPER :: CLIENT DLL :: Info --> Adding this window to cliping region" );
508          OutputDebugString(wd->GetTitle());          OutputDebugString( wd->GetTitle() );
509      }      }
510      if (OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1) {      if ( OUTPUT_WINDOW_TABLE_DEBUG_INFO == 1 ) {
511          ltoa(wd->GetY2(), strB, 10);          ltoa( wd->GetY2(), strB, 10 );
512          ltoa(wd->GetY1(), strT, 10);          ltoa( wd->GetY1(), strT, 10 );
513          ltoa(wd->GetX2(), strR, 10);          ltoa( wd->GetX2(), strR, 10 );
514          ltoa(wd->GetX1(), strL, 10);          ltoa( wd->GetX1(), strL, 10 );
515            
516          OutputDebugString("This window is in the table:");          OutputDebugString( "This window is in the table:" );
517          OutputDebugString(wd->GetTitle());          OutputDebugString( wd->GetTitle() );
518          OutputDebugString(wd->GetId());          OutputDebugString( wd->GetId() );
519          OutputDebugString(strL);          OutputDebugString( strL );
520          OutputDebugString(strT);          OutputDebugString( strT );
521          OutputDebugString(strR);          OutputDebugString( strR );
522          OutputDebugString(strB);          OutputDebugString( strB );
523          OutputDebugString("*******************");          OutputDebugString( "*******************" );
524      }      }
525        
526      HRGN newRegion =      HRGN newRegion =
527          CreateRectRgn(wd->GetX1(), wd->GetY1(), wd->GetX2(), wd->GetY2());          CreateRectRgn( wd->GetX1(), wd->GetY1(), wd->GetX2(), wd->GetY2() );
528            
529      CombineRgn(m_regionResult, newRegion, m_regionResult, RGN_OR);      CombineRgn( m_regionResult, newRegion, m_regionResult, RGN_OR );
530  }  }
531    
532  /*  /*
# Line 534  void CreateRegionFromWindowData(char *ke Line 534  void CreateRegionFromWindowData(char *ke
534    
535     Need to tell the window on the server to do the same.     Need to tell the window on the server to do the same.
536   */   */
537  LRESULT CALLBACK DummyWindowCallbackProc(HWND hwnd, UINT uMsg, WPARAM wParam,  LRESULT CALLBACK DummyWindowCallbackProc( HWND hwnd, UINT uMsg, WPARAM wParam,
538          LPARAM lParam)          LPARAM lParam )
539  {  {
540      //TODO      //TODO
541        
542      return DefWindowProc(hwnd, uMsg, wParam, lParam);      return DefWindowProc( hwnd, uMsg, wParam, lParam );
543  }  }
544    
545  void CreateAndShowWindow(CWindowData * wd)  void CreateAndShowWindow( CWindowData * wd )
546  {  {
547      if (classAlreadyRegistered == 0) {      if ( classAlreadyRegistered == 0 ) {
548          static const char *szWndName = "WTSWinClipperDummy";          static const char * szWndName = "WTSWinClipperDummy";
549          WNDCLASS wc;          WNDCLASS wc;
550            
551          wc.style = 0;          wc.style = 0;
552          wc.lpfnWndProc = DummyWindowCallbackProc;          wc.lpfnWndProc = DummyWindowCallbackProc;
553          wc.cbClsExtra = 0;          wc.cbClsExtra = 0;
# Line 558  void CreateAndShowWindow(CWindowData * w Line 558  void CreateAndShowWindow(CWindowData * w
558          wc.hbrBackground = 0;          wc.hbrBackground = 0;
559          wc.lpszMenuName = 0;          wc.lpszMenuName = 0;
560          wc.lpszClassName = szWndName;          wc.lpszClassName = szWndName;
561            
562          if (RegisterClass(&wc)) {          if ( RegisterClass( &wc ) ) {
563              classAlreadyRegistered = 1;              classAlreadyRegistered = 1;
564          }          }
565      }      }
566        
567      if (classAlreadyRegistered = 1) {      if ( classAlreadyRegistered = 1 ) {
568          HWND hWnd =          HWND hWnd =
569              CreateWindow(TEXT("WTSWinClipperDummy"), wd->GetTitle(), WS_POPUP,              CreateWindow( TEXT( "WTSWinClipperDummy" ), wd->GetTitle(), WS_POPUP,
570                           0, 0, 0, 0, 0, 0, 0, 0);                            0, 0, 0, 0, 0, 0, 0, 0 );
571          ShowWindow(hWnd, 3);          ShowWindow( hWnd, 3 );
572          SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOREDRAW);          SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOREDRAW );
573          wd->TaskbarWindowHandle = hWnd;          wd->TaskbarWindowHandle = hWnd;
574          SetFocus(m_mainWindowHandle);          SetFocus( m_mainWindowHandle );
575      }      }
576  }  }
577    
578  void DestroyTaskbarWindow(CWindowData * wd)  void DestroyTaskbarWindow( CWindowData * wd )
579  {  {
580      if (wd->TaskbarWindowHandle != NULL) {      if ( wd->TaskbarWindowHandle != NULL ) {
581          DestroyWindow(wd->TaskbarWindowHandle);          DestroyWindow( wd->TaskbarWindowHandle );
582      }      }
583  }  }

Legend:
Removed from v.938  
changed lines
  Added in v.992

  ViewVC Help
Powered by ViewVC 1.1.26