Solved

Window Dragging

Posted on 2000-05-05
4
176 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
Comment Utility
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
Comment Utility
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
Comment Utility
listenning
0
 

Author Comment

by:rseve
Comment Utility
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

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

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

19 Experts available now in Live!

Get 1:1 Help Now