資源簡介
主要涵蓋jacob調用ocx控件的方法以及事件的源碼demo,同時還有html頁面中通過js調用ocx控件的代碼示例,并附帶自己開發的ocx控件,運行時需要注意先注冊控件,并且配置好jacob安裝包。

代碼片段和文件信息
package?main;
import?com.jacob.activeX.ActiveXComponent;
import?com.jacob.com.ComThread;
import?com.jacob.com.Dispatch;
import?com.jacob.com.DispatchEvents;
import?com.jacob.com.Variant;
import?com.jacob.test.baseTestCase;
public?class?MyOcxTest?extends?baseTestCase?{
/**
?*?The?actual?work?of?running?the?test.
?*?
?*?@param?waitForQuit
?*?@param?urls
?*/
public?void?runTheTest()?{
//?this?line?starts?the?pump?but?it?runs?fine?without?it
ComThread.startMainSTA();
//?Run?the?test?in?a?thread.?Lets?us?test?running?out?of?“main“?thread
IETestThread?aThread?=?new?IETestThread();
aThread.start();
while?(aThread.isAlive())?{
try?{
Thread.sleep(250);
}?catch?(InterruptedException?e)?{
//?done?with?the?sleep
}
}
ComThread.quitMainSTA();
System.out.println(“Main:?did?quit?main?sta?in?thread?“
+?Thread.currentThread().getName());
if?(aThread.threadFailedWithException?!=?null)?{
aThread.threadFailedWithException.printStackTrace();
fail(“caught?an?unexpected?exception?“
+?aThread.threadFailedWithException);
}
}
}
class?IETestThread?extends?Thread?{
/**?flag?that?says?we?got?a?quit?message?from?IE?*/
public?static?boolean?quitHandled?=?false;
/**
?*?determines?if?we?wait?until?last?quit?call?back?received?before
?*?terminating
?*/
private?static?boolean?waitUntilReceivedQuitCallback?=?true;
/**
?*?the?places?we?should?navigate?to
?*/
private?static?String[]?targets?=?null;
/**
?*?holds?any?caught?exception?so?the?main/test?case?can?see?them
?*/
public?Throwable?threadFailedWithException?=?null;
/**
?*?constructor?for?the?test?thread
?*?
?*?@param?beNeat
?*????????????should?we?wait?until?quit?received
?*?@param?urls
?*????????????the?web?pages?we?will?navigate?to
?*/
public?IETestThread()?{
super();
}
/**
?*?Run?through?the?addresses?passed?in?via?the?constructor
?*/
@Override
public?void?run()?{
//?pick?a?time?that?lets?sourceforge?respond?(in?msec)
int?delay?=?3000;
//?pre-1.14?paired?with?statement?below?that?blows?up
ComThread.InitMTA();
ActiveXComponent?ie?=?new?ActiveXComponent(
“DEMO.DemoCtrl.1“);
try?{
MyOcxEvents?ieE?=?new?MyOcxEvents();
new?DispatchEvents(ie?ieE?“DEMO.DemoCtrl.1“);
System.out.println(“MyOcxEvents?:?Did?hookup?event?listener“);
????Dispatch.call(ie?“Hello“?“HelloActiveX!“);
}?catch?(Exception?e)?{
threadFailedWithException?=?e;
e.printStackTrace();
}?catch?(Throwable?re)?{
threadFailedWithException?=?re;
re.printStackTrace();
}?finally?{
System.out.println(“IETestThread:?Did?send?Quit“);
}
//?a?value?is?set?to?false?if?we?try?to?crash?VM?by?leaving?before
//?callbacks?all?received
if?(waitUntilReceivedQuitCallback)?{
System.out.println(“IETestThread:?Waiting?until?we‘ve?received?quit?callback“);
//?wait?a?little?while?for?it?to?end
while?(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????129536??2018-07-16?14:24??jacob-js調用ocx\Demo.ocx
?????文件???????1129??2018-07-16?14:26??jacob-js調用ocx\index.html
?????文件???????4162??2018-07-16?14:33??jacob-js調用ocx\MyOcxTest.java
?????文件????????297??2018-07-16?11:43??jacob-js調用ocx\MyTest.java
?????目錄??????????0??2018-07-16?17:07??jacob-js調用ocx
-----------?---------??----------?-----??----
???????????????135124????????????????????5
評論
共有 條評論