Paradox Community

Items in pnews.paradox-programming

Subject:Re: Directly Accessing the Contents of a Window.
Date:Sat, 5 Aug 2017 20:23:15 +0200
From:"modridirkac" <jure.zorko@gmail.com>
Newsgroups:pnews.paradox-programming
Not Exactly what you aked for, buit close.
I use something similar to your wish, but for excel.
Did some fast testing, got some results

Look at the main method:
* get PID of notepad.exe
* send some key strokes to that PID
* read from clipboard, what is there

Jure

-------

proc MakeAndRunBAT(cmd string, wait logical, arg smallint)
var TS TextStream
endVar
    TS.Create(fullname(":PRIV:bat.bat"))
   TS.WriteLine(cmd)
   TS.CLose()
   execute(fullname(":PRIV:bat.bat"),wait,arg)
endProc

proc FindPID(nameOfProcess string) longint
; What is PID of given process
var ret longint
     cmd string
     TS TextStream
     AR Array[] String
     line, tmp string
     i smallint
endVar
    cmd = "WMIC /OUTPUT:"+privdir()+"\\PList.txt"+" PROCESS get 
Commandline,Processid"
    MakeAndRunBAT(cmd, true, ExeHidden    )
    ;Convert Unicode to ASCII
    cmd = "TYPE "+privdir()+"\\PList.txt"+" > "+privdir()+"\\PListAscii.txt"
    MakeAndRunBAT(cmd, true, ExeHidden    )

    if not TS.Open(privdir()+"\\PListAscii.txt","r") then return(-1) endIf
    TS.ReadLine(AR)
    TS.Close()
    delete(privdir()+"\\PList.txt")
    delete(privdir()+"\\PListAscii.txt")

   ; if there are too few lines, something went wrong
   if AR.Size() < 10 then return(-1) endIf

    nameOfProcess = lower(nameOfProcess)
    ret = 0
    for i from 1 to AR.Size()
        line = lower(rtrim(AR[i]))
        if not line.match(".."+nameOfProcess+"..") then loop endIf
        ; match, find out PID  (last 5 chars)
        tmp = line.SubStr(line.size()-4,5)
        try
            ret = longint(tmp)
      onFail
          ret=0
      endTry
   endFor
   return(ret)
endProc

proc SendKeysToProc(PID LongInt)
var TS TextStream
     cmd string
endVar
   ; create VBS script
   TS.Create(fullname(":PRIV:run.vbs"))
   TS.WriteLine("Set objShell = WScript.CreateObject(\"WScript.Shell\")")
   TS.WriteLine("objShell.AppActivate ("+string(PID)+")")
   TS.WriteLine("WScript.Sleep 1000")
   TS.WriteLine("objShell.SendKeys \"^a\"")
   TS.WriteLine("objShell.SendKeys \"^c\"")
   TS.WriteLine("WScript.Sleep 2000")
    TS.CLose()
    cmd = fullname(":PRIV:run.vbs")
    MakeAndRunBAT(cmd ,true, ExeHidden)
endProc


method run(var eventInfo Event)
var name string
     PID LongInt
    clip string
endVar
    name = "notepad.exe"
    PID = FindPID(name)
   ; nov send CTRA+A CTRL+C
   SendKeysToProc(PID)

   sleep()
   sleep(1000)

   clip.readFromclipboard()

   view(clip)
endMethod 


Copyright © 2004 thedbcommunity.com