Forum: Ruby Re: interacting with another program

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alexey K. (Guest)
on 2007-05-28 12:27
(Received via mailing list)
> 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.
Axel E. (Guest)
on 2007-05-28 12:52
(Received via mailing list)
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
Jeppe J. (Guest)
on 2007-05-28 20:17
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.


1)
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.

2)
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.

3)
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?
Manish S. (Guest)
on 2007-05-30 06:59
(Received via mailing list)
Jeppe J. wrote:
> 3)
> 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
Jeppe J. (Guest)
on 2007-05-30 08:30
Manish S. wrote:
> Jeppe J. wrote:
>> 3)
>> 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).
This topic is locked and can not be replied to.