Dessiner un cadre autour du controle sous la souris

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;

var
Form1: TForm1;
hOldWnd:integer;
implementation

{$R *.DFM}

procedure FrameWindow(Wnd: HWnd);
var
Rect: TRect;
DC: hDC;
OldPen, Pen: hPen;
OldBrush, Brush: hBrush;
X2, Y2: Integer;
begin
{ Get the target window's rect and DC }
GetWindowRect(Wnd, Rect);
DC := GetWindowDC(Wnd);
{ Set ROP appropriately for highlighting }
SetROP2(DC, R2_NOT);
{ Select brush and pen }
Pen := CreatePen(PS_InsideFrame, 4, 0);
OldPen := SelectObject(DC, Pen);
Brush := GetStockObject(Null_Brush);
OldBrush := SelectObject(DC, Brush);
{ Set dimensions of highlight }
X2 := Rect.Right - Rect.Left;
Y2 := Rect.Bottom - Rect.Top;
{ Draw highlight box }
Rectangle(DC, 0, 0, X2, Y2);
{ Clean up }
SelectObject(DC, OldBrush);
SelectObject(DC, OldPen);
ReleaseDC(Wnd, DC);
{ Do NOT delete the brush, because it was a stock object }
DeleteObject(Pen);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
// remove old frame
if hOldWnd <> 0 then
FrameWindow(hOldWnd);
// Get Oobject under mouse
hOldWnd := WindowFromPoint(Mouse.CursorPos);
// Draw new frame
if hOldWnd <> 0 then
FrameWindow(hOldWnd);
end;
end.
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour13/07/2002
VisualisationVu 2197 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Graphisme
Auteur de l'article
Communauté Delphi Communauté Delphi
connecté le 02/11/2011
0 articles dans la section
Contacter l'auteur