Solved

Resizing MDIChild

Posted on 1998-08-12
13
281 Views
Last Modified: 2010-04-04
I need to perform some actions when my MDIChild is resized (move controls and so on). But, if I write it in its OnResize event, it is called three times until the window stops resizing. It doesn't happen with normal windows. Help!

Thanks.
0
Comment
Question by:Stern
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1361940
Strange!? It doesn't do that on my testapp.
Could you send us the code for the OnResize event?

/// John
0
 

Author Comment

by:Stern
ID: 1361941
I can't get the code in the moment, 'cause it's on another computer, but it's just a call for a procedure I use to position something on the form. Usually it works OK, but when resizing... I tried to trace, and it always comes three times into this event. I don't know, why.
0
 
LVL 1

Expert Comment

by:pjdb
ID: 1361942
3 makes sense : one at the begining, then one for the width and one for the height.
instead of using width and height properies use the SetBounds methods.

JDB
0
 

Author Comment

by:Stern
ID: 1361943
Sorry, it's not clear for me. When, for example, a window is rerstored, or user resizes it with the mouse, how can I control it?
0
 

Author Comment

by:Stern
ID: 1361944
Sorry, it's not clear for me. When, for example, a window is rerstored, or user resizes it with the mouse, how can I control it?
0
 
LVL 2

Expert Comment

by:333
ID: 1361945
Stern,
Instead of OnResize try :

.
procedure WMSizing(var Msg:TMessage); message WM_SIZING;
.

procedure TForm2.WMSizing(var Msg:TMessage);
begin
   {Call for your procedure}
end;

I have tested this and there was just one call to this event.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:pjdb
ID: 1361946
Instead of using something like
Left:=MyLeft;
Top:=MyTop;
Width:=MyWidth;
Height:=MyHeight;

use
SetBounds(MyLeft, MyTop, MyWidth, MyHeight);

The final effect is excatly the same but all the modification are made in one time.
0
 

Author Comment

by:Stern
ID: 1361947
333,
I tried to use WMSizing, but it's called ONLY when user resizes the window dragging one of its bounds, and it isn't called when maximizing/restoring. WM_SIZE suits then, but - the strange thing - it's OK when window's size becomes larger. When width or height becomes smaller, it's always three calls. I thought, WM_SIZE happens after the window is resized, but now I don't know.
0
 
LVL 2

Expert Comment

by:333
ID: 1361948
Stern,
try to use both WMSize and WMSizing procedures:
.
procedure WMSizing(var Msg:TMessage); message WM_SIZING;
procedure WMSize(var Msg:TWMSize); message WM_SIZE;
.
procedure WMSize(var Msg:TWMSize);
begin
   if Msg.SizeType>0 then
     {Call for your procedure}
end;

procedure TForm2.WMSizing(var Msg:TMessage);
begin
    {Call for your procedure}
end;

If SizeType=0, it means that the window is resized by dragging its bounds.
If SizeType>0, the window is minimized, maximized or restored.

AP
0
 

Author Comment

by:Stern
ID: 1361949
I feel, I'm becoming really stupid with this problem. What should I write in WMSizing? When I write it just as you told, the window doesn't resize when dragging it's bounds.
0
 
LVL 2

Expert Comment

by:333
ID: 1361950
OK,
this is my program's Unit2 (MDIChild Form). If you maximize window, then Label1 displays 'Maximized', and when you drag bounds of window, then it displays 'Resizing'.

------------------------------
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm2 = class(TForm)
    Label1: TLabel;
  private
    { Private declarations }
  public
    procedure WMSize(var Msg:TWMSize); message WM_SIZE;
    procedure WMSizing(var Msg:TMessage); message WM_SIZING;
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.WMSize(var Msg:TWMSize);
begin
  if Msg.SizeType>0 then
     Label1.Caption:='Maximized';   {Or in your case the code that changes position of your elements}
end;

procedure TForm2.WMSizing(var Msg:TMessage);
begin
  Label1.Caption:='Resized';  {Or in your case the code that changes position of your elements}
end;

end.
------------------------------

Just change the lines 'Label1.Caption:=...' to what you need.

P.S. If you don't understand, maybe can you post code so I can explain more.

AP
0
 

Author Comment

by:Stern
ID: 1361951
Strange! I did all the same, and it didn't work. And now I did it once more in my app, and it didn't work. But then I made a new project, which only contained this MDIChild and these two procedures, and it works! So, the problem is somewhere in my app. I'll look for it now.

Thank you very much, and make your comment an answer, so that I can give you these points.

Stern
0
 
LVL 2

Accepted Solution

by:
333 earned 50 total points
ID: 1361952
...
procedure WMSizing(var Msg:TMessage); message WM_SIZING;
procedure WMSize(var Msg:TWMSize); message WM_SIZE;
.
procedure WMSize(var Msg:TWMSize);
begin
if Msg.SizeType>0 then
   {Call for your procedure}
end;

procedure TForm2.WMSizing(var Msg:TMessage);
begin
   {Call for your procedure}
end;

If SizeType=0, it means that the window is resized by dragging its bounds.
If SizeType>0, the window is minimized, maximized or restored.

AP
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 270
HTML text in the body of an email (delphi code) 12 95
Magic Software info 18 124
JAudiorecorder record freezing the app 29 59
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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