We help IT Professionals succeed at work.

Windows API - Finding the handle of an owning window

salted
salted asked
on
Medium Priority
1,261 Views
Last Modified: 2008-02-01
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?
Comment
Watch Question

Author

Commented:
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.

Author

Commented:
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.
Independent Consultant
CERTIFIED EXPERT
Commented:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Dan7el - you genius!

Working like a dream :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.