Solved

moving Controls At Run Time ( Code supplied )

Posted on 2004-10-05
2
309 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now