CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2001
    Posts
    113

    Enumerate child windows

    Hi -

    I'm a Win32 C++ developer, not sure how to do this one.

    The point of my question is to auto-fill in a simple form written in Java.

    I have a Java app, similar to the simple example below. On my Win32 patform, I can use a combination of FindWindow() and EnumChildWindows() to find a top-level window and enumerate its child windows. If the top-level window is a non-Java app, this is pretty simple. But I'm having problems with this Java app.

    When I use the Spy++ tool, I can find the top-level window (which it reports is of class SunAwtFrame), but it cannot enumerate any child windows.

    All I want is to be able to get the handle to the two text fields and stuff them with text.

    My auto-fill app must run separate from the Java App.

    Any ideas? I've searched the web for a good part of the morning and have been unable to find help.

    Thanks for your time,
    lizard43


    import java.awt.*;
    import javax.swing.*;

    public class SimpleTest extends JFrame
    {
    public SimpleTest()
    {
    setSize(WIDTH, HEIGHT);
    JTextField Name = new JTextField("name", 20);
    JTextField Name2 = new JTextField("name2", 20);
    getContentPane().add(Name, BorderLayout.NORTH);
    getContentPane().add(Name2, BorderLayout.SOUTH);

    }

    public static final int WIDTH = 100;
    public static final int HEIGHT = 100;

    public static void main(String[] args)
    {
    SimpleTest frame = new SimpleTest();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.show();
    }
    }






  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Find all open windows via Java

    If you can get a list of references to all the Java windows that are open and running, then there are Swing methods to get all the components that are in one of those windows.
    But if you are asking: How to get a list of references to all the Java windows that are open? I dont' think there is any way. Too OS specific.
    And even if you could get a reference to a window, the fields might be private and not allow access.

    The Robot class is the only one I've seen that comes close to what you want to do. But its write-only. Ie you can position the cursor and enter text, but you can't see what you are doing.

    Norm
    Norm

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Enumerate child windows

    Java programs typically run in their own JVM, so if your auto-fill application is run independently, it won't have direct access to your main program, but will need to use an indirect technique, e.g. RMI (Remote Method Invocation). You haven't explained the reasons behind your design (why is a separate program required to fill the form?) So it might be worth considering alternatives...

    Dave

    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Dec 2007
    Posts
    3

    Re: Enumerate child windows

    The java.awt.Window class has several method that may be useful:

    static Window[] getWindows() - Returns an array of all Windows, both owned and ownerless

    static Window[] getOwnerlessWindows() - Returns an array of all Windows created by this application that have no owner.

    Window getOwner() - Returns the owner of this window.

    Window[] getOwnedWindows() - Returns an array containing all the windows this window currently owns.

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Enumerate child windows

    Er, remkop, that thread is nearly 6 years old - even if the poster didn't find an answer, it won't matter now

    Furious activity is no substitute for understanding...
    H.H. Williams
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    Dec 2007
    Posts
    3

    Re: Enumerate child windows

    dlorde, you're right of course.
    It's just that I did a search for "enumerate Java windows", and this thread was the first relevant link, but I couldn't find what I was looking for. So after finding the answer in the javadocs I just added the info to save future searchers some trouble. I realise it looks a bit silly, sorry about that.

  7. #7
    Join Date
    Jul 2012
    Posts
    1

    Re: Enumerate child windows

    Remkop,

    I am agree with you.. your small inputs can save lots of search..and hours..

    Thanks for posting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured