Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Remotely controlling an external application
Message
From
17/04/2003 10:00:32
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Remotely controlling an external application
Miscellaneous
Thread ID:
00778826
Message ID:
00778826
Views:
60
Hello;

I am trying to run an external applicaton and control it by my program..

What´s going wrong down here ? (The keys that I am trying to send to calculator are mixing)
DECLARE Sleep IN Win32API;
    INTEGER dwMilliseconds
DECLARE INTEGER GetActiveWindow ;
    IN Win32API
DECLARE INTEGER GetWindow IN Win32API ;
    INTEGER HWND, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API ;
    INTEGER HWND, STRING @cText, INTEGER nType
DECLARE INTEGER BringWindowToTop IN Win32API ;
    INTEGER HWND
Declare integer SetActiveWindow in user32.dll ;
     integer hwnd
oShell = CREATEOBJECT("WScript.Shell")
nhandler = 0
*oShell.AppActivate("Calculator")
RUN /N CALC.EXE
do  while nhandler = 0
    nhandler = ais_running("Calculator")
enddo
* is running, so activate it
bringwindowtotop(nhandler)
oShell.SendKeys("1")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("+")
= Sleep(200) && Pause VFP for a 1/10 of a second
oShell.SendKeys("2")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("=")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("+")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("3")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("+")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("4")
= Sleep(200) && Pause VFP for a 1/10 of a second 
oShell.SendKeys("=")
return
FUNCTION ais_running
    * check if a given application is running
    LPARAMETER ctitle                       
    *
    hnext = getactivewindow()
    * iterate through the open windows
    DO  WHILE hnext<>0
        ctext = REPLICATE(CHR(0),80)
        getwindowtext(hnext,@ctext,80)         && get window title
        IF  UPPER(ALLTRIM(ctitle)) $ UPPER(ctext)
            *
            RETURN hnext
        ENDIF
        hnext = getwindow(hnext,2)            && next window
    ENDDO
    * required window not found
    RETURN 0
ENDFUNC
TIA

Claudio
"Now to him who is able to do immeasurably more than all we ask or imagine, according to his power that is at work within us, Ephesians 3:20
Next
Reply
Map
View

Click here to load this message in the networking platform