Delphi 獲取當前鼠標下的控件內容


 

Delphi 獲取當前鼠標下的控件內容

主要函數:

GetCursorPos;//獲取鼠標的位置

WindowFromPoint;//獲取制定point下的handle

GetClassName;//獲取類的名字

 

function TForm1.GetEditText: string;
var
  Point: TPoint;
  Name: array[0..255] of Char;
  Buffer: array[0..1023] of Char;
  AHandle: THandle;
begin
  //取得鼠標位置
  GetCursorPos(Point);
  //取得當前窗口句柄
  AHandle := WindowFromPoint(Point);
  GetClassName(AHandle, Name, Length(Name));
  if AHandle = Self.Handle then
    Exit;
  SendMessage(AHandle, WM_GETTEXT, 1023, Integer(@Buffer));
  Caption := StrPas(Name);
  Result := StrPas(Buffer);  
end;

 

procedure TForm1.tmr1Timer(Sender: TObject);
begin
  mmo1.Lines.Text := GetEditText;
end;

 

https://blog.csdn.net/lwstar23133/article/details/6773883


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM