[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

To change code

Posted on 2001-07-30
6
Medium Priority
?
256 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
Technology Partners: 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 880 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

649 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