TPoint P;
char Buf[64];
AnsiString ClassName;GetCursorPos(&P);
GetClassName(WindowFromPoint(P),Buf,sizeof(64));
ClassName = AnsiString(Buf);

解决方案 »

  1.   

    var
      ClassName: PChar;
      ptCursor: TPoint;
      hWndOver: HWND;
      Text: PChar;
    begin
      GetCursorPos(ptCursor);
      hWndOver := WindowFromPoint(ptCursor);
      GetMem(ClassName, 100);
      GetMem(Text, 255);
      try
        GetClassName(hWndOver, ClassName, 100);
        SendMessage(hWndOver, WM_GETTEXT, 255, LongInt(Text));
        Canvas.FillRect(Rect(5, 20 , PreClassLength + 20, 40));
        Canvas.FillRect(Rect(5, 40 , PreTextLength + 20, 60));
        PreClassLength := Canvas.TextWidth(ClassName);
        PreTextLength := Canvas.TextWidth(Text);
        if PreClassLength > PreTextLength then
          Width := Canvas.TextWidth(ClassName) + 20
        else
          Width := Canvas.TextWidth(Text) + 20;
        Canvas.TextOut(5, 20, string(ClassName));
        Canvas.TextOut(5, 35, string(Text));
      finally
        FreeMem(ClassName);
        FreeMem(Text);
      end;
    end;
    把classname换成name就可以了。
      

  2.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
      vPoint: TPoint;
    begin
      S := '<没有找到>';
      vPoint := ScreenToClient(Mouse.CursorPos);
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
          S := Components[I].Name;
          Break;
        end;
      Caption := S;
    end;
      

  3.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
      vPoint: TPoint;
    begin
      S := '<没有找到>';
      vPoint := ScreenToClient(Mouse.CursorPos);
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
          S := Components[I].Name;
          Break;
        end;
      Caption := S;
    end;
      

  4.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
      vPoint: TPoint;
    begin
      S := '<没有找到>';
      vPoint := ScreenToClient(Mouse.CursorPos);
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
          S := Components[I].Name;
          Break;
        end;
      Caption := S;
    end;
      

  5.   

    查看delphi的帮助
    好像说The WindowFromPoint function does not retrieve the handle of a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search. 因此可以试试ChildWindowFromPoint函数了
      

  6.   

    我的代码你不要写在button的事件中,
    你把它写在一个timer的ontimer事件中,然后用鼠标在屏幕中移动,
    所有的窗口都能得到。
      

  7.   

    还有你要处理的是窗体对象,得到窗口体handle就可以了,
    不用非要得到名称。
      

  8.   

    zswang(伴水)
    谢谢!
    直接窗体上的是行的,但在panel里面的label就不行了。
    能不能再改进一下。
      

  9.   

    还有你要处理的是窗体对象,得到窗口体handle就可以了,
    不用非要得到名称。
      

  10.   

    还有你要处理的是窗体对象,得到窗口体handle就可以了,
    不用非要得到名称。
      

  11.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
    begin
      S := '<没有找到>';
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect,
          TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
          S := Components[I].Name;
      Caption := S;
    end;
      

  12.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
    begin
      S := '<没有找到>';
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect,
          TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
          S := Components[I].Name;
      Caption := S;
    end;
      

  13.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      S: string;
    begin
      S := '<没有找到>';
      for I := 0 to ComponentCount - 1 do
        if (Components[I] is TControl) and
          PtInRect(TControl(Components[I]).BoundsRect,
          TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
          S := Components[I].Name;
      Caption := S;
    end;