Solved

Window Dragging

Posted on 2000-05-05
4
177 Views
Last Modified: 2012-05-04
How do I prevent a window (form) from being dragged & also ensure that it is centered on the screen under all conditions
0
Comment
Question by:rseve
4 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2782639
hi,
this should do it:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)

    { Private declarations }
procedure WMMouseActivate(var Msg: TWMMouseActivate); message WM_MOUSEACTIVATE;
procedure WmNCHitTest(var Msg :TWMNCHitTest); message WM_NCHITTEST;
    procedure FormCreate(Sender: TObject);
   public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMMouseActivate(var Msg: TWMMouseActivate);
 begin
  Msg.Result := MA_NOACTIVATE;
end;

procedure TForm1.WmNCHitTest(var Msg: TWMNCHitTest);
begin
  DefaultHandler(Msg);
  if Msg.Result = HTCAPTION then
    Msg.Result := HTNOWHERE;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 form1.position := poScreencenter;
 form1.borderstyle := bsdialog;
end;

end.



0
 
LVL 4

Expert Comment

by:mhervais
ID: 2782701
here is a simple example

1) create a new application
2) on your form set the position attribute to poscreencenter

then try this :
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
    myLeft : integer;
    MyTop : Integer;
    formcreated : boolean;
    procedure FormMoved(var Message : TMessage); message WM_MOVE ;
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.FormMoved(var Message : TMessage) ;
begin
  if not formcreated then exit;
  message.Result := 1;
  Left := MyLeft;
  Top := Mytop;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyLeft := Left;
  MyTop := Top;
  formcreated := true;
end;

end.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2782757
listenning
0
 

Author Comment

by:rseve
ID: 2783507
Thanks inthe,
works perfectly, looking at the answers of prev questions, I'd say with your experience you should be writing a book

Cheers !
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

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

862 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

23 Experts available now in Live!

Get 1:1 Help Now