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

截取外部程式ListBox和ComboBox的内容

缺席
hotswin
中階會員


發表:72
回覆:92
積分:52
註冊:2003-11-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-01-06 09:26:14 IP:59.125.xxx.xxx 訂閱
以下代碼是在網路上抓的,但是我怎麼試都抓不出來,(自己用Delphi寫一支有Listbox的執行檔作外部程式來測試)
win2000的環境下使用。
是不是要用hook的方式,寫一支DLL來 截取外部程式的Listbox的Item內容呢???

function GetListBoxText(mHandle: THandle; mStrings: TStrings): Boolean;
var
vItemCount: Integer;
I: Integer;
S: string;
begin
Result := False;
if not Assigned(mStrings) then Exit;
mStrings.BeginUpdate;
try
mStrings.Clear;

function GetComboBoxText(mHandle: THandle; mStrings: TStrings): Boolean;
var
  vItemCount: Integer;
  I: Integer;
  S: string;
begin
  Result := False;
  if not Assigned(mStrings) then Exit;
  mStrings.BeginUpdate;
  try
    mStrings.Clear;
    vItemCount := SendMessage(mHandle, CB_GETCOUNT, 0, 0);
    for I := 0 to vItemCount - 1 do begin
      SetLength(S, SendMessage(mHandle, CB_GETLBTEXTLEN, I, 0));
      SendMessage(mHandle, CB_GETLBTEXT, I, Integer(@S[1]));
      mStrings.Add(S);
    end;
    SetLength(S, 0);
  finally
    mStrings.EndUpdate;
  end;
  Result := True;
end; { GetComboBoxText }

//Example
procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Handle, 1, MOD_WIN, VK_F2);
  RegisterHotKey(Handle, 2, MOD_WIN, VK_F3);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, 1);
  UnRegisterHotKey(Handle, 2);
end;

procedure TForm1.WMHOTKEY(var Msg: TWMHOTKEY);
begin
  case Msg.HotKey of
    1:
      GetListBoxText(
        WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y)),
        MemoText.Lines);
    2:
      GetComboBoxText(
        WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y)),
        MemoText.Lines);
  end;
end;

vItemCount := SendMessage(mHandle, LB_GETCOUNT, 0, 0);
for I := 0 to vItemCount - 1 do begin
SetLength(S, SendMessage(mHandle, LB_GETTEXTLEN, I, 0));
SendMessage(mHandle, LB_GETTEXT, I, Integer(@S[1]));
mStrings.Add(S);
end;
SetLength(S, 0);
finally
mStrings.EndUpdate;
end;
Result := True;
end; { GetListBoxText }
------
xinjier禮品贈品
lonmener
一般會員


發表:16
回覆:32
積分:9
註冊:2005-08-20

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-06-06 00:02:54 IP:58.57.xxx.xxx 未訂閱

[code delphi]
//Hwn为外部ListBox的句柄

var
buffer: array[0..255] of Char;
i, h:integer;
begin
h := SendMessage(Hwn, LB_GETCOUNT,0, 0); //取LISTBOX行数

for i:=0 to h-1 do
SendMessage(Hwn, LB_GETTEXT, i, integer(@buffer));

{buffer为外部ListBox中各行的内容}
end;
[/code]
編輯記錄
lonmener 重新編輯於 2009-06-06 00:05:14, 註解 無‧
lonmener 重新編輯於 2009-06-06 00:05:56, 註解 無‧
系統時間:2024-04-24 7:35:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!