Fordy, that's exactly how they work.
bennyandthejets: You need to traverse the set of windows yourself (like Fordy says), and then process the child windows as you find them until you reach the window you require. Using the handle from another program is guaranteed to give you problems.
This should help you:
Code:
DWORD dwlp;
EnumWindows((WNDENUMPROC)EnumProc,dwlp);
Later on in the program...
Code:
BOOL __stdcall EnumProc(HWND hWnd,LPARAM lp)
{
DWORD * pPid;
DWORD result;
void *hg;
DWORD id;
if(hWnd==NULL)
return FALSE;
hg = GlobalAlloc(GMEM_SHARE,sizeof(DWORD));
pPid = (DWORD *)GlobalLock(hg);
result = GetWindowThreadProcessId(hWnd,pPid);
if(result){
char title[110];
char className[95];
char totalStr[256];
GetClassName(hWnd,className,95);
GetWindowText(hWnd,title,110);
id=*pPid;
ultoa(id,totalStr,10);
strcat(totalStr,"\t");
if(title){
strcat(totalStr,title);
strcat(totalStr,"\t");
}
strcat(totalStr,className);
// TODO: Do something with totalStr
}
else{
GlobalUnlock(hg);
GlobalFree(hg);
return false;
}
GlobalUnlock(hg);
GlobalFree(hg);
return true;
}