locked
WM_HTML_GETOBJECT returns developers console instead of the main window (IE) RRS feed

  • Question

  • I'm accessing my Internet Explorer window with a valid handler (hWnd) like this:

    lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT");
                    if (lngMsg != 0)
                    {
                        SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes);
                        if (!(bool)(lRes == 0))
                        {
                            int hr = ObjectFromLresult(lRes, ref IID_IHTMLDocument2, 0, ref document);
                        }
                    }

    While accessing the window as is it works as expected and I get an object of type IHTMLDocument2 with the window document. But if I open the developers console, it seems that the console overlaps the main window. 

    For instance, the url of the document will be "res://C:\\WINDOWS\\SYSTEM32\\F12\\F12Script.dll/23/console/console.html", the title will match the title of the selected tab, etc. 

    Is there a way to access the window itself and not the debugger?

    Tuesday, June 9, 2020 11:09 AM

All replies

  • Hello kfedor,

    Thanks for posting here.

    I not very clear about this issue. If you are talking about how to get the target window handle, I can only see hWnd you directly given but I can't see related code of how to find the hWnd. Or if you are talking about how to get IHTMLDocument2 object interface of target window, it depends the hWnd you pass in. Which window handle do you use as hWnd.

    About the overlap, by default, when I press F12 the debugger console window partly overlap the main IE window. Through spy++ tool you can see that they has different window handle. With passing in these different window handle you can get IHTMLDocument2 object interface for main IE window and debugger console window respectively.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, June 10, 2020 3:34 AM
  • Hi, Rita!

    Thanks for the tip. Indeed, spying on handlers shows, that there are 2 different handlers, one for the main window I'm interested in and one for the debugger window. I have one more question then, how do I differentiate them? 

    This is how I get to the windows: 

     

    EnumProc proc = new EnumProc(EnumWindows);

    EnumChildWindows(hWnd, proc, ref hWnd);

    Where hWnd is the handler of Internet Explorer browser (not the window). 

    I enumerate over the children like this:

       private static int EnumWindows(IntPtr hWnd, ref IntPtr lParam)
            {
                int retVal = 1;
                StringBuilder classname = new StringBuilder(128);
                GetClassName(hWnd, classname, classname.Capacity);
                /// check if the instance we have found is Internet Explorer_Server
                if ((bool)(string.Compare(classname.ToString(), "Internet Explorer_Server") == 0))
                {
                    lParam = hWnd;
                    retVal = 0;
                }
                return retVal;
            }

    The thing is, the debugger window has the same classname as the main one. And looking into the window details in Spy++, I realize the windows are very similiar... I need a way to filter out the debugger window.  

    Wednesday, June 10, 2020 8:32 AM

  • Where hWnd is the handler of Internet Explorer browser (not the window). 

    To enumerate child windows,  hWnd should be the parent window

    For example, it works for me with :

    var ie = (SHDocVw.WebBrowser)Activator.CreateInstance(Type.GetTypeFromProgID("InternetExplorer.Application"));
    ie.Visible = true;
    ie.Navigate("http://www.google.com");
    while (ie.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { };
    int hWndIE = ie.HWND;
    

    then 

    IntPtr hWndChild = IntPtr.Zero;
    EnumChildCallback cb = new EnumChildCallback(EnumChildProc);
    EnumChildWindows((IntPtr)hWndIE, cb, ref hWndChild);

    etc...

    Wednesday, June 10, 2020 2:50 PM
  • Hello kfedor,

    When you open a new page it will create a "Frame Tab" sub-tree which containing a "F12FrameWindow", a "InternetToolBarHost" and a "TabWindowClass" like the following snapshot shows:

    What you mentioned are debug console window and main window are included in the "F12FrameWindow" and the "TabWindowClass" separately like the following snapshot shows. Although they have the same class name "Internet Explorer_Server" but they have different root classes.

    So what you need to do is finding the child window "TabWindowClass" belongs to "Frame Tab" and then find the "Shell DocObject View" -> "Internet Explorer_Server".

    Please let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, June 11, 2020 1:50 AM
  • Hi, Rita!

    Yes, I've gone the same route - checking the parent's hierarchy :)

    Thanks for your help

    Thursday, June 11, 2020 7:58 AM