Solved

To change code

Posted on 2001-07-30
6
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

689 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