Solved

moving Controls At Run Time ( Code supplied )

Posted on 2004-10-05
2
312 Views
Last Modified: 2010-04-05
I need some assistance on the following code:
It is used to "Move Controls" at "Run Time".

With this code in place, you are able to move not only the Controls.
But the Form as well. And I DO NOT want the form to move in the
Project that this code is going to be used in.
I am going to use it as a basis of a "Desktop" type of program.
So, like your Desktop, it does not move.

Anyway, can someone please assist me in the following code.?
I just want the Control that " I Specify " to be moved at "Run Time"

Thank you All
Carrzkiss

//=========Code Start=============\\
unit Unit1;

interface

uses
  Windows,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls, Menus, registry;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    ListBox1: TListBox;
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

const
  SC_SIZE = $F012;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  iTemp: Integer;
  r : TRegIniFile;
begin
  (* Open the key in the registry where we store all the positions *)
  r := TRegIniFile.Create('Resize Test');

  (* Loop through all the components on a form *)
  for iTemp := 0 to ComponentCount -1 do
    (* Get the position of all controls *)
    if Components[iTemp] is TControl then
    with Components[iTemp] as TControl Do
    begin
      left:=r.readinteger(Name,'Left',left);
      top:=r.readinteger(Name,'Top',Top);
      (* Make there cursors crosses *)
      cursor:=crCross;
    end;
  (* Release the registry object *)
  r.free;

  (* Use our own message handler for all message sent to the application *)
  Application.OnMessage := AppMessage;
end;

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  (* Only do anything if the left mouse button is pressed *)
  if  msg.message = wm_LBUTTONDOWN then
  begin
   (* Release the mouse capture *)
   WinProcs.ReleaseCapture;
   (* Send a message to the control under the mouse to go into move mode *)
   postmessage    ( msg.hwnd,WM_SysCommand, SC_SIZE, 0 );
   (* Say we have handled this message *)
   Handled:=true;
  end;
end;


procedure TForm1.FormDestroy(Sender: TObject);
var
  iTemp: Integer;
  r : TRegIniFile;
begin
  (* As in the form create loop through all the components But this *)
  (* time write the left and top properties to the registry         *)

  r := TRegIniFile.Create('Resize Test');
  for iTemp := 0 to ComponentCount -1 do
    if Components[iTemp] is TControl then
    with Components[iTemp] as TControl Do
    begin
      r.writeinteger(Name,'Left',left);
      r.writeinteger(Name,'Top',Top);
    end;
  r.free;
  end;
end.
//===========End of Code==============\\


0
Comment
Question by:Wayne Barron
2 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 12235204
Hi,

Perhaps you could check if the control under the mouse is the form itself or not:

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  (* Only do anything if the left mouse button is pressed *)
  if  msg.message = wm_LBUTTONDOWN then
  begin
    if msg.hwnd <> Form1.Handle then begin // <- added
     (* Release the mouse capture *)
     WinProcs.ReleaseCapture;
     (* Send a message to the control under the mouse to go into move mode *)
     postmessage    ( msg.hwnd,WM_SysCommand, SC_SIZE, 0 );
     (* Say we have handled this message *)
     Handled:=true;
    end;  // <- added
  end;
end;

Regards, Geo
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12236816
Hello [geobul];

  Great, great work.

  I have an unlimited amount of control on the forms that are to stay
In there default position. And having to add in each control when designing
Could be a little tedious (to say the least), But atleast everything is working like it suppose too.

  Thank you very much.
Carrzkiss
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
FMX StringGrid1->Canvas->FillRect Problem 3 171
Multiple image collision 13 80
Dynamically Created Query 3 62
scroll down TListBox component in Delphi 1 19
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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