Solved

How to fire events from HTML into Application

Posted on 2001-06-08
8
1,029 Views
Last Modified: 2007-11-27
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...
0
Comment
Question by:neo77
8 Comments
 

Author Comment

by:neo77
Comment Utility
I am willing to create a COM object for this if required
0
 

Expert Comment

by:robertmitchell_99
Comment Utility
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
0
 

Author Comment

by:neo77
Comment Utility
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
0
 
LVL 2

Expert Comment

by:GloriousRain
Comment Utility
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Expert Comment

by:peterchen092700
Comment Utility
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
0
 

Author Comment

by:neo77
Comment Utility
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 ?
0
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 75 total points
Comment Utility
a) yes, using the "external" property of IHTMLWindow2
b) yes, by embedding an activex control on the page.

a) seems recommended,
should be window.external, or document.parentWindow.external, in scripting languages.

You create a component that does the stuff you want/need. The application hosting the HTMLView creates an instance of this, and provides this as "External Dispatch" interface to the view.  (ATL's CAxWindow has a "SetExternalDispatch" method, I'm not sure how to do this in MFC, but there's a sample for this on http://msdn.microsoft.com/downloads/samples/internet/browser/driller/default.asp

Peter








0
 
LVL 7

Expert Comment

by:peterchen092700
Comment Utility
>> 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)

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now