Delphi - creating hidden MDI child forms

There are many different forms of mdi in my application, and they are created after a successful user login. How can I better hide this creation process? It looks stupid and takes longer, while mdi forms get tinted after creating a new form, etc.

So far I have used LockWindowUpdate, which does not hide everything, but I would like to use a splash screen showing the progress of creation, but I can not with LockWindowUpdate.

Best regards Janne

+4
source share
3 answers

To create invisible MDI child forms, you set your Visible property to False and, in addition, you need to disable the VCL behavior that shows their strength at creation time. This is done using the FormStyle TCustomForm property installer, which sets Visible to True for MDI child forms.

If you set the FormStyle parameter in the object inspector, then a property identifier will already be created at the time the form is created, and the form will not be shown immediately, but only after the construction is completed. This allows you to reset the request to show the form by overriding the AfterConstruction() method as follows:

 procedure TMDIChild.AfterConstruction; begin Exclude(FFormState, fsVisible); inherited; end; 

This will create an invisible MDI child form.

To verify this, you can create a new MDI application in the IDE, override the method in the child form class, as shown above, and simulate a lengthy initialization:

 procedure TMainForm.FileNew1Execute(Sender: TObject); var i: integer; begin for i := 1 to 10 do begin CreateMDIChild('NONAME' + IntToStr(MDIChildCount + 1)); Update; Sleep(500); end; for i := 0 to MDIChildCount - 1 do MDIChildren[i].Visible := True; end; 

Without an overridden AfterConstruction() method, it will create and display child MDIs every half second. Using the overridden method, it will display them all after a busy period of 5 seconds, which will give you the opportunity to display your splash screen.

Important:

Using LockWindowUpdate() to reduce flickering or suppress the output of any screen is wrong, wrong, wrong. Don't do this ; read the Raymond Chen series of articles on this topic to understand why this is.

+7
source

I had a similar problem with flickering MDI kids. I used the combination of AfterConstruction and WM_SETREDRAW wrappers from this tip : Managing the layout of fsMDIChild windows in Delphi

 SendMessage(Application.MainForm.ClientHandle, WM_SETREDRAW, False, 0); try Child := TChildForm.Create(Self); Child.Left := ...; Child.Top := ...; Child.Show; finally SendMessage(Application.MainForm.ClientHandle, WM_SETREDRAW, True, 0); InvalidateRect(Application.MainForm.ClientHandle, nil, True); end; 

And everything is working fine.

0
source

try this code, it works for me

  try SendMessage(Application.MainForm.ClientHandle,WM_SETREDRAW,0,0); FormChild:=TBaseChildForm.Create(application); FormChild.Caption:='Form '+IntToStr(n); FormChild.Show; finally SendMessage(Application.MainForm.ClientHandle,WM_SETREDRAW,1,0); RedrawWindow(Application.MainForm.ClientHandle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_NOINTERNALPAINT); end; 
0
source

Source: https://habr.com/ru/post/1307541/


All Articles