Des fenêtres "collantes"

bebeb3 Messages postés 13 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 18 septembre 2003 - 31 janv. 2003 à 10:25
bebeb3 Messages postés 13 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 18 septembre 2003 - 2 févr. 2003 à 17:47
slt,

Je voudrait que les différentes fenêtres de mon soft puissent se coller les unes aux autres (comme celles de winamp) et que lorsque j'en déplace une, celle(s) qui y sont collées suivent.

Donnez-moi des pistes ou des exemples et merci d'avance

8D

2 réponses

cs_lugdanum Messages postés 58 Date d'inscription samedi 23 novembre 2002 Statut Membre Dernière intervention 12 décembre 2006
31 janv. 2003 à 11:56
Salut je te propose deux solutions, pas forcément les meilleurs mais bon! :

tu rajoute un timer et tu mets ce code dans son ontimer:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
form2.left:=form1.Left+232; //(1)
form2.Top:=form2.Top; //(2)
end;

pour(1), en fait tu fais la différence de leurs positions sur le bureau, moi ici ma fiche principal était (left=260,top=140) et ma fiche qui la suit(left=592,top=140), j'ai fais 592-260 pour obtenir sa positon.
pour(2) j'ai mis cela pour qu'elle reste toujours à la même hauteur.
enfin l'interval du timer est de 100.
Tu peux largement améliorer ce code. Sache aussi que le timer utilise de la resource mais avec les pc actuels....

Pour la deuxième c'est mieux mais un petit peu plus complexe:

dans la partie déclaratoin privée tu rajoutes:
procedure WMNCHitTest(var M: TWMNCHitTest); message wm_NCHitTest;

ensuite dans ton code tu mets:
procedure Tform1.WMNCHitTest(var M: TWMNCHitTest);
begin
inherited;
if M.Result=htCaption then form2.Left:=form1.Left+232;
if M.Result=htCaption then form2.top:=form1.top;
end;

voili voilou, paufine un peu et cela devrais rouler lol

@+
0
bebeb3 Messages postés 13 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 18 septembre 2003
2 févr. 2003 à 17:47
G résolu mon problème, en fait g traduit une astuce C++ trouvé sur je sais plus quel site.
Donc pour ceux que ça interresse, voir ci-dessous.

A rajouter dans les déclarations privées de la fiche
procedure WMWINDOWPOSCHANGING (Var Msg: TWMWINDOWPOSCHANGING);message WM_WINDOWPOSCHANGING;

function EnumWindowsProc (Wnd: HWND;List: TStrings): BOOL; stdcall;

procedure TForm1.WMWINDOWPOSCHANGING (Var Msg: TWMWINDOWPOSCHANGING);
var
rWindow: TRect;
StickAt : Word;
sWList : Tstrings;
hHandle : Thandle;
i : integer;
begin
sWList := Tstringlist.create;
EnumWindows(@EnumWindowsProc, Integer(sWList));
StickAt := 15;
bSnapped:=false;

with sWList do
for i := 0 to count -1 do begin
hHandle := FindWindow(nil, Pchar(sWList[i]));
if GetWindowRect(hHandle,rWindow) then begin

// RIGHT
with Msg.WindowPos^ do
if(x <= rWindow.right + StickAt) and (x >= rWindow.right - StickAt) then
if ((y + cy> rWindow.top) and (y < rWindow.Bottom)) then begin
bSnapped := true;
x := rWindow.right;
end;
//LEFT
with Msg.WindowPos^ do
if(x + cx <= rWindow.left + StickAt) and (x + cx >= rWindow.left - StickAt) then
if ((y + cy> rWindow.top) and (y < rWindow.Bottom)) then begin
bSnapped := true;
x := rWindow.left - cx;
end;
//TOP
with Msg.WindowPos^ do
if(y + cy <= rWindow.top + StickAt) and (y + cy >= rWindow.top - StickAt) then
if ((x + cx > rWindow.left) and (x < rWindow.right)) then begin
bSnapped := true;
y := rWindow.top - cy;
end;
//BOTTOM
with Msg.WindowPos^ do
if(y <= rWindow.Bottom + StickAt) and (y >= rWindow.Bottom - StickAt) then
if ((x + cx > rWindow.left) and (x < rWindow.right)) then begin
bSnapped := true;
y := rWindow.Bottom;
end;
end;
end;
FreeAndNil(sWList);
end;

function EnumWindowsProc (Wnd: HWND;List: TStrings): BOOL; stdcall;
var
caption: array [0..256] of Char;
begin
Result := True;
if GetWindowText (Wnd, Caption, SizeOf(Caption)-1) <> 0 then
if IsWindowVisible(wnd) then
List.AddObject( caption, TObject( Wnd ));
end;

Remarque : le défaut de ce code est qu'il faut redéfinir
certains comportement de la fiche qui sont normalement communs
et définit dans ses propriétés comme les contraintes de taille,
l'accrochage magnétiqye sur les bords de l'écran (delphi 7), etc.
0
Rejoignez-nous