Solved

To change code

Posted on 2001-07-30
6
227 Views
Last Modified: 2010-04-06
This is a code for moving and resizing component.
I want to change it. Problem is :
 ReleaseCapture;
 (Sender as TPanel).Perform(WM_SysCommand,fSysCmd,0); //<- And here's the heart of the whole component!

I want that when I am resizing component, it is automaticliy geting new dimensions. Not by "RealeaseCapture" but with it's real new sizes. Thanks.

unit Unit1;

interface

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

type
TForm1 = class(TForm)
   Panel1: TPanel;
  procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
    Y: Integer);
  procedure FormShow(Sender: TObject);
private
   // variable to hold the value passed to WM_SYSCOMMAND...
 fSysCmd:integer;
 // variable to hold the "default" cursor, just in case it isn't "crDefault"
 fSavedCursor:TCursor;
 FEnableMoving: Boolean;
 FEnableSizing: Boolean;

 // -> Bug fix (explained below)
 fClientControl:TWinControl;
 fClientMouseMove:TMouseMoveEvent;
public

end;

var
Form1: TForm1;

implementation

{$R *.DFM}

// constants passed to WM_SYSCOMMAND
// For some reason, these are not listed in the help file,
// I had to play around a bit to find them...
const
SizeE  = $F002; // east
SizeW  = $F001; // west
SizeN  = $F003; // north
SizeS  = $F006; // south
SizeNW = $F004; // northwest
SizeNE = $F005; // northeast
SizeSW = $F007; // southwest
SizeSE = $F008; // southeast

// Drags the entire panel ...
MoveIt = $F012;

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
Edge=15; // how close to the edge do we get before saying we're "on" it? (in  pixels)
Corner=20; // the corners are a bit harder to detect, so we add some tolerance
var
P:TPoint;
re_align:TAlign;
begin
with Sender as TPanel do
begin
re_align := Align;
Align := alNone;
// Create a TPoint from from the mouse coordinates passed to the function...
P:=point(X,Y);
Form1.Caption:=IntToStr(x)+' '+inttostr(y);
// All this if-then-else stuff decides which constant will be passed to WM_SYSCOMMAND
// Here we just use some math to create a small square at each corner,
// then check to see if the mouse is within any them...
if FEnableSizing then
begin
 if ptInRect(Rect(0,0,Corner,Corner),P) then fSysCmd:=SizeNW
 else if ptInRect(Rect(0,Height-Corner,Corner,Height),P) then fSysCmd:=SizeSW
 else if ptInRect(Rect(Width-Corner,Height-Corner,Width,Height),P) then fSysCmd:=SizeSE
 else if ptInRect(Rect(Width-Corner,0,Width,Corner),P) then fSysCmd:=SizeNE

 // if it's not in a corner, then is it near an edge?
 else if (X < Edge) then fSysCmd:=SizeW
 else if ( X > (Width-Edge) ) then fSysCmd:=SizeE
 else if (Y < Edge) then fSysCmd:=SizeN
 else if ( Y > (Height-3) ) then fSysCmd:=SizeS

 // if it's none of the above, then MouseDown should drag the whole panel...
 else
   if FEnableMoving then fSysCmd:=MoveIt
   else fSysCmd := 0;
end
 else
   if FEnableMoving then fSysCmd:=MoveIt
   else fSysCmd := 0;

// Now that we have the correct system command, we can use its
// value to determine which screen cursor to display...
case fSysCmd of
 SizeE,SizeW:Cursor:=crSizeWE;
 SizeN,SizeS:Cursor:=crSizeNS;
 SizeNE,SizeSW:Cursor:=crSizeNESW;
 SizeNW,SizeSE:Cursor:=crSizeNWSE;
 MoveIt:if (ssLeft in Shift) then Screen.Cursor := crSizeAll
        else begin
          Screen.Cursor := crDefault;
          Cursor := crDefault;
        end;
 else Cursor:=crDefault;
end;
if (ssLeft in Shift) then
begin
 ReleaseCapture;
 (Sender as TPanel).Perform(WM_SysCommand,fSysCmd,0); //<- And here's the heart of the whole component!
end;
Align := Re_align;
end
end;

procedure TForm1.FormShow(Sender: TObject);
begin
fsyscmd:=0;
fenablesizing:=True;
fenablemoving:=True;
end;

end.
0
Comment
Question by:cvbmn
6 Comments
 
LVL 21

Expert Comment

by:gemarti
ID: 6335412
You have to SetCapture First then ReleaseCapture;
0
 

Author Comment

by:cvbmn
ID: 6335571
How to use it ? Can you give me some example ? Thanks.
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6335635
Maybe in an OnMouseDown Event?

SetCapture(panel1.handle);

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
vbmn earned 220 total points
ID: 6336531
Use examples in EForumLib from

http://www.devexpress.com

Register and you'll get on E-Mail password and site from where you can download it.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6336715
// Why you cannot tell to window do the work.
// All you need it override WM_NCHITTEST message.

Example:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Type
 TMyPanel = class(TPanel)
 private
  procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
 End;


{ TMyPanel }

procedure TMyPanel.WMNCHitTest(var Msg: TWMNCHitTest);
Const
 Border = 3;

Var
 P : TPoint;
begin
 With Msg Do Begin
  Result := HTCAPTION;

  P := ScreenToClient(Point(XPos, YPos));

  If P.Y < Border Then
   Result := HTTOP;

  If P.Y > Height - Border Then
   Result := HTBOTTOM;

  If (P.X < Border) Then
   If P.Y < Border Then Result := HTTOPLEFT
   Else If P.Y > Height - Border Then Result := HTBOTTOMLEFT
        Else Result := HTLEFT;

  If (P.X > Width - Border) Then
   If P.Y < Border Then Result := HTTOPRIGHT
   Else If P.Y > Height - Border Then Result := HTBOTTOMRIGHT
        Else Result := HTRIGHT;
 End;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 With TMyPanel.Create(Self) Do Begin
  Parent := Self;
  SetBounds(20, 20, 300, 100);
 End;
end;


end.

0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6336758
listening...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question