[Delphi] 纯文本查看 复制代码 unit Unit5;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm5 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TForm5.Button1Click(Sender: TObject);
var
h: THandle;
begin
h := FindWindow(nil, PChar('管理员: C:\Windows\system32\cmd.exe'));
if h <> 0 then
begin
showmessage('找到句柄');
SetForegroundWindow(h);
PostMessage(h, WM_KEYDOWN, VK_RETURN, 0); //发达回车到cmd窗口成功!
// SendMessage(h, WM_SETTEXT, Length(Memo1.Text), Integer(PChar(Memo1.Text)));
PostMessage(h, WM_CHAR, Length(Memo1.Text), Integer(PChar(Memo1.Text))); //假设memo1中的内容是dir /w
end;
end;
end.
|