Solved

To change code

Posted on 2001-07-30
6
210 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
Comment Utility
You have to SetCapture First then ReleaseCapture;
0
 

Author Comment

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

Expert Comment

by:gemarti
Comment Utility
Maybe in an OnMouseDown Event?

SetCapture(panel1.handle);

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Accepted Solution

by:
vbmn earned 220 total points
Comment Utility
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
Comment Utility
// 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
Comment Utility
listening...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now