Solved

Window Dragging

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 112
Delphi Firemonkey Need Sample for Online Shopping Example. 2 218
Create a path if not exists 7 125
Firemonkey BASS_Init into a thread 17 84
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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