Link to home
Start Free TrialLog in
Avatar of UdiRaz
UdiRaz

asked on

Why does spy++ get handles to windows I am not?

Hi,
I am using a web browser control and trying to get a handle to its Internet Explorer_Server. I am using the following code as someone here suggested but I got a NULL value. How does spy++ finds the window childs?

I tried 4 different ways.
option 1 : webControl->GetSafeHwnd() is the handle as the spy++ found but GetLastChild returns NULL
option 2: same result
option 3: crash on m_Browser->get_HWND()
option 4: FindWindowEx()


Thanks
static HWND GetLastChild(HWND hwndParent)
{
   HWND hwnd = hwndParent;
   while (TRUE) {
      HWND hwndChild = ::GetWindow(hwnd, GW_CHILD);
      if (hwndChild==NULL)
         return hwnd;
      hwnd = hwndChild;
   }
   return NULL;
}
 
// here is how I use it. /////
 
// option 1
CWnd * webControl = GetDlgItem(IDC_BROWSER_EXPLORER);
HWND lastChild = GetLastChild(webControl->GetSafeHwnd());
SetWindowSubclass(lastChild, InjectMyCharacters, 0, 0);
 
// option 2 ( CBrowserExplorer * m_Browser )
HWND lastChild = GetLastChild(m_Browser->GetSafeHwnd());
SetWindowSubclass(lastChild, InjectMyCharacters, 0, 0);
 
// option 3 ( get_HWND is a member of the activeX control )
HWND lastChild = GetLastChild(m_Browser->get_HWND()->GetSafeHwnd());
SetWindowSubclass(lastChild, InjectMyCharacters, 0, 0); 
Open in New Window 
 
// option 4
controlHandle = ::FindWindowEx( m_Browser->GetSafeHwnd(), NULL, MAKEINTATOM(0x8000),  NULL );

Open in new window

childWindow.bmp
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi UdiRaz,

sorry, but I don't see how 'GetLastChild' can return NULL except NULL is passed as 'hwndParent'.

Either you posted a different 'GetLastChild' here or for any reason 'webControl->GetSafeHwnd()' returns NULL.

I tested the function with an application where I use a IE-control and found, that there might be cases where the IE-control itself already is created while the wanted child-windows are not created yet - maybe you call that code too early ...

ZOPPO
Avatar of UdiRaz
UdiRaz

ASKER

Hi ZOPPO,

Thanks for your response. I am not fully understand your answer.
I used the same version of GetLastChild(). I copy and paste it from my code. I am calling this method only in one place and get NULL as return.

What IE control are you using? maybe the default web browser supportted by the wizard has some bugs? How does spy++ get the children handles?

Thanks
Udi Raz
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UdiRaz

ASKER

Thanks. It turns that I did called this method to early ( OnInitDlg ).