当前位置:主页>仓库管理软件> 列表

怎样获得一个程序中TreeView的内容? 找库存软件下载

进销存软件版1楼: 要说明的是目标程序是外部程序。
好象是要用SendMessage获得吧?怎样获得?或者谁提供一下TreeView的消息资料

2楼: 要知道这个类的名称呀。。
要不然就得不断的去遍历! 如库存软件下载

3楼: To5207:类名这些东西就不用担心拉,实际一点说一下方法更好

4楼: 线程注入!同取ListVie差不多!HOOK也行。
我这有HOOK 的,取数据可以用文件映射,发送windows消息都行;

{***************************************************************}
{ }
{ PraiseSoft SoftWare System }
{ Copyright(c) 2004-2005 PraiseSoft Software Corporation }
{ SoftWareName: HOOK Other Program of TreeView }
{ Version: V1.0 }
{ DevIDE: Delphi7.0 Windows 2000 Professional }
{ Build: 2006-01-15 }
{ Author: jfyes Email: jf_yes@163.com QQ: 348677065 }


{ Function: }
{ Description: }
{ Noteice: 1.本信息资料仅用于个人和非商业用途,复制请保留此信息,
未经作者书面许可,不得作任商业用途。}

{***************************************************************}
library HOOKTreeView;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library''s USES clause AND your project''s (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
Windows,
Messages,

CommCtrl;

var
HOOK_NEXT: HHOOK;


function CheckClassName(const ClassName: PChar): BOOL;
const
SClassName: array[0..2] of array [0..18] of Char =(''TTreeControl'', ''TTreeView'', ''SysTreeView32'');
var
I: Integer;
begin
Result := False;
for I := Low(SClassName) to High(SClassName) do
if Windows.lstrcmp(ClassName, SClassName[I]) = 0 then
begin
Result := True;
break;
end;
end;

function FormatChar(OutPut: PChar; const Format: PChar; arglist: array of Integer): Integer;
begin
Result := Windows.wvsprintf(OutPut, Format, @arglist[Low(arglist)]);
end;

function TViewGetNode(hTView: HWND; ItemId: HTreeItem): PTVItem;
var
Item: TTVItem;
begin
with Item do
begin
hItem := ItemId;
mask := TVIF_PARAM;
end;
if TreeView_GetItem(hTView, Item) then
Result := @Item
else
Result := nil;
end;

function TViewGetFirstNode(hTView: HWND): TTVItem;

begin
Result := TViewGetNode(hTView, TreeView_GetRoot(hTView))^;
end;

function TViewGetCount(hTView: HWND): Integer;
begin
Result := CommCtrl.TreeView_GetCount(hTView);
end;

function TViewGetNodeText(hTView: HWND; const Node: TTVItem;
lpBuf: PChar; const lpBufSize: Integer): BOOL;
var
Item: TTVItem;
begin
Item.mask := TVIF_TEXT;
Item.pszText := lpBuf;
Item.hItem := Node.hItem;
Item.cchTextMax := lpBufSize;
Result := CommCtrl.TreeView_GetItem(hTView, Item);
end;

procedure ReadTreeViewData(const H: HWND; const ClassName: PChar);
var
Count: Integer;
pItem: TTVITEM;
MSG, lPText: array[0..1024] of Char;
begin
Count := TViewGetCount(H);
pItem := TViewGetFirstNode(H);
TViewGetNodeText(H, pItem, lPText, SizeOf(lPText));
FormatChar(MSG, ''ClassName: %s Count %d ''#13#10''TViewGetFirstNode %s'', [Integer(ClassName), Count, Integer(@lPText)]);
Windows.MessageBox(H, MSG, ClassName, MB_OK);
end;


function MouseProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult; stdcall;
const
TreeView = WC_TREEVIEW;//''SysTreeView32'';
var
H: HWND;
ClassName: array[0..255] of Char;
begin
Result := 0;
if nCode < 0 then
Result := Windows.CallNextHookEx(HOOK_NEXT, nCode, wParam, lParam)
else if nCode = HC_ACTION then begin
if wParam = WM_LBUTTONDOWN then
begin
H := Windows.PMouseHookStruct(lParam)^.hwnd;
if H <> 0 then begin
FillChar(ClassName, SizeOf(ClassName), #0);
Windows.GetClassName(H, ClassName, SizeOf(ClassName));
if CheckClassName(ClassName) then
ReadTreeViewData(H, ClassName);
end;
end;
Result := Windows.CallNextHookEx(HOOK_NEXT, nCode, wParam, lParam);
end;
end;

function InstallHook: BOOL; stdcall;
begin
HOOK_NEXT := Windows.SetWindowsHookEx(WH_MOUSE, @MouseProc, hInstance, 0);
Result := HOOK_NEXT <> 0;
end;

procedure UnInstallHook; stdcall;
begin
if HOOK_NEXT <> 0 then
Windows.UnhookWindowsHookEx(HOOK_NEXT);
end;

exports
InstallHook,
UnInstallHook;
begin

end.


===========
var
Form1: TForm1;

function InstallHook: BOOL; stdcall; external ''HOOKTreeView.dll'' name ''InstallHook'';
procedure UnInstallHook; stdcall; external ''HOOKTreeView.dll'' name ''UnInstallHook'';

var
IsInstal: BOOL = False;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
IsInstal := InstallHook;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
if IsInstal then
UnInstallHook
end;

end.

5楼: 感谢jfyes提供另外一个更好的办法,比用SendMessage方便多了
当然如果有SendMessage的方法也说一下
再等一下,如果没有人跟就送分了

6楼: 接受答案了.