想实现如下效果,但不知怎么写代码
在Edit框中输入字符,回车后能够将字符发送到WINDDOWS其它程序中,
比如记事本,WORD文档中,
有点像输入法的效果
请问代码怎么写呢?

解决方案 »

  1.   

    只要记得先得到原来的文本就行了
    下面是刚写的,向一个打开的文本文件里面输入文字(a.txt)
    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      h: HWND;
      str: pchar;
      hEdit: HWND;
      len: Integer;
      text: String;
    begin
      if key=vk_return then
        h := FindWindow(nil,pchar('a.txt - 记事本'));
        if h > 0 then
        begin
          //Showmessage('found');
          hEdit := FindWindowEx(h,0,'Edit',nil);
          if hEdit > 0 then
          begin
            //先得到原来的文本
            try
              len := SendMessage(hEdit,WM_GETTEXTLENGTH,0,0);
              Getmem(str,len+1);
              SendMessage(hEdit,WM_GETTEXT,len+1,LPARAM(str));
              //showmessage('found edit');
              text := Strpas(str) + Edit1.Text;
              SendMessage(hEdit,WM_SETTEXT,length(text),LPARAM(text));
            finally
              FreeMem(str);
            end;
          end;
      end;
    end;
      

  2.   

    to:naughtyboy(重归起跑线) 
    谢谢你了
    不过,你这样只是对一个固定'a.txt - 记事本'进行字符的发送
    怎么样能够使其发送到任意的程序当中呢
      

  3.   

    把naughtyboy(重归起跑线)的   
    h := FindWindow(nil,pchar('a.txt - 记事本'));
    改为
    h=GetWindow(GetDesktopWindow(), GW_HWNDNEXT);
    再加个while循环。。