?
Solved

moving Controls At Run Time ( Code supplied )

Posted on 2004-10-05
2
Medium Priority
?
315 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
[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
2 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 200 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 31

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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