Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Listening to Windows Post Message in Windows Forms Web Browser Control

$
0
0

I have a requirement to listen to post message from dynamic HTML page post when forms web browser control navigation is done.

The dynamic page sends JSON data through Window.Parent.PostMessage(JSON data )

We can't use iframe to load the dynamic page and hook message listener.

I tried below code to hook onemessage event .

I chose not to use DocumentCompleted event to hook onmessage handler since it is fired when doc is completed and there is no point in adding event handler for onmessage event to listen post messages as the message is posted and window does not have handler attached.

void_loginBrowser_Navigated(objectsender,WebBrowserNavigatedEventArgse)

        {

vardoc = (senderasSystem.Windows.Forms.WebBrowser).Document;

mshtml.

IHTMLWindow3rawWindow = (mshtml.IHTMLWindow3)doc.Window.DomWindow;

rawWindow.attachEvent("onmessage",new DHTMLEventDelegate(MyEventHandler));

}

public delegate void DHTMLEventDelegate(IHTMLEventObj e);

public void MyEventHandler(IHTMLEventObj e)
        {
         //this is not firing
          
        }

I don't seem to resolve IHTMLEventObj5(which MSDN says will contain message data) even though I have MSHTML.dll ver 10.0  .

Please help me in attaching this event as I need to receive the JSON data through this event only .

 

(this.YourEventHandler)

}

               

 

               

//doc.DomDocument


                mshtml.

IHTMLWindow3rawWindow = (mshtml.IHTMLWindow3)doc.Window.DomWindow;

              

// rawWindow.attachEvent("onmessage", OnLoadListener);


                rawWindow.attachEvent(

"onmessage",newDHTMLEventDelegate(this.YourEventHandler));


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>