Solved

To change code

Posted on 2001-07-30
6
216 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 56
Delphi application Soap connection 5 96
Base1 Encode/Decode 3 68
Delphi Ado Query To Converts Joined Columns Into Rows Based on Primary Key 4 39
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now