Link to home
Start Free TrialLog in
Avatar of salted
salted

asked on

Windows API - Finding the handle of an owning window

Hey,

I've got an instance of InternetExplorer on a new thread running in my app, and, using IE.HWND I am trying to get the handle of the IE window including all the chrome, however, IE.HWND only gives me the handle for the document itself and the status bar for some reason.

I've tried this:

[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
public const int GW_HWNDFIRST = 0;
...

hwnd = (IntPtr)GetWindow(hwnd, GW_HWNDFIRST);

But it's returning a IntPtr with the value of 0.

Anyone now how to go up enough to get the actual full window - it's classname is "IEFrame" - and i've tried using that to get it, but it did the same, and even if it did work, it doesn't garauntee it will get the right instance of IE (i don't want to search by WindowTitle/Name)

[DllImport("user32.Dll")]
public static extern IntPtr FindWindow(string sClassName, string sWindowName);

...

hwnd = FindWindow("IEFrame", string.Empty);


Is there another Windows API function I can import?
Avatar of salted
salted

ASKER

Sorry - just to add, I tried manually spying the handle for the full window of an instance of IE and putting that in the app and it worked perfectly. So i know that's what i'm after. I just can't seem to get that handle at run-time.
Avatar of salted

ASKER

hehe, sorry, one more thing i just thought of - it's IE7 Beta 2 Preview that is installed on this machine - although from when i was doing this with IE6 it doesn't seem to make much difference. I need it to work with IE7 - I can't be certain, but i'm pretty sure IE6's chrome window had a classname of "IEFrame" as well.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America 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 salted

ASKER

Dan7el - you genius!

Working like a dream :)