zoukankan      html  css  js  c++  java
  • delphi用postMessage发送字符到记事本

    演示了PostMessage, SendMessage, WM_CHAR发送汉字。

    源代码:
    -------------------------------------------

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      p rivate
        { P rivate declarations }
      public
        constructor Create(AOwner: TComponent); override;

        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}
    {$APPTYPE CONSOLE}
    var
      hNotePad:HWND;
      hedit:HWND;

    constructor TForm1.Create(AOwner: TComponent);
    begin
      inherited;
      Memo1.Text:='这是猪悟能的postmessage测试';
    end;

    procedure TForm1.Button1Click(Sender: TObject);

    begin
        hNotePad:=FindWindow('Notepad','无标题 - 记事本');
        if hNotePad<>0 then
        begin
          hedit:=FindWindowEx(hNotePad,0,'edit',nil);
          PostMessage(hedit,WM_CHAR,Wparam('B'),0);
          Writeln('send');
        end;

    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    { TODO -o猪悟能 : 发送串必须用sendMessage }
       hNotePad:=FindWindow(nil,'无标题 - 记事本');
       if hNotePad<>0 then
       begin
        hedit:=FindWindowEx(hNotePad,0,'edit',nil);
        SendMessage(hedit,WM_SETTEXT,Length(Memo1.Text),
          Integer(PChar(Memo1.Text)));
        Writeln('send');
       end;

    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
     hNotePad:=FindWindow('Notepad','无标题 - 记事本');
      if hNotePad<>0 then
      begin
        hedit:=FindWindowEx(hNotePad,0,'edit',nil);
        PostMessage(hedit,WM_CHAR,Wparam($bd),0);
        PostMessage(hedit,WM_CHAR,Wparam($f1),0);
        Writeln('send');
      end;
    end;

    end.

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    Xenu Link Sleuth简单使用
    C#简单游戏外挂制作(以Warcraft Ⅲ为例)
    Silverlight InkPresenter 实现路径回放的探索
    Microsoft Virtual Earth Silverlight Map Control (CTP)快速上手
    【Azure实例】有趣的Silverlight应用:录播简笔画
    Azure Services Platform 入门系列文章索引页
    javascript原型的类继承
    javascript给类添加的方法
    checkbox 全选
    【nodejs】 在 Ubuntu 12.04 安裝 Node.js【转】
  • 原文地址:https://www.cnblogs.com/jijm123/p/14395396.html
Copyright © 2011-2022 走看看