通过另外一个应用程序给多个文本框赋值, 模拟单击事件
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过另外一个应用程序给多个文本框赋值, 模拟单击事件相关的知识,希望对你有一定的参考价值。
被调用的应用程序:
- unit Unit2;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm2 = class(TForm)
- Button1: TButton;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form2: TForm2;
- implementation
- {$R *.dfm}
- procedure TForm2.Button1Click(Sender: TObject);
- var
- h_form, h_text1, h_text2, h_button: HWND;
- str1, str2: string;
- begin
- // 获取窗口的句柄.
- h_form := findWindow(‘TForm1‘, ‘Form1‘);
- // 获取文本框的句柄. (注意多个)
- h_text1 := FindWindowEx(h_form, 0, ‘TEdit‘, nil);
- h_text2 := FindWindowEx(h_form, h_text1, ‘TEdit‘, nil);
- str1 := ‘本文1!‘;
- str2 := ‘本文2!‘;
- SendMessage(h_text1, WM_SETTEXT, 0, LPARAM(str1));
- SendMessage(h_text2, WM_SETTEXT, 0, LPARAM(str2));
- // 获取按钮的句柄. (注意多个)
- h_button := FindWindowEx(h_form, 0, ‘TButton‘, nil);
- SendMessage(h_button, WM_LBUTTONDOWN, 0, 0);
- SendMessage(h_button, WM_LBUTTONUP, 0, 0);
- label1.Caption := inttohex(h_form, 2);
- label2.Caption := inttohex(h_text1, 2);
- label3.Caption := inttohex(h_text2, 2);
- label4.Caption := inttohex(h_button, 2);
- end;
- end.
- object Form2: TForm2
- Left = 0
- Top = 0
- Caption = ‘Form2‘
- ClientHeight = 211
- ClientWidth = 408
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -11
- Font.Name = ‘Tahoma‘
- Font.Style = []
- OldCreateOrder = False
- PixelsPerInch = 96
- TextHeight = 13
- object Label1: TLabel
- Left = 144
- Top = 8
- Width = 57
- Height = 17
- Caption = ‘Label1‘
- end
- object Label2: TLabel
- Left = 74
- Top = 48
- Width = 57
- Height = 25
- Caption = ‘Label2‘
- end
- object Label3: TLabel
- Left = 208
- Top = 48
- Width = 79
- Height = 17
- Caption = ‘Label3‘
- end
- object Label4: TLabel
- Left = 144
- Top = 96
- Width = 79
- Height = 25
- Caption = ‘Label4‘
- end
- object Button1: TButton
- Left = 144
- Top = 160
- Width = 75
- Height = 25
- Caption = ‘Button1‘
- TabOrder = 0
- OnClick = Button1Click
- end
- end
调用的程序:
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm1 = class(TForm)
- Edit1: TEdit;
- Edit2: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Button1: TButton;
- Label3: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- // showmessage(‘登陆成功!‘);
- label3.Caption := ‘登陆成功!‘;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- label3.Caption := ‘‘;
- end;
- end.
- object Form1: TForm1
- Left = 0
- Top = 0
- Caption = ‘Form1‘
- ClientHeight = 360
- ClientWidth = 486
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -11
- Font.Name = ‘Tahoma‘
- Font.Style = []
- OldCreateOrder = False
- OnCreate = FormCreate
- PixelsPerInch = 96
- TextHeight = 13
- object Label1: TLabel
- Left = 168
- Top = 155
- Width = 40
- Height = 13
- Caption = #29992#25143#21517‘:‘
- end
- object Label2: TLabel
- Left = 168
- Top = 203
- Width = 28
- Height = 13
- Caption = #23494#30721‘:‘
- end
- object Label3: TLabel
- Left = 208
- Top = 288
- Width = 193
- Height = 41
- Caption = ‘Label3‘
- end
- object Edit1: TEdit
- Left = 224
- Top = 152
- Width = 121
- Height = 21
- ImeName = #20013#25991‘(‘#31616#20307‘) - ‘#26497#28857#20116#31508
- TabOrder = 0
- end
- object Edit2: TEdit
- Left = 224
- Top = 200
- Width = 121
- Height = 21
- ImeName = #20013#25991‘(‘#31616#20307‘) - ‘#26497#28857#20116#31508
- TabOrder = 1
- end
- object Button1: TButton
- Left = 270
- Top = 248
- Width = 75
- Height = 25
- Caption = #30331#38470
- TabOrder = 2
- OnClick = Button1Click
- end
- end
http://blog.csdn.net/huang_xw/article/details/8644506
以上是关于通过另外一个应用程序给多个文本框赋值, 模拟单击事件的主要内容,如果未能解决你的问题,请参考以下文章
freemarker 取得文本框内容赋值给一个变量, 怎么实现?
在c#中,将一个textbox设置成多行,并在其中输入多行内容,怎样选中一行并将其显示在另外一个文本框中,