关于获取其它程序窗口编辑框内容解决思路
关于获取其它程序窗口编辑框内容
想通过一个小程序获取一个叫“客户信息”窗口中不为空编辑框的内容
窗口有四个编辑框,请大家指教。
------解决方案--------------------
先获取到编辑框的句柄,可以根据Z序查找到句柄,你用Spy++看下;
然后用下面的函数获取编辑框里面的内容:
function GetWndText(ThWnd: hWnd): string;
var
Ret:LongInt;
mText:PChar;
Buf:Integer;
begin
Ret := SendMessage(ThWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText,Ret);
try
Buf := LongInt(mText);
SendMessage(ThWnd, WM_GETTEXT, Ret, Buf);
Result := StrPas(mText);
finally
FreeMem(mText,Ret);
end;
end;
------解决方案--------------------
既然找到了句柄,直接用api GetWindowText不就得了
------解决方案--------------------
1.FindWindows 先找主窗体
2.EnumChildWindows 找出所有子窗体
循环再判一下就成了
------解决方案--------------------
listbox不能这么读啊
要读内存,用下面的函数:
uses CommCtrl;
function TreeNodeGetNext(mHandle: THandle; mTreeItem: HTreeItem): HTreeItem;
var
vParentID: HTreeItem;
begin
Result := nil;
if (mHandle <> 0) and (mTreeItem <> nil) then begin
Result := TreeView_GetChild(mHandle, mTreeItem);
if Result = nil then
Result := TreeView_GetNextSibling(mHandle, mTreeItem);
vParentID := mTreeItem;
while (Result = nil) and (vParentID <> nil) do begin
vParentID := TreeView_GetParent(mHandle, vParentID);
Result := TreeView_GetNextSibling(mHandle, vParentID);
end;
end;
end;
function TreeView_SelectItem_Ex(hwndTV: HWND; slText: TStringList): Boolean;
var
vItemCount: Integer;
vBuffer: array[0..255] of Char;
vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
I: Integer;
vItem: TTVItem;//uses CommCtrl
vTreeItem: HTreeItem;
begin
Result := False;
if hwndTV = 0 then exit;
GetWindowThreadProcessId(hwndTV, @vProcessId); // ?瑕?蝒?餈?ID
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
if (vProcess = 0) then
Exit;
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
if vPointer = nil then exit;
try
vItemCount := TreeView_GetCount(hwndTV);
好的代码像粥一样,都是用时间熬出来的