How to pass the events and values from ocx to html or JSP
Hi,
I developed activex control using MFC activex control wizard. i need to pass events and values from activex control (ocx) to html page or JSP. Any options available
in MFC activex control wizard to pass those events and values?
Could anyone point out what I have to do next?
Thanks in Advance
Regards
Jaiganesh
Re: How to pass the events and values from ocx to html or JSP
It doesn't matter what framework you use to implement ActiveX - the basics for AcitiveX-to-html interaction stay the same.
Passing values between ActiveX and html is always made by means of properties defined in ActiveX.
To firing events outside of ActiveX there should be source interface (events) defined in ActiveX, a connection point mechanism should be implemented incorporating these events - and html code should be aware of ActiveX events by means of <SCRIPT ID="SomeID" FOR="AxObjectInstanceName" EVENT="AxEventEntry()">...</SCRIPT> fragments as many as many events you whish to process.
Re: How to pass the events and values from ocx to html or JSP
Ok, the sample.
Component is built as MFC control. Wizard adds source interface and connection points support by default. We have to add events to control class (right-click in class view and select Add Event... in context menu) and provide some way to fire them. Since our component absolutely dumb we'll make synchronous event firing - Test1 event will be fired on RunTest1 method (of default dispinterface) call, Test2 event will be fired on setting component's OutName property.
As I previously said HTML page (Test.htm) includes two <script> entries - for each event of the single object instance. RunTest1 method is called by correspondent button click, another button been clicked sets the OutName property value equal to editbox text.
Re: How to pass the events and values from ocx to html or JSP
Another sample. Now we have ActiveX control which have child dialog with edit box and button. Text input from edit is fired to HTML page by button click. This is another way to pass some value to container - to implement event with parameter. But previous mechanism (where event with no parameter serves for notification purpose only, but data are passed through properties) stays suitable too (but not implemented in this sample - see previous one).
Last edited by Igor Vartanov; July 27th, 2005 at 06:20 AM.
Re: How to pass the events and values from ocx to html or JSP
I was asked for a kind of step-by-step tutorial for last sample.
Let's see how it could be implemented in VC++6.
1. Run MFC ActiveX ControlWizard for AxMfcTest2 project
at first screen change nothing and press Next
unselect Has an "About" box
select Available in "Insert Object" dialog
press Finish (since we're going to implement control with child dialog there will none of window classes subclassed)
press OK
2. Add event to control class
At ClassView tab select _DAxMfcTest2Events interface with right click and select Add Event... in context menu
in Add Event dialog put string "SetText" to External Name field and in Parameter list add parameter szText of BSTR* type.
press OK
Now we have:
eventidSetText = 1 added to enum{}
void FireSetText(BSTR FAR* szText) protected method added to class CAxMfcTest2Ctl
EVENT_CUSTOM("SetText", FireSetText, VTS_PBSTR) entry added to event map of the class
3. Add child dialog resource to project:
add dialog resource, rename it to IDD_MYCTRL
delete all controls set by default and add static, edit box (IDC_TEXT) and button (IDC_SETTEXT)
tune dialog resource settings:
- style -> Child
- border -> None
- check Control
- check Control parent
4. Generate dialog class for child dialog:
in resource editor right-click dialog resource and select Class Wizard
push OK on Create a new class proposal - New Class wizard dialog should appear with Base Class field set to CDialog and Dialog ID field set to IDD_MYCTRL
put CMyCtrlDlg class name and press OK
in class wizard dialog select IDC_SETTEXT object ID and doubleclick BN_CLICKED message to generate OnSettext() method
close wizard dialog with OK
add #include "AxMfcTest2Ctl.h" to MyCtrlDlg.cpp includes
add handler code to Settext() (see sources)
Code:
// MyCtrlDlg.cpp
void CMyCtrlDlg::OnSettext()
{
// TODO: Add your control notification handler code here
CString szText;
GetDlgItemText( IDC_TEXT, szText );
CAxMfcTest2Ctrl* pctrl = (CAxMfcTest2Ctrl*)GetParent();
pctrl->SetText(szText);
}
5. Tie together dialog and control classes:
Note: You can see call for non-existent method SetText(CString szText) in code of handler, so we have to add this method to control class to provide event firing with string passed to it
add void SetText(CString szText) to control class (see sources)
Re: How to pass the events and values from ocx to html or JSP
Now we will add to our MFC ActiveX ability to report its safety.
To make it seemed safe for browser we have to implement two category registration for our control. These categories are CATID_SafeForInitializing and CATID_SafeForScripting.
For this purpose we have to add to our AxMfcTest2 project the AxMfcTest2CtrlCatReg.cpp file (see attachment) and ensure its RegisterControlAsSafe and UnregisterControlAsSafe functions to be called on ActiveX registration and unregistration respectively.
BTW, you may be surprised with such code in AxMfcTest2CtrlCatReg.cpp:
Re: How to pass the events and values from ocx to html or JSP
Hi Igor,
I am a java guy, looking for a quick solution for a small component i need. Your code (AxMfcTest2) helped me a lot.
Just for one quick change, i need exact same exept in opposite. I mean i want to set text when a button(i mean <input type="button"...) clicked on html. I want to pass text from html text box to activex text button when html button is clicked.
Re: How to pass the events and values from ocx to html or JSP
Originally Posted by zxmn50
Hi Igor,
I am a java guy, looking for a quick solution for a small component i need. Your code (AxMfcTest2) helped me a lot.
Just for one quick change, i need exact same exept in opposite. I mean i want to set text when a button(i mean <input type="button"...) clicked on html. I want to pass text from html text box to activex text button when html button is clicked.
I appreciate if anyone tells me how to do it.
Thanks,
John
If ActiveX button has Caption property just set it to value you need
or other way you can use some default interface method for this:
Re: How to pass the events and values from ocx to html or JSP
Igor,
Please don't mind. I didn't understand what you said because i don't know vc++. Could you explain little more details or sample code would help.
I have text box and button in html. I have text box in activesx control. When we click button on html, text should pass from html text box to activex control text box.
Thanks so much for your help, i have been searching and trying to read about mfc activex controls, it's just been taking long time.
Re: How to pass the events and values from ocx to html or JSP
Originally Posted by zxmn50
Please don't mind. I didn't understand what you said because i don't know vc++. Could you explain little more details or sample code would help.
My reply was in HTML, not C++.
I have text box and button in html. I have text box in activesx control. When we click button on html, text should pass from html text box to activex control text box.
Now your description looks more clear.
You have to think in object categories. Your button and ActiveX dialog are objects of some HTML page. The button press will fire its onClick handler. There you can call the method of ActiveX dialog object passing him the string what you want. This method will set the dialog's edit text with the string you passed. If you implement the ActiveX acording to my sample, you have to know its dialog is just a Windows object having no interface to outer world, I mean it has no communication abilities to HTML's virtual machine except the abilities given to him by the ActiveX control which wraps the dialog. So, to make the string from HTML be able to reach the dialog you have to have the method in ActiveX which will receive the string, access the internal dialog object and instruct it to set the edit text.
You have to add the method to ActiveX (that addition detailed actions will depend on VisualStudio version), say SetEditText(BSTR text).
Re: How to pass the events and values from ocx to html or JSP
hi Igor,
Thanks for reply, i was in offline for past 3 days.
Sorry to bug you again. Yes, yyou understood my problem, but i was not sure where to add the additional method you mentioned.
I tried to do the way you said, but it didn't work. surely, i am missing something.
I attached sameple project from vc++ 2005, its basically same code from you, with little modifications.
The purpose of control i am doing is to show a baloon from html. The message has to come from html.
AcitveX control has a text box, and one button.
Html page has one text box and a button. When user clicks on html button, Text from Html text box needs to pass to Activex control text box and when user clicks on activex control button it has to show baloon in tray icon.
Right now activex control is working itself. the problem only i have is passing text from html textbox to activex textbox.
Please check page1.html file to test.
Thanks for your help, please suggest where to write that additional method to accept html text.
Re: How to pass the events and values from ocx to html or JSP
Wonderful, Thanks Igor. I made few changes to send more parameters, and more functionality. It’s all working fine now.
I spent lot of time trying to learn c++ mfc, discovered lot of things.
One last question, how do i convert this activex using from shared DLLs to use Static libraries. I don't want this activex to have dependency on client machine.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.