Embed ActiveX controls inside Java GUI
来源:互联网 发布:中国男女收入差距数据 编辑:程序博客网 时间:2024/05/21 10:03
From: http://www.codeproject.com/java/javacom.asp
Introduction
This article provides a skeleton for embedding ActiveX controls within your Java Applications. The sample project shows how to embed the Internet Explorer 5.0 just like any other Java Widget.
There are two major problems that needed to be solved to be able to do this.
Problem #1 was solved by an undocumented API present in all versions of JDK's from Sun, for example JDK 1.1.8, JDK 1.2.2 and JDK 1.3. Here's the URL which explains how to get the HWND of a java.awt.Canvas object and an extract from the project which shows the implementation.
http://www.jguru.com/jguru/faq/view.jsp?EID=44507
// Returns the HWND for panel. This is a hack which works with// JDK1.1.8, JDK1.2.2 and JDK1.3. This is undocumented. Also // you should call this only after addNotify has been called.public int getHWND() { int hwnd = 0; DrawingSurfaceInfo drawingSurfaceInfo = ((DrawingSurface)(getPeer())).getDrawingSurfaceInfo(); if (null != drawingSurfaceInfo) { drawingSurfaceInfo.lock(); Win32DrawingSurface win32DrawingSurface = (Win32DrawingSurface)drawingSurfaceInfo.getSurface(); hwnd = win32DrawingSurface.getHWnd(); drawingSurfaceInfo.unlock(); } return hwnd;}
Problem #2 was a bit more complicated but MSDN's Online KB was of great help in solving this. Here's the URL which explains how to add an ActiveX control as a child of any HWND using ATL and an extract from the project which shows how the concept is implemented.
http://support.microsoft.com/support/kb/articles/Q192/5/60.ASP
// Creates IE controlVOID CreateIEControl(ThreadParam *pThreadParam){ AtlAxWinInit(); printf("Create AtlAxWin Begin...[0x%x][%s]/n",pThreadParam->hwnd,pThreadParam->szURL); // In the 2nd Param you can use ProgID or UUID of any activex control. HWND hwndChild = ::CreateWindow("AtlAxWin", "Shell.Explorer.1", WS_CHILD|WS_VISIBLE, 0,0,0,0, pThreadParam->hwnd,NULL, ::GetModuleHandle(NULL), NULL); IUnknown *pUnk = NULL; AtlAxGetControl(hwndChild,&pUnk); printf("Create AtlAxWin Done...[0x%x]/n",pUnk); // get an interface to set the URL. CComPtrTo Build the Project edit and use Build.BAT present in the downloadable Zip file above.spBrowser; pUnk->QueryInterface(IID_IWebBrowser2, (void**)&spBrowser); if (spBrowser) { CComVariant ve; CComVariant vurl(pThreadParam->szURL);#pragma warning(disable: 4310) // cast truncates constant value spBrowser->put_Visible(VARIANT_TRUE);#pragma warning(default: 4310) // cast truncates constant value spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve); }}
To run the Java Application, use "java MyWindow http://www.codeproject.com" from the command line.
That's it! Have Fun.
Davanum Srinivas
Other popular Java Programming articles:
- Executing commands on a remote machine - Part 1 A simple tool that allows you to control other machines from your program
- SOCKS Proxy + SSL Tunnel A full featured SOCKS 4 & 5 proxy server written in Java.
- Talk2Me: Java instant messenger A near to perfect clone of the very popular Yahoo messenger. Purely written in Java and SWING, this messenger also uses the capabilities of JNI and JAWT to provide some features.
- Add Mouse Wheel support to Swing Widgets This article shows how to add support for Mouse Wheel for Java Swing Widgets
- Embed ActiveX controls inside Java GUI
- ActiveX Controls
- Licensing ActiveX Controls
- Packaging ActiveX Controls
- component&Activex controls
- Security of ActiveX Controls
- Forms Controls and ActiveX Controls in Excel
- Using ActiveX Controls with MFC
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- Inside ASP.NET 2.0 – Controls Model
- vb.net中控件事件调用的问题??
- 如何查看SQL2000当前版本号的2个方法和各个版本说明
- Linux内核Makefile浅析
- 未来最庞大的网络用户群是农民
- Duff's Device
- Embed ActiveX controls inside Java GUI
- 函数内 声明一个字符数组和一个指向字符串数组的指针 区别
- Integrating Java and ActiveX
- Creating MTS ActiveX Object in Java
- 用书名加 光盘下载
- Lucene.net中文分词探究
- 合
- Spring配置从jndi获得DataSource
- Lucene中文分词