Mega Code Archive

 
Categories / Delphi / Hardware
 

Get the active TWinControl under the mouse cursor

Title: get the active TWinControl under the mouse cursor? { Sie können z.B diese Funktion in einer allgemein gültigen Prozedure aufrufen, die Sie dann allen betroffenen Ereignisse zuweisen. } { You may call this function in a global event procedure, linking as many components events to it as you need. } function FindControlAtPos: TWinControl; var Pt: TPoint; begin GetCursorPos(Pt); Result := FindControl(WindowFromPoint(Pt)); end; { (Beispiel) Hier die allgemein gültige Procedure für OnMouseUp. Die Behandlung von OnClick bleibt dabei erhalten: die Funktionalität aus OnMouseUp kommt dazu. } { (example) There's the global proc for the OnMouseUp event. Note: OnClick keeps working, so you can "add" the OnMouseUp facility to no cost. } procedure TForm1.GenericMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var TWC: TWinControl; begin TWC := FindControlAtPos; //what for a class ! Showmessage('Here we are: ' + TWC.ClassName); //Let it blink... TWC.Visible := False; Sleep(150); TWC.Visible := True; end;