Link to home
Start Free TrialLog in
Avatar of neo77
neo77

asked on

How to fire events from HTML into Application

I have an application with CHtmlView , i want to be able to fire events into the mainapp , like clicking on a button on hyperlink calls a function within my App, just like what we have in Search window on Windows 2000.

I have looked into IHTMLDocument interface but the documentation was confusing for me , any suggestions or samples ???

I can only offer 75 points now cause that is all i have...
Avatar of neo77
neo77

ASKER

I am willing to create a COM object for this if required
Hi NEO77,

Its a bit tricky but this is how its done.

in your html file add a javascript function like this

<SCRIPT LANGUAGE=javascript>
<!--
function button1_onclick() {
location.href="#MyMessage";
}
</SCRIPT>

Basically, what this does is send a message to the browser to go to the internal file bookmark MyMessage.

As there is no MyMessage this message is passed on to the CHTMLView


in your CHTMLView implementation, implement the function:

CHTMLView::OnBeforeNavigate2( LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel )

The lpszURL contains the messages sent from the html file through the browser object so handle it like so

     if (NULL != strstr(lpszURL, "MyMessage"))
     {
         // put your handling in here
     }

Best of luck,

Robert
Avatar of neo77

ASKER

Sure does serve the purpose i'll give you the points if nothing else shows up , i am waiting if someone could give final remarks about if its possible through IHTMLDocument or not ... sorry but i have to keep the discussion open for now
Add an handler for OnBeforeNavigate2, check the URL parameter, set pbCancel to true, and run "your own" action

(it's likely that you need to decouple this operation, i.e. not call a NavigateTo or something from inside the OnBeforeNavigate handler, but post a message to yourself, and do the action in the message handler)

Helped?
Peter
Avatar of neo77

ASKER

is it possible to expose methods from the application to the page , i.e.  i be able to call a method that is in the application from javascript code in page ?
ASKER CERTIFIED SOLUTION
Avatar of peterchen092700
peterchen092700

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> is it possible to expose methods from the application to the page

yes, there's a DRILLER example in MSDN  that show how to
(basically, you can set an external dispatch interface - from ATL it's CAxWindow::SetExternalDispatch - and call into it using window.external.Foo() from jscript)