BobFishel has asked for the wisdom of the Perl Monks concerning the following question:

Wise and Venerable Monks: Using Win32::ole (or really any module) is it possible to interact with windows of other programs?

Say for example that I know program X will be running, I'd like to populate a field in that window then 'click' a button. This will generate some text in a list box in yet a third window which I want to read and do some manipulations on.

1. Is this possible and how would I go about doing it?

2. If it is possible, how do I get the windows handles to interact with them?

Thank you monks, I will patiently await your replys! Thanks for the help!
  • Comment on Win32: Can I interact with windows I didn't create?

Replies are listed 'Best First'.
Re: Win32: Can I interact with windows I didn't create?
by Corion (Patriarch) on Jan 16, 2009 at 16:36 UTC

    This is not the domain of Win32::OLE, as generic "windows" do not have any OLE interface. You seem to want Win32::GuiTest, which has the functions to find window handles and also to send clicks and keystrokes to it.

      Is there any way to tell whether a foreign application has an ole interface?

        Look in its documentation.

Re: Win32: Can I interact with windows I didn't create?
by CountZero (Bishop) on Jan 16, 2009 at 17:40 UTC
    The docs of Win32::GUI say as follows:
    Non-owned windows

    Every window, even windows not created by your Perl script, can be referenced by Win32::GUI; all you need to know is its "handle", a numerical value that identifies that window. Many functions in the Win32::GUI package return such handles, as for example:

    $First = Win32::GUI::GetForegroundWindow();
    This value can then be passed to any function that requires a window object; but of course, not being an object, you can't call it as a method:
    Win32::GUI::Hide($First); # correct $First->Hide(); # wrong
    Should you need to know the numerical handle of a window created by Win32::GUI, it is stored in its -handle key (this is the value that almost all function really use):
    print "Window handle is $Window->{-handle} \n";

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      I've been searching for a way to detect a window if it is under the mousecursor but I haven't found a way.. any ideas?
Re: Win32: Can I interact with windows I didn't create?
by marto (Cardinal) on Jan 16, 2009 at 16:36 UTC

    Perhaps Win32::GuiTest and its FindWindowLike function can help you with this.

    Hope this helps

    Martin