This thing I have wanted to write before, but after I write "Make OCX", "MFC Application OCX", the HTML call OCX has been unsuccessful, for a long time, are almost giving up. Yesterday, the leader needed my side. A function that launches an external application through a browser is limited to the company's ignorance of the OCX, and it takes up the task. I knew I had failed before trying, so this time I went into the pit, and I had a long pit, until I had to get off work.
Record the workaround.
First, prepare an OCX that can run normally.
This thing or C + + write more convenient, the previous several have written, not more to repeat.
Two, prepare a registration and uninstall the OCX batch file
Register. Bat
regsvr32 "%~dp0ocx15.ocx"
Uninstalling. bat
regsvr32 "%~dp0ocx15.ocx"-u
Three, prepare a call to OCX HTML file
<HTML><Head><Scripttype= "Text/javascript"language= "JavaScript"> functionShow (string1) {alert ('123'); varobj=document.getElementById ("Testocx"); alert (obj); varret=obj. Startapplication (string1); alert (ret); }</Script></Head><Body><ObjectID= "Testocx"width=""Height=""ClassID= "Clsid:440bf279-30b8-41d2-afe7-f19141110c96"></Object></OBJECT> <inputtype= "button"ID= "BTN1"name= "BTN1"value= "Call ocx"title= "Call ocx"onclick= "Show (' File:///D:/SE-1515/ECGWorkstation.exe.lnk ')"></input></Body></HTML>
Here ClassID must notice, at that time I saw the OCX project in the IDL file uuid There are many, I do not know which, the use of the file is the top of a UUID, the result is because the UUID error, debugging for a long time. The UUID here is best obtained from the registry, taking the following method:
In the run, type regedit into the Registry Editor, click Find in the Edit options,
This is just to find our registered OCX. The 440bf279-30b8-41d2-afe7-f19141110c96 here is the CLSID we want,
At this point, the HTML page is not necessarily able to display this OCX control, need to enable ActiveX in Internet Options, for convenience, I put the item under, all with ActiveX enabled.
At the same time, under Advanced options, remove the 3 checks.
At this time, your HTML page should be able to display the OCX control, of course, you also hide, call OCX should be no problem, HTML call OCX This can only be tried in IE browser, do not ask me why, are Microsoft things.
Four, precautions
1, pay attention to the CLSID must be correct
2, note the settings inside the Internet options.
3, attention must be IE browser.
JAVASCRIPT calls OCX for those pits