Best
--
=======================
Steven Tang
SYWWUYU)
**:)
I'm not sure that I understand the question rightly. Do you mean to call
from an ActiveX to a javascript function in a webpage (callback from
ActiveX)? My understanding of your timer solution is to poll a property of
the ActiveX object. I believe that there must be a better and more direct
solution. Here is the basic idea:
We can call from an ActiveX control to a javascript function using the
IOleObject::GetClientSite method
(http://msdn.microsoft.com/en-us/library/ms692603(VS.85).aspx). The method
returns an IOleClientSite interface
(http://msdn.microsoft.com/en-us/library/ms693706.aspx).
IOleClient::GetContainer
(http://msdn.microsoft.com/en-us/library/ms688620(VS.85).aspx) returns an
IOleContainer interface. IOleContainer can be QueryInterface-ed as
IHTMLDocument2
(http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx) in a web
browser. Calling IHTMLDocument2::parentWindow
(http://msdn.microsoft.com/en-us/library/aa752599(VS.85).aspx) provides us
with the IHTMLWindow2 interface. Then, we can call its execScript method to
run any javascript code we specified in the callback.
Here is an implementation of the above idea. (The ActiveX control in this
example is written in C#. We need to convert it to MFC ActiveX code based
on the logic)
http://www.googlemother.com/wpblogs/2008/09/02/cusingactivexdevelopmentinthe
javascriptmethodcall/
Additional readings:
Component-Based Development with Visual C#
http://www.codeproject.com/KB/books/0764549146_8.aspx
(see the section 'Customizing the WebBrowser component')
Regards,
Jialiang Ge (jia...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Thank you very much.
新年快乐
=======================
Steven Tang
SYWWUYU)
**:)
Glad to help.
Regards,
Jialiang Ge (jia...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
I just checked in the example of calling script from MFC activex control.
Please download the example from
All-In-One Code Framework
http://cfx.codeplex.com/SourceControl/ListDownloadableCommits.aspx
Changeset: 22487
===================
To run the example:
Download the changeset 22487, and open CodeFx 2008 - COM.sln in an elevated
instance of Visual Studio. Build the examples HTMLEmbedActiveX and
MFCSafeActiveX, then run HTMLEmbedActiveX. Open the page
MFCSafeActiveX.html which loads the MFCSafeActiveX control. Enter
"HelloWorld" in the text box for "Call Script", and click the button "Call
Script". "HelloWorld" is the name of a javascript in the page. When
clicking "Call Script", the MFC ActiveX control reads the script name, and
invoke the script using COleDispatchDriver::InvokeHelper. IE will pop up an
alert dialog "HelloWorld" which tells you that the call succeeds.
Regards,
Jialiang Ge (jia...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
IServiceProvider *serviceProvider = NULL;
IWebBrowser2 *browser = NULL;
IHTMLDocument3 *doc3 = NULL;
IHTMLDocument *doc = NULL;
IHTMLDocument2 *doc2 = NULL;
IDispatch *docDisp = NULL;
IHTMLElement *elem = NULL;
IDispatch* script;
IHTMLWindow2 *win2;
HRESULT hr;
hr = pUnkSite->QueryInterface(IID_IServiceProvider,
(void**)&serviceProvider);
if(!SUCCEEDED(hr))
{
return;
}
hr = serviceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2,
(void**)&browser);
if(!SUCCEEDED(hr))
{
return;
}
hr = browser->get_Document(&docDisp);
if(!SUCCEEDED(hr))
{
return;
}
hr = docDisp->QueryInterface(IID_IHTMLDocument3, (void**)&doc3);
if(!SUCCEEDED(hr))
{
return;
}
hr = docDisp->QueryInterface(IID_IHTMLDocument, (void**)&doc);
hr = docDisp->QueryInterface(IID_IHTMLDocument2, (void**)&doc2);
if(!SUCCEEDED(hr))
{
return;
}
else
{
hr = doc2->get_parentWindow(&win2);
if(!SUCCEEDED(hr))
{
return;
}
hr = doc1->get_Script(&script);
if(SUCCEEDED(hr))
{
return;
}
}
Both the get_parentWindow and get_Script return an error, e_NOINTERFACE, the
other methods all return OK, what am I dong wrong?
thanks