Solved

Window Dragging

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

636 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