以下是我的类似楼上老兄的实现,但我这个可以穷举出鼠标位置控件的所有父类信息: procedure TMain.FowTimTimer(Sender: TObject); var poss:TPoint; ic:Hdc; Bmp:TbitMap; Hands: HWND; Buf: array[0..129] of Char; Stmp:TStrings; itmp,iwidth,iheight:integer; sword,sline:string; begin GetCursorPos(Poss); with FmFol do begin if (poss.x <> tag-10) or (poss.y<>FowTim.Tag-10) then left:=screen.Width else begin Hands := WindowFromPoint(Poss); if (left=tag) or (hands=handle) then exit; // if (left=tag) or (hands=handle) or (hands=main.handle) then exit; stmp:=TStringList.create; stmp.Add('句柄: '+IntToStr(Hands)); GetClassName(Hands, Buf, 128); stmp.Add ('类名: '+Buf); itmp:=GetParent(Hands); while itmp>0 do begin {if (itmp=application.Handle) or (itmp=main.handle) then begin stmp.Free; exit; end } // else //begin GetClassName(itmp, Buf, 128); if buf<>'' then stmp.Add (inttostr(stmp.Count-1)+'级父类: '+Buf); itmp:=GetParent(itmp); // end; end; SendMessage(Hands, WM_GETTEXT, 128, Integer(@Buf)); sword:='字符: '+buf; if length(sword)>132 then sword:=sword+'....'; repeat itmp:=pos(chr(10),sWord); if itmp>0 then begin sline:=copy(sWord,1,itmp-1); sword:=copy(sWord,itmp+1,length(sword)); end else sline:=sword; itmp:=pos(chr(13),sline); if itmp>0 then sline:=copy(sline,1,itmp-1); stmp.Add(sline); until sline=sword; // stmp.Add('字符: '+buf); // iheight:=0; iwidth:=0; for itmp:=0 to stmp.Count-1 do if canvas.TextWidth(stmp[itmp])+15>iWidth then iWidth:=canvas.TextWidth(stmp[itmp])+15; // begin iheight:=stmp.Count*(canvas.TextHeight(stmp[0])+2); // end; width:=iwidth; height:=iheight; SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE+ SWP_NOSIZE+SWP_NOACTIVATE+SWP_NOOWNERZORDER); ic:=CreateDC('DISPLAY',nil,nil,nil); if tag+width>screen.Width then tag:=screen.Width-width; if FowTim.Tag +height>screen.Height then FowTim.Tag:=screen.Height-height; Bmp:=Tbitmap.Create; bmp.Width := Width; bmp.Height :=Height; bitblt(bmp.Canvas.handle,0,0,Width,Height,ic,tag,FowTim.Tag,SRCCOPY); Left :=tag; Top :=FowTim.tag; bitblt(canvas.handle,0,0,Width,Height,bmp.Canvas.handle,0,0,SRCAND); canvas.Font.Color:=ClYellow; SetBkMode(canvas.handle,TRANSPARENT); for itmp:=0 to stmp.Count-1 do canvas.TextOut(5,5+itmp*canvas.TextHeight(stmp[itmp]),TrimRight(stmp[itmp])); deletedc(ic); bmp.free; stmp.Free; end; tag:=poss.x+10; FowTim.Tag:=poss.y+10; end; end;
我是指My_first(海浪)而言的,并且我是将桌面取回的字符以一个半透明的窗口显示的.
用com对象。去网上找找多得是
这个不用COM,发送WM_GETTEXT消息即可!function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall; var buffer: array[0..255] of char; begin Result := True; GetClassName(hwnd,buffer,256); if StrPas(Buffer)='Edit' then begin SendMessage(hwnd,WM_GETTEXT,256,lparam); Result:=False; end; end; procedure TForm1.Button1Click(Sender: TObject); var hwnd: Integer; buffer: array[0..255] of char; begin hwnd := FindWindow('IEFrame',nil); if hwnd<> 0 then begin EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@buffer[0])); Caption := StrPas(buffer); end; end;注意各版本的类可能不同,IEFrame是IE 6下!
var
className: PChar;
atCursor: TPoint;
hWndMouseOver: HWND;
text: PChar;
L:integer;
begin
GetCursorPos(atCursor);
hWndMouseOver:=WindowFromPoint(atCursor);
GetMem(ClassName, 100);
getmem(text,255);
try
GetClassName(hWndMouseOver, ClassName, 100);
GetWindowText(hwndmouseover,text,L);
Label_ClassName.Caption:='所属类名: '+String(ClassName);
Edit1.Text:=String(text);
finally
FreeMem(ClassName);
FreeMem(Text);
end;
end;
end.
http://www.vckbase.com/document/viewdoc.asp?id=288
procedure TMain.FowTimTimer(Sender: TObject);
var poss:TPoint;
ic:Hdc;
Bmp:TbitMap;
Hands: HWND;
Buf: array[0..129] of Char;
Stmp:TStrings;
itmp,iwidth,iheight:integer;
sword,sline:string;
begin
GetCursorPos(Poss);
with FmFol do
begin
if (poss.x <> tag-10) or (poss.y<>FowTim.Tag-10) then left:=screen.Width
else
begin
Hands := WindowFromPoint(Poss);
if (left=tag) or (hands=handle) then exit;
// if (left=tag) or (hands=handle) or (hands=main.handle) then exit;
stmp:=TStringList.create;
stmp.Add('句柄: '+IntToStr(Hands));
GetClassName(Hands, Buf, 128);
stmp.Add ('类名: '+Buf);
itmp:=GetParent(Hands);
while itmp>0 do
begin
{if (itmp=application.Handle) or (itmp=main.handle) then
begin
stmp.Free;
exit;
end }
// else
//begin
GetClassName(itmp, Buf, 128);
if buf<>'' then stmp.Add (inttostr(stmp.Count-1)+'级父类: '+Buf);
itmp:=GetParent(itmp);
// end;
end;
SendMessage(Hands, WM_GETTEXT, 128, Integer(@Buf));
sword:='字符: '+buf;
if length(sword)>132 then sword:=sword+'....';
repeat
itmp:=pos(chr(10),sWord);
if itmp>0 then
begin
sline:=copy(sWord,1,itmp-1);
sword:=copy(sWord,itmp+1,length(sword));
end
else sline:=sword;
itmp:=pos(chr(13),sline);
if itmp>0 then sline:=copy(sline,1,itmp-1);
stmp.Add(sline);
until sline=sword;
// stmp.Add('字符: '+buf);
// iheight:=0;
iwidth:=0;
for itmp:=0 to stmp.Count-1 do if canvas.TextWidth(stmp[itmp])+15>iWidth then iWidth:=canvas.TextWidth(stmp[itmp])+15;
// begin
iheight:=stmp.Count*(canvas.TextHeight(stmp[0])+2);
// end;
width:=iwidth;
height:=iheight;
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE+ SWP_NOSIZE+SWP_NOACTIVATE+SWP_NOOWNERZORDER);
ic:=CreateDC('DISPLAY',nil,nil,nil);
if tag+width>screen.Width then tag:=screen.Width-width;
if FowTim.Tag +height>screen.Height then FowTim.Tag:=screen.Height-height;
Bmp:=Tbitmap.Create;
bmp.Width := Width;
bmp.Height :=Height;
bitblt(bmp.Canvas.handle,0,0,Width,Height,ic,tag,FowTim.Tag,SRCCOPY);
Left :=tag;
Top :=FowTim.tag;
bitblt(canvas.handle,0,0,Width,Height,bmp.Canvas.handle,0,0,SRCAND);
canvas.Font.Color:=ClYellow;
SetBkMode(canvas.handle,TRANSPARENT);
for itmp:=0 to stmp.Count-1 do canvas.TextOut(5,5+itmp*canvas.TextHeight(stmp[itmp]),TrimRight(stmp[itmp]));
deletedc(ic);
bmp.free;
stmp.Free;
end;
tag:=poss.x+10;
FowTim.Tag:=poss.y+10;
end;
end;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
begin
hwnd := FindWindow('IEFrame',nil);
if hwnd<> 0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@buffer[0]));
Caption := StrPas(buffer);
end;
end;注意各版本的类可能不同,IEFrame是IE 6下!