file: // create the armed forces 2004.6.15file: // Author: transparent ink beans (nickname) file: // QQ: 33125083file: // Description: This program is modified from "a" magnetic "window" --- wujian2 article The reason is that the original article is not full and file: // has an error, and feels imperfect, if you cannot distinguish whether the two windows are in the same area, not file: // Stop the edge of the screen. However, this procedure has a shortcomings, such as window form can't move File with Winamp's window: // I hope everyone will advise, this is my first article. File: // Detailed description, please see the original text
Unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;
type TForm1 = class (TForm) Button1: TButton; procedure Button1Click (Sender: TObject); procedure FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Magnetize (var nl, nt: integer); procedure Edgetize (var nL, nT: integer); procedure private {Private declarations} // define at where near the edge of the screen public {public declarations} END;
Const magneticForce: Integer = 20;
Var form1: tform1; file: // The main window Form1 is appropriately changed, and BorderStyle is set to BSNONE Lastx, lasty: integer; winampRect: TRECT; hwnd_winamp: hwnd;
IMPLEMENTATION
{$ R * .dfm}
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Close; File: // Close window end;
procedure TForm1.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); const classname = 'Winamp v1.x'; file: // if the change ClassName = 'TAppBuilder', // you It will be found that even Delphi also has an extraction, begin lastx: = x; file: // Save pointer coordinate lasty: = y; hwnd_winamp: = findwindow (classname, nil); file: // Get Winamp's window handle if hwnd_winamp> 0 Then getWindowRect (hwnd_winamp, winamprect); file: // Gets the area end of the Winamp window;
procedure TForm1.FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); var nLeft, nTop: integer; begin if HiWord (GetAsyncKeyState (VK_LBUTTON))> 0 then begin nLeft: = Left X-LastX; file : // Calculate window position Ntop: = TOP Y-Lasty; if hwnd_winamp> 0 Then file: // This will modify the Magnetize (NLEFT, NTOP) file: // You can also perform screen edge docking when the window does not exist. Else Edgtize (NLSE EDGETIZE (NLEFT, NTOP); SetBounds (NLEFT, NTOP, WIDTH, Height); // Setting the window position end; end; file: / / ============= The above part is a transcription Others, below is written by ================================ / Procedure TFORM1.Magnetize (var NL, NT: Integer; var B_LR, B_TB, V_L , V_r, v_t, v_b: boolean; file: / / Defines the intermediate variable, B_LR, B_TB is used to identify the window file: / / whether the V_L, V_R, V_T, V_B is used to identify the window, respectively Near NR, NB, TL, TR, TT, TB: INTEGER; // NR, NB, respectively, to save Form1 right position and lower position Begin NR: = NL width; file: // calculate the Right, Bottom NB of Form1 : = NT Height; File: // Judgment Whether the window is within the scope of the target window (I don't know if you have a simpler algorithm) if width <= (WinampRect.right-winamprect.Left) THEN FILE: // If Form Wide less than target Form B_LR: = ((NL> = WINAMPRECT.LEFT) AND (NL <= WINAMPRECT.RIGHT) OR ((Nr> = WINAMPRECT.LE FT) AND (NR <= WINAMPRECT.Right)) ELSE B_LR: = ((NL <= WINAMPRECT.RIGHT) AND (NR> = WINAMPRECT.RIGHT) OR ((NL <= WINAMPRECT.LEFT) AND (nr> = WINAMPRECT.LEFT); if Height <= (WINAMPRECT.BOTTOM-WINAMPRECT.TOP) THEN FILE: // If Form is less than target Form B_TB: = ((NT> = WINAMPRECT.TOP) and (NT <= WINAMPRECT .Bottom) OR ((NB> = WINAMPRECT.TOP) AND (NB <= WinampRect.bottom) ELSE B_TB: = ((NT <= WINAMPRECT.TOP) and (nb> =
WINAMPRECT.TOP) OR (NT <= WINAMPRECT.BOTTOM) AND (NB> = WINAMPRECT.BOTTOM); / / Determine whether the two window is sufficient to close // calculate the distance of the border absolute value TL: = ABS (WINAMPRECT.RIGHT -nl); Tr: = ABS (WINAMPRECT.LEFT-NR); TT: = ABS (WinampRect.bottom-NT); TB: = ABS (WinAmpRect.top-Nb); v_l: = TL