I'm trying to use the Java Access Bridge to get information about Swing components from inside a C++ app. However, none of the callbacks I register ever get called. I tried enuming the windows an then calling IsJavaWindow() on each handle, but it always returns false. Any ideas on why it apparently is not working?
I presume it's a problem with my app rather than the bridge installation because the demo Monkey and Ferret programs work, initializeAccessBridge() returns true, and the debugger reveals that the WindowsAccessBridge dll is loaded.
I'm using Java 6, update 13 on Windows Vista and I think version 2.0.1 of the access bridge.
JavaAccess::JavaAccess(void)
{
using namespace std;
BOOL isInitialized = initializeAccessBridge();
if(isInitialized)
{
cout << "Bridge Initialized!" << endl;
}
else
{
cout << "Initialization failed!" << endl;
return;
}
EnumWindows((WNDENUMPROC)EnumWndProc, NULL);
SetJavaShutdown(OnJavaShutdown);
SetFocusGained(OnFocusGained);
SetMouseClicked(OnMouseClicked);
}
JavaAccess::~JavaAccess(void)
{
shutdownAccessBridge();
}
void JavaAccess::OnJavaShutdown( long vmID )
{
using namespace std;
cout << "Java shutdown!" << endl;
}
void JavaAccess::OnFocusGained( long vmID, FocusEvent event, AccessibleContext context )
{
using namespace std;
cout << "Focus Gained!" << endl;
ReleaseJavaObject(vmID, event);
ReleaseJavaObject(vmID, context);
}
void JavaAccess::OnMouseClicked( long vmID, jobject event, jobject source )
{
std::cout << "Mouse clicked!" << std::endl;
ReleaseJavaObject(vmID, event);
ReleaseJavaObject(vmID, source);
}
BOOL CALLBACK JavaAccess::EnumWndProc( HWND hwnd, LPARAM lparam )
{
if (IsJavaWindow(hwnd))
{
std::cout << "Found Java Window!" << std::endl;
return FALSE;
}
else
{
std::cout << "Still looking" << std::endl;
return TRUE;
}
}
All of the callbacks are static functions.