newtron,
Cita:
Empezado por newtron
...una aplicación en VB6 de la cual tengo desde mi programa Delphi, que leer y escribir Strings desde y hacia unos Controles de Texto...¿Alguien me podría poner un ejemplo simple de envió/recepción de cadenas de caracteres desde/hacia otro programa VB6 sabiendo el nombre de los controles del programa VB?...
|
Revisa este código:
Código:
Option Explicit
'Código en VB6 de la aplicación que recibe y envía strings por medio de Delphi
Private Sub Command1_Click()
Dim Msg, Title As String
Msg = Text1 + " " + Text2 + " " + Text3
Title = "VB6"
Call MsgBox(Msg, vbOKOnly + vbInformation, Title)
End Sub
Private Sub Command2_Click()
Text1 = Empty
Text2 = Empty
Text3 = Empty
End Sub
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Label4: TLabel;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
public
end;
const
WindowName : String = 'Recibir Strings con Windows APIs';
var
Form1: TForm1;
SL : TStringList;
implementation
{$R *.dfm}
function EnumChildWindowsCallback(Window : THandle; SL : TStringList) : LongBool; Stdcall;
var
Buffer : Array[0..255] of Char;
begin
if (GetClassName(Window, Buffer, 256) <> 0) then
begin
SL.AddObject(Buffer, TObject(Window));
Result := True;
end
else
Result := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Window : THandle;
i,j : Integer;
Buffer : Array[0..8192] of Char;
AData : Array[0..2] of String;
begin
Window := FindWindow(nil, PChar(WindowName));
if (Window <> 0) then
begin
SL := TStringList.Create;
AData[0] := Edit1.Text;
AData[1] := Edit2.Text;
AData[2] := Edit3.Text;
EnumChildWindows(Window, @EnumChildWindowsCallback, LPARAM(SL));
j := 2;
for i := 0 to SL.Count - 1 do
begin
if (SL.Strings[i] = 'ThunderRT6TextBox') then
begin
StrPCopy(Buffer,AData[j]);
SendMessage(THandle(SL.Objects[i]), WM_SETTEXT, SizeOf(Buffer), Integer(@Buffer));
Dec(j);
end;
end;
SL.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Window : THandle;
i,j : Integer;
Buffer : Array[0..8192] of Char;
AData : Array[0..2] of String;
begin
Window := FindWindow(nil, PChar(WindowName));
if (Window <> 0) then
begin
SL := TStringList.Create;
EnumChildWindows(Window, @EnumChildWindowsCallback, LPARAM(SL));
j := 2;
for i := 0 to SL.Count - 1 do
begin
if (SL.Strings[i] = 'ThunderRT6TextBox') then
begin
SendMessage(THandle(SL.Objects[i]), WM_GETTEXT, SizeOf(Buffer), Integer(@Buffer));
AData[j] := Buffer;
Dec(j);
end;
end;
Edit1.Text := AData[0];
Edit2.Text := AData[1];
Edit3.Text := AData[2];
SL.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
MsgApp, MsgUsr : String;
begin
MsgApp := 'Delphi 7';
MsgUsr := Edit1.Text + ' ' + Edit2.Text + ' ' + Edit3.Text;
MessageBox(Handle, PChar(MsgUsr), PChar(MsgApp), MB_OK + MB_ICONINFORMATION);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Edit1.Text := EmptyStr;
Edit2.Text := EmptyStr;
Edit3.Text := EmptyStr;
end;
end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32,
Permite enviar (TEdit.Text) y recibir (TextBox) Strings hacia y desde un programa en VB6, como se muestra en la siguiente imagen:
Todo el código del ejemplo esta disponible en :
SendMessage Delphi 7 & VB6.rar
Nota: En VB6 los controles equivalentes a un TEdit
son los TextBox y su ClassName es ThunderRT6TextBox
Revisa esta información:
Espero sea útil
Nelson.