Monday, August 25, 2008

Sample FindWindow

HWND hwnd = NULL,hTmpWnd = NULL;

CWnd *WindowHandle = NULL;

LPCTSTR lpStr;

char szWndName[100],szCapWndName[20],szCapAddName[20]; c

har szCaptionName[100];

char szClassName[100]; BOOL bTrue = FALSE;
HWND hMainWnd = NULL;

HWND hCapWnd = NULL;

m_hAddressWnd = NULL;

hwnd = ::FindWindow("#32770","anadona - New Contact");

if (hwnd) { hTmpWnd = ::GetWindow(hwnd, GW_CHILD);
if ( hTmpWnd ) { ::GetWindowText(hTmpWnd, szWndName, sizeof(szWndName));
int i =0,b=0;

while (i<20)>

{ if (lstrcmp(szWndName,"Captured Text") == 0)

{ hCapWnd = hTmpWnd ;b++; }

if (lstrcmp(szWndName,"Address") == 0)

{m_hAddressWnd = hTmpWnd; b++;}

hTmpWnd = ::GetWindow(hTmpWnd, GW_HWNDNEXT);

::GetWindowText(hTmpWnd, szWndName, sizeof(szWndName));

i++; if (b==2) break;
}
hTmpWnd = hCapWnd;

::GetWindowText(hTmpWnd, szWndName, sizeof(szWndName));

if (lstrcmp(szWndName,"Captured Text") == 0)

{ hTmpWnd = ::GetWindow(hTmpWnd, GW_CHILD);

if ( hTmpWnd ) { ::GetClassName(hTmpWnd, szWndName, sizeof(szWndName));

lpStr = csAddressBlock;

::SendMessage(hTmpWnd,WM_SETTEXT,0,(LPARAM)lpStr);

hTmpWnd = ::GetWindow(hTmpWnd, GW_HWNDNEXT);

::GetWindowText(hTmpWnd, szCaptionName, sizeof(szCaptionName));

::GetClassName(hTmpWnd, szClassName, sizeof(szClassName));

while (bTrue == FALSE)

{

if ((lstrcmp(szCaptionName,"&Contact") == 0 ) && (lstrcmp(szClassName,"Button") == 0) )

{ bTrue = TRUE; break; }

hTmpWnd = ::GetWindow(hTmpWnd, GW_HWNDNEXT);

::GetWindowText(hTmpWnd, szCaptionName, sizeof(szCaptionName));

::GetClassName(hTmpWnd, szClassName, sizeof(szClassName)); }

::SendMessage(hTmpWnd,WM_LBUTTONDOWN, 1, 0);

::SendMessage(hTmpWnd,WM_LBUTTONUP, 1, 0); }

} } }

No comments: