Re:how to stop a window moving?
Handle the WM_NCHittest and change the HTCaption to HTNowhere, an example:
{This doesn't allow a form to be moved if the screen resolution is > 800X600.
Since yours is bsDialog, you won't need the DeleteItemsFromSysMenu call}
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
procedure Exit1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DontMove(var Msg : TMessage); message WM_NCHITTEST;
procedure DeleteItemsFromSysMenu;
end;
var
Form1: TForm1;
implementation
//uses Unit2;
{$R *.DFM}
procedure TForm1.DeleteItemsFromSysMenu;
var
SysMenuHwnd : THandle;
i : integer;
begin
SysMenuHwnd := GetSystemMenu(Form1.Handle, False);
// Have to be done in reverse order because if not the
// numbering would be different each time the function
// is called.
for i := 6 downto 0 do
DeleteMenu(SysMenuHwnd, i, MF_BYPOSITION);
end;
procedure TForm1.DontMove(var Msg : TMessage);
var
bAllowMove : Boolean;
begin
bAllowMove := (Screen.Width >= 800);
inherited;
if (Msg.Result <> htReduce) and (Msg.Result <> htClose) and
(Msg.Result <> htSysMenu) then
if (Msg.Result = htCaption) and (not bAllowMove) then
Msg.Result := htNowhere;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
DeleteItemsFromSysMenu;
end;
end.
Quote
> how can i prevent a window being moved?
> bsDialog and fsStayOnTop, so it can only be moved by the mouse.
> it seems to me i have to provide special WndProc / WM handling, but that's
> where i get lost.