Sign in to follow this  
Followers 0
cappy2112

First time calling Autoit from COM

2 posts in this topic

#1 ·  Posted (edited)

I have used autoit from scripts before, now I'm trying thru COM.

Will I be able to access UDF's and beta versions of autoit thru COM?

If so- how do I access them, since they are not in the DLL>

thanks

Edited by cappy2112

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Some interesting ways have been found to do this. See Send Params.

Passing params to an invisible AU3 program and getting data back, also invisibly, is almost as good as using dll calls.

Here's an example with a Delphi program that uses the AutoItX com object to get the color of a random pixel and get the RGB components from an AU3 program that uses the color.au3 function.

The AU3 program, Color1.EXE, opens its GUI off screen, so it is not visible. The #NoTrayIcon means there is no tray icon, obviously, and the $WS_EX_TOOLWINDOW in the GUICreate means it also does not show in the taskbar.

The Delphi program, Test1, writes the color to an editbox in Color1 and pushes a button to tell Color1 that the data is there. Color1 reads it, gets the RGB breakdown and writes it to an editbox in Test1. For demonstration purposes, the editbox also is invisible.

The edit1.onchange event is triggered as soon as Color1 starts to write to the editbox and the event handler deals with the data.

#include <Color.au3>
#include <GUIConstants.au3>
#NoTrayIcon
AutoItSetOption("GUIOnEventMode",1)

;$mainwindow = GUICreate("Color1", 200, 100) for a visible window
$mainwindow = GUICreate("Color1", 1,1,-200,-100,0x00C00000,$WS_EX_TOOLWINDOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "DoQuit")
$DataHerebutton = GUICtrlCreateButton("Data", 50, 5, 60, 20)
$Box = GUICtrlCreateEdit ( "", 50, 50, 120, 40 )
GUICtrlSetOnEvent($DataHerebutton, "DataHere")
GUISetState(@SW_SHOW)

While 1
  Sleep(100)  
WEnd

Func DataHere ()
$nColor=GUICtrlRead($Box)
$r=_ColorGetRed($nColor)
$g=_ColorGetGreen($nColor)
$b=_ColorGetBlue($nColor)
$st="R: "&string($r)&" G: "&string($g)& " B: "&string($b)
ControlSetText("Test1","","Edit1",$st);
EndFunc 
    
Func DoQuit ()
     Exit
EndFunc

And the Delphi code

unit TestUnit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs,ComObj,ActiveX,AutoItX3Lib_TLB, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

Edit1: TEdit;

procedure FormCreate(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Edit1Change(Sender: TObject);

procedure FormActivate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

var aix: IAutoItX3;

ntitle:widestring='Color1';

nulstr:widestring=chr(0);

procedure TForm1.Button1Click(Sender: TObject);

var cst:widestring;

begin

cst:=inttostr(aix.pixelgetcolor(random(screen.Width),random(screen.Height)));

ntitle:='Color1';

aix.Run('color1.exe',nulstr,SW_Normal);

aix.WinActivate(ntitle,nulstr);

aix.WinWaitActive(ntitle,nulstr,10);

aix.ControlSetText(ntitle,nulstr,'Edit1',cst);

aix.ControlClick(ntitle,nulstr,'Button1','left',1,5,5);

end;

procedure TForm1.Edit1Change(Sender: TObject);

begin

aix.sleep(5);

aix.WinClose(ntitle,nulstr);

showmessage(edit1.Text);

end;

procedure TForm1.FormActivate(Sender: TObject);

begin

edit1.Visible:=false;

end;

procedure TForm1.FormCreate(Sender: TObject);

var g:tguid;

begin

g:=stringtoguid('AutoITX3.Control');

aix:=CreateComObject(g) as IAutoItX3;

end;

end.

color1.au3

Edited by BobK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0