Get Handle to Alert window using Browser Window Handle

    General discussion

  • Hi All,

    I am writing an application to simulate data entry of web pages using a MFC application. This thread might give an idea what i'm trying to do


    I have a button in the html page, which when clicked shows up a alert window (javascript window.alert). I want to simulate click of the enter button by getting the HWND to the alert window and sending VK_ENTER to it, so that it goes away. I was able to get the window handle (HWND) to the Internet Explorer window. I iterate through all the child windows of the Internet Explorer window to find the handle to the alert window. But the problem is, i'm not able to get a handle to the alert window. 

    I tried to use spy and see what is the parent window of the alert window and in the 'Property Inspector' i can see that the parent of the alert window is 'Windows Internet Explorer'. Further i compared the handle of the 'Windows Internet Explorer' in the 'Property Inspector' with the one i get in my code and it matches. Butttt.... when i do 

    HWND childWnd = ::GetWindow(hWnd,GW_CHILD);
    childWnd = ::GetWindow(childWnd,GW_HWNDNEXT);									

    Where hWnd is the handle to 'Internet Explorer', i do not see the alert window in any of the 'childWnd'. 

    Also when i expand the 'Internet Explorer' in the Spy's main window i do not see the alert window although Property Inspector says 'Internet Explorer' in the parent of the alert window. Can someone please explain what is happening here?

    Any help is highly appreciated.


    Monday, October 25, 2010 11:27 AM

All replies

  • Hi,

    Try EnumChildWindows. Some time GetWindow is not reliable.


    Tuesday, October 26, 2010 11:36 PM
  • Hi,

    I tried EnumChildWindows to enumerate all the child windows of the browser window, but still i'm not able to get handle to the Alert window.

    One thing that intrigues me is why is it that the SPY says the parent of the Alert window is the browser. But the Alert window is not listed under the child windows of the browser?



    Wednesday, October 27, 2010 10:28 AM