In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to use java embedded activeX controls". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use java embedded activeX controls.
Here SWT/JFace is used to develop the org.eclipse.swt.ole.win32 package that comes with SWT in application to support embedded OLE and ActiveX.
The specific usage is as follows:
/ / create a framework with OleFrame as OLE (or ActiveX)
OleFrame oleFrame = new OleFrame (this, SWT.NONE)
/ / create a container for ActiveX, where classID is the classid of ActiveX, which can be found in the registry
OleControlSite oleControl = new OleControlSite (oleFrame, SWT.NONE, "classID")
/ / the OleAutomation class is used to execute methods in ActiveX.
OleAutomation oleAutomation = new OleAutomation (oleControl)
/ / display ActiveX in application
OleControl.doVerb (OLE.OLEIVERB_SHOW)
The specific process of calling a method in AcitveX:
1. Method calls without parameters
/ / get the ID,Method Name of Method Name as the specific method name in ActiveX
Int [] regspid = oleAutomation.getIDsOfNames (new String [] {"MethodName"})
Int dispIdMember = regspid [0]
/ / method call
OleAutomation.invoke (dispIdMember)
2. Method call with parameters
/ / get the ID,Method Name of Method Name as the specific method name in ActiveX
Int [] regspid = oleAutomation.getIDsOfNames (new String [] {"MethodName"})
Int dispIdMember = regspid [0]
/ / set the specific parameters of the method. The length of the Variant array is the number of MethodName method parameters
/ / suppose there are four parameters
Variant [] rgvarg = new Variant [4]
Rgvarg [0] = new Variant (fileID)
Rgvarg [1] = new Variant (itdsURL)
Rgvarg [2] = new Variant (idType)
Rgvarg [3] = new Variant (reportURL)
/ / method call
OleAutomation.invoke (dispIdMember, rgvarg)
Call OLE Exemple:Java program embedded Word application program
Package test.swt
Import java.io.File
Import org.eclipse.swt.SWT
Import org.eclipse.swt.graphics.Point
Import org.eclipse.swt.layout.GridData
Import org.eclipse.swt.layout.GridLayout
Import org.eclipse.swt.ole.win32.OLE
Import org.eclipse.swt.ole.win32.OleClientSite
Import org.eclipse.swt.ole.win32.OleFrame
Import org.eclipse.swt.widgets.Button
Import org.eclipse.swt.widgets.Display
Import org.eclipse.swt.widgets.Shell
Import org.eclipse.swt.widgets.Composite
Public class ActiveXTest
{
Private Shell sShell = null
Private Button button = null
Private OleClientSite clientSite
Public static void main (String [] args)
{
Display display = Display.getDefault ()
ActiveXTest thisClass = new ActiveXTest ()
ThisClass.createSShell ()
ThisClass.sShell.open ()
While (! thisClass.sShell.isDisposed ()
{
If (! display.readAndDispatch ()
Display.sleep ()
}
Display.dispose ()
}
/ * *
* This method initializes sShell
, /
Private void createSShell ()
{
GridData gridData = new GridData ()
GridData.horizontalSpan = 2
GridLayout gridLayout = new GridLayout ()
GridLayout.numColumns = 3
SShell = new Shell ()
SShell.setText ("Shell")
SShell.setLayout (gridLayout)
SShell.setSize (new Point (800600))
OleFrame frame = new OleFrame (sShell, SWT.NONE)
Button = new Button (sShell, SWT.NONE)
Button.setLayoutData (gridData)
Button.setText ("Save")
Button.addSelectionListener (new org.eclipse.swt.events.SelectionAdapter () {
Public void widgetSelected (org.eclipse.swt.events.SelectionEvent e)
{
ClientSite.save (new File ("d:/test.docx"), true)
}
});
Frame.setSize (800600)
ClientSite = new OleClientSite (frame, SWT.NONE, "Word.Document.8")
ClientSite.setSize (400400)
ClientSite.doVerb (OLE.OLEIVERB_SHOW)
}
}
Simple summary of SWT calling ActiveX
Public class SWT_ActivexUtil {
Private OleFrame _ frame
Private OleControlSite _ site
Private OleAutomation _ auto
SWT_ActivexUtil (String activexId, OleControlSite site) {
If (site = = null) {
Shell shell = new Shell ()
_ frame = new OleFrame (shell, SWT.NONE)
_ site = new OleControlSite (_ frame, SWT.NONE, activexId)
_ auto = new OleAutomation (_ site)
} else {
_ site = site
_ auto = new OleAutomation (site)
}
}
Public int getID (String name) {
Try {
Int [] ids = _ auto.getIDsOfNames (new String [] {name})
If (ids.length > = 0)
Return ids [0]
} catch (RuntimeException e) {
E.printStackTrace ()
}
Return-1
}
Public Variant [] createVariants (String [] paras) {
Variant [] vr = new Variant [paras.length]
For (int iTuno Bandi)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.