[Solved] Get the Window Handle of a document ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
bcris
Posts: 21
Joined: Wed Aug 17, 2011 3:51 pm

[Solved] Get the Window Handle of a document ?

Post 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 !
Last edited by Hagar Delest on Thu Sep 08, 2011 5:32 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.3 on Windows XP SP3
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Get the Window Handle of a document ?

Post 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.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
bcris
Posts: 21
Joined: Wed Aug 17, 2011 3:51 pm

Re: Get the Window Handle of a document ?

Post by bcris »

Thank you for your reply !

Here is a possible solution:

Code: Select all

        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);

OpenOffice 3.3 on Windows XP SP3
bcris
Posts: 21
Joined: Wed Aug 17, 2011 3:51 pm

Re: Get the Window Handle of a document ?

Post by bcris »

Solved.
OpenOffice 3.3 on Windows XP SP3
Post Reply