Getting text of foreign application's ListBox Item.

Hello,
I have a problem. What I am trying to achieve is create automatic test for a foreign application (enter text, push button, select from menu…. etc).

And now I am stuck with ListBox. As it seems in ‘Spy++’ that the ListBox is LBS_OWNERDRAWFIX. So LB_GETTEXT sometimes gets last column or nothing (if the last column is empty). What I did am I overwriting function’s pointers in the process’s memory (ExtTextOutW, TextOutW). Now before the application calls one of these functions it get through my code, I check if the DC belongs to ListBox and if it’s true I store a string.




All works fine until I scroll or change the line (PageDown) for some unknown to me reason lines appear in the ListBox but they are not drawn through hooked functions, as a result of this behavior my sequence of strings is corrupted.

Any ideas what function draws those lines?

Some code example.

BOOL WINAPI Detour_ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,const RECT *lprc,LPCTSTR lpString,UINT cbCount,const INT *lpDx)
{
PrototypeOf_ExtTextOutW* fn = (PrototypeOf_ExtTextOutW*)Ptr_ExtTextOutW;
Test(hdc,lpString,cbCount,Y,X);
return (*fn)(hdc,X,Y,fuOptions,lprc,lpString,cbCount,lpDx);
}

void Test(HDC hdc,LPCTSTR lpString,int cc,int y,int x){
if (lpString==NULL) return;

HWND control = WindowFromDC(hdc);
wchar_t spBuf[BUF_SIZE],cname[100];
wmemset(cname,'\0',100);

GetClassName(control,cname,100);

if (wcscmp(cname,_T("ListBox"))==0){
wmemset(spBuf,'\0',BUF_SIZE);
wmemset(cname,'\0',100);
if (cc==0) cc = wcslen(lpString);
wmemcpy_s(cname,100,lpString,cc);

swprintf(spBuf,BUF_SIZE,_T("%d~~%d~~%d~~%s"),control,y,x,cname);
DWORD i=0;
CallNamedPipe(lpszPipename, spBuf, wcslen(spBuf)*sizeof(wchar_t), NULL,0, &i, NMPWAIT_WAIT_FOREVER);
}
}
Text can also be drawn via DrawText(). Check MSDN Online to make sure you cover all API's.
http://msdn.microsoft.com/en-us/library/dd162490%28v=vs.85%29.aspx

DrawText
DrawTextEx
ExtTextOut
PolyTextOut
TabbedTextOut
TextOut

When an application calls one of these functions, the operating system passes the call to the graphics engine, which in turn passes the call to the appropriate device driver. At the device driver level, all of these calls are supported by one or more calls to the driver's own ExtTextOut or TextOut function.

As MSDN says ALL text function pases ExtTextOut or TextOut function. :(
Topic archived. No new replies allowed.