CVS: seamlessrdp/ServerExe/HookDll hookdll.c,1.21,1.22

Pierre Ossman <[email protected]> Wed, 15 Mar 2006 05:19:57 -0800
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11816/ServerExe/HookDll

Modified Files:
	hookdll.c 
Log Message:
Get window titles in unicode and send them over the channel in UTF-8. This
also meant that we had to catch WM_SETTEXT after it was handled (so that we
can use GetWindowTextW()).


Index: hookdll.c
===================================================================
RCS file: /cvsroot/rdesktop/seamlessrdp/ServerExe/HookDll/hookdll.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** hookdll.c	15 Mar 2006 12:15:23 -0000	1.21
--- hookdll.c	15 Mar 2006 13:19:54 -0000	1.22
***************
*** 45,48 ****
--- 45,49 ----
  static HHOOK g_cbt_hook = NULL;
  static HHOOK g_wndproc_hook = NULL;
+ static HHOOK g_wndprocret_hook = NULL;
  
  static HINSTANCE g_instance = NULL;
***************
*** 109,121 ****
  				if (wp->flags & SWP_SHOWWINDOW)
  				{
! 					char title[150];
  					int state;
  
  					vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
  
! 					GetWindowText(hwnd, title, sizeof(title));
  
  					vchannel_write("TITLE,0x%x,%s,0x%x", hwnd,
! 						       vchannel_strfilter(title), 0);
  
  					if (style & WS_MAXIMIZE)
--- 110,122 ----
  				if (wp->flags & SWP_SHOWWINDOW)
  				{
! 					unsigned short title[150];
  					int state;
  
  					vchannel_write("CREATE,0x%p,0x%p,0x%x", hwnd, parent, 0);
  
! 					GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
  
  					vchannel_write("TITLE,0x%x,%s,0x%x", hwnd,
! 						       vchannel_strfilter_unicode(title), 0);
  
  					if (style & WS_MAXIMIZE)
***************
*** 163,184 ****
  			break;
  
  		case WM_SETTEXT:
  			{
! 				char *title;
  				if (!(style & WS_VISIBLE))
  					break;
! 				title = _strdup((char *) lparam);
  				vchannel_write("TITLE,0x%p,%s,0x%x", hwnd,
! 					       vchannel_strfilter(title), 0);
! 				free(title);
  				break;
  			}
  
- 		case WM_DESTROY:
- 			if (!(style & WS_VISIBLE))
- 				break;
- 			vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
- 			break;
- 
  		default:
  			break;
--- 164,221 ----
  			break;
  
+ 		case WM_DESTROY:
+ 			if (!(style & WS_VISIBLE))
+ 				break;
+ 			vchannel_write("DESTROY,0x%p,0x%x", hwnd, 0);
+ 			break;
+ 
+ 		default:
+ 			break;
+ 	}
+ 
+       end:
+ 	return CallNextHookEx(g_wndproc_hook, code, cur_thread, details);
+ }
+ 
+ static LRESULT CALLBACK
+ wndprocret_hook_proc(int code, WPARAM cur_thread, LPARAM details)
+ {
+ 	HWND hwnd, parent;
+ 	UINT msg;
+ 	WPARAM wparam;
+ 	LPARAM lparam;
+ 
+ 	LONG style;
+ 
+ 	if (code < 0)
+ 		goto end;
+ 
+ 	hwnd = ((CWPRETSTRUCT *) details)->hwnd;
+ 	msg = ((CWPRETSTRUCT *) details)->message;
+ 	wparam = ((CWPRETSTRUCT *) details)->wParam;
+ 	lparam = ((CWPRETSTRUCT *) details)->lParam;
+ 
+ 	style = GetWindowLong(hwnd, GWL_STYLE);
+ 
+ 	/* Docs say that WS_CHILD and WS_POPUP is an illegal combination,
+ 	   but they exist nonetheless. */
+ 	if ((style & WS_CHILD) && !(style & WS_POPUP))
+ 		goto end;
+ 
+ 	switch (msg)
+ 	{
  		case WM_SETTEXT:
  			{
! 				unsigned short title[150];
  				if (!(style & WS_VISIBLE))
  					break;
! 				/* We cannot use the string in lparam because
! 				   we need unicode. */
! 				GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));
  				vchannel_write("TITLE,0x%p,%s,0x%x", hwnd,
! 					       vchannel_strfilter_unicode(title), 0);
  				break;
  			}
  
  		default:
  			break;
***************
*** 186,190 ****
  
        end:
! 	return CallNextHookEx(g_wndproc_hook, code, cur_thread, details);
  }
  
--- 223,227 ----
  
        end:
! 	return CallNextHookEx(g_wndprocret_hook, code, cur_thread, details);
  }
  
***************
*** 235,238 ****
--- 272,279 ----
  	if (!g_wndproc_hook)
  		g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0);
+ 
+ 	if (!g_wndprocret_hook)
+ 		g_wndprocret_hook =
+ 			SetWindowsHookEx(WH_CALLWNDPROCRET, wndprocret_hook_proc, g_instance, 0);
  }
  
***************
*** 245,248 ****
--- 286,292 ----
  	if (g_wndproc_hook)
  		UnhookWindowsHookEx(g_wndproc_hook);
+ 
+ 	if (g_wndprocret_hook)
+ 		UnhookWindowsHookEx(g_wndprocret_hook);
  }
  



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642