我用NTA方式已经在DELPHI的菜单上加了个菜单子项 , 下面的代码已经在DELPHI的菜单上了的一项了(我想应该是和DELPHI在同一个进程空间上了)也执行到showmessage('找到字段'+edit1.Text);这行了 可是SendMessage(hListBox, LB_SETCURSEL, i, 1);却没一点反映 为什么?
//////-----------------------------------------------------------function EnumProc(hwnd:Thandle;lparam:lparam):boolean; stdcall;implementation{$R *.dfm}
var
frmAbout: TfrmAbout;
hListBox:HWnd;
procedure TfrmAbout.Button2Click(Sender: TObject);
var
SourceHwnd, TargetHWnd:HWND;
nItems:integer;
i:integer;
s:string;
begin
SourceHwnd:= FindWindow('TFieldsEditor', 'dtmyx_OrderTrace.adsMaster');
if SourceHwnd = null then
raise exception.Create('找不到-TFieldsEditor-dtmyx_OrderTrace.adsMaster');
EnumChildWindows(SourceHwnd, @EnumProc, Integer(@TargetHWnd)); if hListBox = null then
raise exception.Create('找不到-TListBox-'); nItems := SendMessage(hListBox, LB_GETCOUNT, 0, 0);
showmessage(inttostr(nItems)); for i:=0 to nItems-1 do
begin
SetLength(S, SendMessage(hListBox, LB_GETTEXTLEN, i, 0));
SendMessage(hListBox, LB_GETTEXT, i, Integer(@s[1]));
//showmessage(s);
if UpperCase(s)= UpperCase(edit1.Text) then
begin
showmessage('找到字段'+edit1.Text);
SetWindowPos(Handle, HWND_TOPMOST, self.Left, self.Top, self.Width, self.Height,0);
SendMessage(hListBox, LB_SETCURSEL, i, 1);
break;
end;
end;
end;function EnumProc(hwnd:Thandle;lparam:lparam):boolean; stdcall;
var
aName: array [0..255] of char;
nItems:integer;
begin
result := True;
GetClassName(hwnd, aName, 256);
showmessage(StrPas(@aName));
frmAbout.Memo1.Lines.Add(StrPas(@aName));
if StrPas(@aName)='TListBox' then
begin
PInteger(lparam)^ := hwnd;
hListBox:= hwnd;
nItems := SendMessage(hwnd, LB_GETCOUNT, 0, 0);
if nItems>0 then
Result:=False;
end;
end;
//////-----------------------------------------------------------function EnumProc(hwnd:Thandle;lparam:lparam):boolean; stdcall;implementation{$R *.dfm}
var
frmAbout: TfrmAbout;
hListBox:HWnd;
procedure TfrmAbout.Button2Click(Sender: TObject);
var
SourceHwnd, TargetHWnd:HWND;
nItems:integer;
i:integer;
s:string;
begin
SourceHwnd:= FindWindow('TFieldsEditor', 'dtmyx_OrderTrace.adsMaster');
if SourceHwnd = null then
raise exception.Create('找不到-TFieldsEditor-dtmyx_OrderTrace.adsMaster');
EnumChildWindows(SourceHwnd, @EnumProc, Integer(@TargetHWnd)); if hListBox = null then
raise exception.Create('找不到-TListBox-'); nItems := SendMessage(hListBox, LB_GETCOUNT, 0, 0);
showmessage(inttostr(nItems)); for i:=0 to nItems-1 do
begin
SetLength(S, SendMessage(hListBox, LB_GETTEXTLEN, i, 0));
SendMessage(hListBox, LB_GETTEXT, i, Integer(@s[1]));
//showmessage(s);
if UpperCase(s)= UpperCase(edit1.Text) then
begin
showmessage('找到字段'+edit1.Text);
SetWindowPos(Handle, HWND_TOPMOST, self.Left, self.Top, self.Width, self.Height,0);
SendMessage(hListBox, LB_SETCURSEL, i, 1);
break;
end;
end;
end;function EnumProc(hwnd:Thandle;lparam:lparam):boolean; stdcall;
var
aName: array [0..255] of char;
nItems:integer;
begin
result := True;
GetClassName(hwnd, aName, 256);
showmessage(StrPas(@aName));
frmAbout.Memo1.Lines.Add(StrPas(@aName));
if StrPas(@aName)='TListBox' then
begin
PInteger(lparam)^ := hwnd;
hListBox:= hwnd;
nItems := SendMessage(hwnd, LB_GETCOUNT, 0, 0);
if nItems>0 then
Result:=False;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货