Download source and binary files - 6.9 Kb
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 - Get the HWND of a Java Heavy Weight component.
Problem #2 - How to attach an activex control as a child of the HWND above.
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.
public int getHWND()
int hwnd = 0;
DrawingSurfaceInfo drawingSurfaceInfo = ((DrawingSurface)(getPeer())).getDrawingSurfaceInfo();
if (null != drawingSurfaceInfo)
Win32DrawingSurface win32DrawingSurface = (Win32DrawingSurface)drawingSurfaceInfo.getSurface();
hwnd = win32DrawingSurface.getHWnd();
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.
VOID CreateIEControl(ThreadParam *pThreadParam)
printf("Create AtlAxWin Begin...[0x%x][%s]\n",pThreadParam->hwnd,pThreadParam->szURL);
HWND hwndChild = ::CreateWindow("AtlAxWin",
IUnknown *pUnk = NULL;
printf("Create AtlAxWin Done...[0x%x]\n",pUnk);
#pragma warning(disable: 4310) // cast truncates constant value
#pragma warning(default: 4310) // cast truncates constant value
spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve);
To Build the Project edit and use Build.BAT present in the downloadable Zip file above.
To run the Java Application, use "java MyWindow http://www.codeproject.com" from the command line.
That's it! Have Fun.