全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2249
推到 Plurk!
推到 Facebook!

如何將字串傳入到Windows目前作用視窗Cursor所在位置

尚未結案
Wawa
一般會員


發表:27
回覆:55
積分:16
註冊:2002-10-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-09-30 05:41:00 IP:61.224.xxx.xxx 未訂閱
請教 Delphi 如何將字串傳入到Windows目前作用視窗Cursor所在位置, 1.Windows目前作用視窗:指目前 Cursor 閃爍等待輸入字串之視窗, 2.Cursor所在位置:指要傳入字串所在位置(即字串要加在 Cursor 後) 3.如何能用 HotKey (例:Ctrl A), 則傳送字串到 ","到 Cursor 後 謝謝指導!!
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-09-30 08:07:27 IP:61.155.xxx.xxx 未訂閱
unit Unit1;    interface    uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls;    type   TForm1 = class(TForm)     Edit1: TEdit;     Edit2: TEdit;     Button1: TButton;     Memo1: TMemo;     CheckBox1: TCheckBox;     procedure FormCreate(Sender: TObject);   private    procedure ON_WM_HOTKEY(var m:TMessage);message WM_HOTKEY;     { Private declarations }   public     { Public declarations }   end;    var   Form1: TForm1;    implementation    {$R *.dfm}    procedure TForm1.ON_WM_HOTKEY(var m: TMessage); begin    if(m.WParam=123)then  //如果id是123   if ActiveControl is Tedit then      (ActiveControl as tedit).SelText:=',';    end;    procedure TForm1.FormCreate(Sender: TObject); begin RegisterHotKey(Handle,123,MOD_CONTROL,integer('A')); //123是自己定义的id ,热键是 ctrl+A end;    end.    这样就可以了!
Wawa
一般會員


發表:27
回覆:55
積分:16
註冊:2002-10-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-09-30 13:32:33 IP:61.224.xxx.xxx 未訂閱
真的非常感謝 sos_admin 的解答. 但我最不會的是如何取得 Window 目前 Cursor 所在的作用視窗, 該作用視窗可能是 NotePad, Word, ... 只要能輸入字元的視窗皆是, 甚至連我現在所打的地方都算是. 例如下列程式碼, 可將所要貼上的字串加在 NotePad 上, 但我想要的是目前 Cursor 所在的作用視窗, 不一定是 NotePad, 任何程式都有可能, 因 Window 的 Caret 同一時間只會存在一個等待輸入的作用視窗. 希望您不吝再次賜教, 謝謝!! procedure TForm1.Button1Click(Sender: TObject); var s:string; h, npad:HWND; begin // h:=childwindowfrompoint(findwindow('notepad',nil),point(50,50)); Npad := FindWindow(nil, '未命名 - 記事本'); if npad <> 0 then begin h:=ChildWindowFromPoint(npad,Point(10,10)); if h <> 0 then begin BringWindowToTop(Npad); //使其成為focus之window s:='測試Test'; SendMessage(h, WM_SETTEXT,0,longint(PCHAR(S))); end; end; end;
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-30 15:27:20 IP:202.39.xxx.xxx 未訂閱
也許有點幫助: http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&oe=UTF-8&th=302997ef3a3a4050&rnum=11    --- 歡迎光臨 KTop 研究院
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-09-30 16:16:26 IP:61.155.xxx.xxx 未訂閱
参考: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=35055 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wawa
一般會員


發表:27
回覆:55
積分:16
註冊:2002-10-04

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-10-01 09:57:38 IP:61.224.xxx.xxx 未訂閱
謝謝 sos_admin,hagar, 問題已解決了!! 較為好且正確的做法應為下列的程式碼,我是在國外網站找到的, 特別張貼出來, 希望對需要的人能有所幫助 function GetSysFocus : integer; Var hOtherWin,OtherThreadID,hFocusWin : integer; Begin hOtherWin := GetForegroundWindow; OtherThreadID := GetWindowThreadProcessID( hOtherWin, nil); If AttachThreadInput( GetCurrentThreadID, OtherThreadID, true ) Then Begin hFocusWin := GetFocus; result := GetFocus; AttachThreadInput( GetCurrentThreadID, OtherThreadID, False ); End else result := getFocus; End;
系統時間:2024-05-03 2:09:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!