Avoid new MDI child resizing animation (and delay) in Delphi MDI applications

Source: Internet
Author: User

Avoid new MDI child resizing animation (and delay) in Delphi MDI applications

Lock (prevent) window updating when creating new MDI child forms
By Zarko Gajic

 

If you are creating MDI applications using Delphi, you must have noticed some "quirks" or issues that you cannot simply handle/fix from your code.

 

MDI interface was designed in the days of Windows 3 (some 10 + years ago) and it was designed with a single type of application in mind: A parent window that hosts multiple instances of the same class of "document" window (just think of you first MS word ).

 

Nasty MDI child resizing Animation

When creating (to show) An MDI child an animation of resizing will take place. This animation might look ugly if the code executed during the creation of your MDI child takes some time to process.

Even if windowstate property was set to wsmaximized when an MDI child is created it will be created using default pos at X, Y coordinates where you left your form at design time.

Windows simply insists on creating MDI children visible and at a default position.

After creation, the MDI child will get maximized but an uugly animation will take place.

 

Quickly create MDI children-Eliminate "Create & resize" Animation


To eliminate the MDI child creation and resizing animation you can send a special message to the MDI parent form, wm_setredraw. the wm_setredraw can be sent to a window to enable changes in that window to be redrawn or to prevent changes in that window from being redrawn.
To prevent the animation flicker, have the next code in your MDI parent form's unit:

 

Tmdimainform = Class (tform)
Private
Flockclientwindowupdatecount: integer;
Public
Constructor create (aowner: tcomponent); override;
Procedure lockclientwindowupdate;
Procedure unlockclientwindowupdate;
End;

...

 

Constructor tmdimainform. Create (aowner: tcomponent );
Begin
Inherited create (aowner );
Flockclientwindowupdatecount: = 0;
End;

 

Procedure tmdimainform. lockclientwindowupdate;
Begin
If flockclientwindowupdatecount = 0 then sendmessage (clienthandle, wm_setredraw, 0, 0 );
INC (flockclientwindowupdatecount );
End;

 

Procedure tmdimainform. unlockclientwindowupdate;
Begin
Dec (flockclientwindowupdatecount );
If flockclientwindowupdatecount = 0 then
Begin
Sendmessage (clienthandle, wm_setredraw, 1, 0 );
Redrawwindow (clienthandle, nil, 0, rdw_frame or rdw_invalidate or rdw_allchildren or rdw_nointernalpaint)
End
End;

 

Now, when you need to create (and show) An MDI client form (s), just call lockclientwindowupdate and unlockclientwindowupdate.
If a client window takes some time to create, you can change the cursor to let the user something (form creation) is going on:

 

Lockclientwindowupdate;
Screen. cursor: = crhourglass;
Try
Application. createform (mdichildform );
Finally
Screen. cursor: = crdefault;
Unlockclientwindowupdate;
End;

 

That's it. Now your MDI child forms will load faster and without the confusing animation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.