Page 1 of 1

[Solved] Get the Window Handle of a document ?

PostPosted: Wed Aug 24, 2011 10:49 am
by bcris
Could anybody help me with the java calls needed to find out the window handle of a document, starting from an XSpreadsheetDocument object ?

I use Open Office 3.3 on Windows XP SP3 and Java 1.6.0_26.

Thanks in advance !

Re: Get the Window Handle of a document ?

PostPosted: Wed Aug 24, 2011 10:10 pm
by rudolfo
If the Spreadsheet document is loaded in OpenOffice it has a CurrentController property. Which in turn has a ApplicatonMainWindow, ComponentWindow and/or a Frame. Check the UNO API on SpreadsheetDocuments or use a object inspection tool like MRI (can be found amoung the OOo extensions).
In any case though the ComponentWindow and ApplicatonMainWindow are shown as type awt.XWindow they are still UNO objects and not Java Windowing Toolkit objects. So I have my doubts, that they would let you access their window handle.

Re: Get the Window Handle of a document ?

PostPosted: Mon Aug 29, 2011 10:30 am
by bcris
Thank you for your reply !

Here is a possible solution:

Code: Select all   Expand viewCollapse view
        XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
        XController c = model.getCurrentController();
        XFrame frame = c.getFrame();
        XWindow window = frame.getContainerWindow();
        XSystemDependentWindowPeer  xWindowPeer = (XSystemDependentWindowPeer) UnoRuntime.queryInterface(XSystemDependentWindowPeer.class, window);
        int handle = (Integer) xWindowPeer.getWindowHandle("".getBytes(), SystemDependent.SYSTEM_WIN32);


Re: Get the Window Handle of a document ?

PostPosted: Thu Sep 08, 2011 4:02 pm
by bcris
Solved.