Solved

Window Dragging

Posted on 2000-05-05
4
179 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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