A nicer spy

François Gouget fgouget at codeweavers.com
Tue Feb 13 23:51:57 CST 2001


   The current spy implementation will truncate a 12 character window
name to just 10 characters even though it uses a 16 bytes buffer!

   The problem is that it always reserves space for the ellipsis. The
proposed implementation is smarter about this (and may also be very
slightly more efficient).


Changelog:

   François Gouget <fgouget at codeweavers.com>

 * windows/spy.c
   Be smarter about the ellipsis in SPY_GetWndName

-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: windows/spy.c
===================================================================
RCS file: /home/cvs/wine/wine/windows/spy.c,v
retrieving revision 1.12
diff -u -r1.12 spy.c
--- windows/spy.c	2001/01/25 21:47:12	1.12
+++ windows/spy.c	2001/02/14 05:09:22
@@ -1444,23 +1444,27 @@
     WND* pWnd = WIN_FindWndPtr( hwnd );
     if( pWnd )
     {
-	INT n = sizeof(wnd_buffer) - 6;
 	LPSTR p = wnd_buffer;
         char  postfix;
 	
 	if( pWnd->text && pWnd->text[0] != '\0' )
 	{
 	    LPWSTR src = pWnd->text;
+	    int n=sizeof(wnd_buffer)-2;
 	    *(p++) = postfix = '\"';
-	    while ((n-- > 1) && *src) *p++ = *src++;
-            if( *src ) for( n = 0; n < 3; n++ ) *(p++)='.';
+	    while ((n-- > 0) && *src) *p++ = *src++;
 	}
 	else /* get class name */
 	{
-	    *(p++)='{';
-	    GlobalGetAtomNameA((ATOM) GetClassWord(pWnd->hwndSelf, GCW_ATOM), p, n + 1);
-	    p += strlen(p);
-	    postfix = '}';
+	    *(p++) = '{';
+	    p+=GlobalGetAtomNameA((ATOM) GetClassWord(pWnd->hwndSelf, GCW_ATOM), p, sizeof(wnd_buffer)-1);
+	    postfix='}';
+	}
+	if( p-wnd_buffer == sizeof(wnd_buffer)-1 ) {
+	    p=wnd_buffer+sizeof(wnd_buffer)-5;
+	    *(p++) = '.';
+	    *(p++) = '.';
+	    *(p++) = '.';
 	}
 	*(p++) = postfix;
 	*(p++) = '\0';


More information about the wine-patches mailing list