| Problem with OLE control [message #373045] |
Fri, 29 August 2003 11:08  |
Eclipse User |
|
|
|
Originally posted by: xiecai.yahoo.com
I am newbie with SWT, after reading some article in eclipse.org, I try to
write something to call IE browser using OLE, I got problem: the IE window
doesn't work well. I post my code below, please help me check out the
error point.
thanks!
////////////////////////////////
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.ole.win32.*;
import org.eclipse.swt.internal.ole.win32.*;
public class BrowserTest {
static OleControlSite controlSite;
static OleAutomation webBrowser;
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
Button btn = new Button(shell, SWT.PUSH);
btn.setText("Open IE browser...");
btn.pack();
btn.setLocation(10,10);
btn.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Shell browser = new Shell(shell, SWT.NONE);
//browser.open();
try{
OleFrame frame = new OleFrame(browser, SWT.NONE);
controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
controlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
}catch(SWTError se){
System.out.println("Unable to open activeX control");
return;
}
browser.open();
webBrowser = new OleAutomation(controlSite);
int[] ids = webBrowser.getIDsOfNames(new String[]{"Navigate", "URL"});
Variant[] rgvarg = new Variant[] {new
Variant("http://www.google.com")};
int[] rgdispidNamedArgs = new int[]{ids[1]};
webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
webBrowser.dispose();
display.dispose();
}
}
|
|
|
|
| Re: Problem with OLE control [message #373050 is a reply to message #373047] |
Fri, 29 August 2003 14:02  |
Eclipse User |
|
|
|
Originally posted by: xiecai.yahoo.com
Hi asra,
It works,it works.
Thanks
asra wrote:
> Hi Aquarius!
> It is only enough to put a FillLayout at your browser .
> .......
> Shell browser = new Shell(shell, SWT.NONE);
> browser.setLayout(new FillLayout());
> ......
> Asra.
> "Aquarius" <xiecai@yahoo.com> a écrit dans le message de news:
> binq8g$u4m$1@eclipse.org...
> >
> > I am newbie with SWT, after reading some article in eclipse.org, I try to
> > write something to call IE browser using OLE, I got problem: the IE window
> > doesn't work well. I post my code below, please help me check out the
> > error point.
> >
> > thanks!
> >
> > ////////////////////////////////
> >
> > import org.eclipse.swt.*;
> > import org.eclipse.swt.widgets.*;
> > import org.eclipse.swt.events.*;
> > import org.eclipse.swt.ole.win32.*;
> > import org.eclipse.swt.internal.ole.win32.*;
> >
> > public class BrowserTest {
> > static OleControlSite controlSite;
> > static OleAutomation webBrowser;
> > public static void main(String[] args) {
> > Display display = new Display();
> > final Shell shell = new Shell(display);
> > Button btn = new Button(shell, SWT.PUSH);
> > btn.setText("Open IE browser...");
> > btn.pack();
> > btn.setLocation(10,10);
> > btn.addSelectionListener(new SelectionAdapter(){
> > public void widgetSelected(SelectionEvent e){
> > Shell browser = new Shell(shell, SWT.NONE);
> > //browser.open();
> > try{
> >
> > OleFrame frame = new OleFrame(browser, SWT.NONE);
> > controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer");
> > controlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
> > }catch(SWTError se){
> > System.out.println("Unable to open activeX control");
> > return;
> > }
> > browser.open();
> >
> > webBrowser = new OleAutomation(controlSite);
> > int[] ids = webBrowser.getIDsOfNames(new String[]{"Navigate", "URL"});
> > Variant[] rgvarg = new Variant[] {new
> > Variant("http://www.google.com")};
> > int[] rgdispidNamedArgs = new int[]{ids[1]};
> > webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs);
> >
> > }
> > });
> >
> > shell.open();
> > while (!shell.isDisposed()) {
> > if (!display.readAndDispatch())
> > display.sleep();
> > }
> > webBrowser.dispose();
> > display.dispose();
> >
> > }
> > }
> >
> >
|
|
|
Powered by
FUDForum. Page generated in 0.04398 seconds