• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1245
  • Last Modified:

Windows API - Finding the handle of an owning window


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)

public static extern IntPtr FindWindow(string sClassName, string sWindowName);


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

Is there another Windows API function I can import?
  • 3
1 Solution
saltedAuthor 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.
saltedAuthor 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.
saltedAuthor Commented:
Dan7el - you genius!

Working like a dream :)

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now