Re: interacting with another program


#1

To summarize:

  1. Read data from another program by ruby program
  2. Data analysis by ruby program
  3. action perform in the other program by ruby program

As far as I understand you want to interact with Win32 GUI application.
Try to use Windows messages to get data and perform actions on its GUI
controls (text area, buttons).

All you need is:

  1. Find the program window (== get it’s handle) by title
  2. Find the GUI control you want to work with (== get it’s handle)
  3. Send message to this control (for example - to get text from text box
    you need something like WM_GETTEXT message (see MSDN for details), to
    push a button WM_LBUTTONDOWN,…)

For step 1, 2 I cannot remember Win API functions by name, but you
shouldn’t have any problems finding one (See MSDN, section about Window
functions).

It’s very brief explanation. If you have more specific question - feel
free to ask.


#2

If you use Windows as an OS to perform the interaction
with another program, you might have a look at AutoIt and how to use
it from Ruby:

www.rubygarden.org/ruby?AutoIt_For_Windows

Best regards,

Axel


#3

Alexey K. wrote:

All you need is:

  1. Find the program window (== get it’s handle) by title
  2. Find the GUI control you want to work with (== get it’s handle)
  3. Send message to this control (for example - to get text from text box
    you need something like WM_GETTEXT message (see MSDN for details), to
    push a button WM_LBUTTONDOWN,…)

For step 1, 2 I cannot remember Win API functions by name, but you
shouldn’t have any problems finding one (See MSDN, section about Window
functions).

It’s very brief explanation. If you have more specific question - feel
free to ask.

This should be the function to find the window handle:
http://msdn2.microsoft.com/en-us/library/ms633499.aspx
For this I also need the name of the class, but I have installed a tool
that can show me that.

I couldn’t find a function on MSDN to find a controls handle, so I’m
kinda stuck on this one. Please help me out here.

To push a button I’ll need
BM_CLICK(http://msdn2.microsoft.com/en-us/library/ms673557.aspx)?

For textfield i want to get the text from, I think I have to use
EM_GETTEXTEX (http://msdn2.microsoft.com/en-us/library/ms652050.aspx)
right?


#4

Jeppe J. wrote:

To push a button I’ll need
BM_CLICK(http://msdn2.microsoft.com/en-us/library/ms673557.aspx)?

For textfield i want to get the text from, I think I have to use
EM_GETTEXTEX (http://msdn2.microsoft.com/en-us/library/ms652050.aspx)
right?

I believe this should solve most of your problems.
http://raa.ruby-lang.org/project/win32-guitest/
Hope it helps.
Regards,
Manish


#5

Manish S. wrote:

Jeppe J. wrote:

To push a button I’ll need
BM_CLICK(http://msdn2.microsoft.com/en-us/library/ms673557.aspx)?

For textfield i want to get the text from, I think I have to use
EM_GETTEXTEX (http://msdn2.microsoft.com/en-us/library/ms652050.aspx)
right?

I believe this should solve most of your problems.
http://raa.ruby-lang.org/project/win32-guitest/
Hope it helps.
Regards,
Manish

Thanks

I’ve actually looked a bit into autoit for ruby and it solved most of my
problems, but maybe this will come in handy if I have any trouble with
autoit.

My biggest problem right now is that the program I want to automate is
using some web based elements, which means that there is some text I
cant seem to get from the program. I’m considering using some kind of
screenscrape to regonize the text I need, if such solution is available
(or even nessecary).