Getting rid of the initial flash of a WS_MAXIMIZE child

Getting rid of the initial flash of a WS_MAXIMIZE child

How can I open an MDI child form so that it’s initially in a maximized state? Every time I try, it appears in its normal size, then maximizes visibly. I can’t hide it because Delphi won’t let me, and if I trick it by hiding it in CreateParams, it’s maximized for a split second (just after OnShow()), then is reduced to normal size, then is re-maximized. This is all happening somewhere after OnShow() and I can’t seem to stop it … I just need it to open already maximized, and all ready to go. … Help!

One thing you might have noticed is that child forms set with thewsMaximized property have a visible flash when they’re first created.First they’re created in a normal state, then they maximize. This is moreannoying than problematic.

For those of you who are experienced inmucking about with form properties, you might think that setting the form’swindow style to WS_MAXIMIZE in the CreateParams method would do the trick.Alas, that doesn’t work either. But don’t worry, there’s a verysimple solution.

One of the ways you can prevent the user from seeing background operationson a window is to prevent it from painting, then having it refresh after thechanges have been made. To the user, it will appear as if the screen wasautomagically changed in the blink of an eye. With respect to opening up amaximized MDI child form in an MDI application, this is exactly the type ofthing we’re going to do.

The specific function that allows us to prevent screen painting is a WinAPIfunction called LockWindowUpdate. LockWindowUpdate takes a singleparameter ? the handle of the window ? and prevents it from painting untilLockWindowUpdate is called again with a parameter of ‘0.’ So, with respectto our particular problem, to prevent a maximized MDI child from flashing atcreate, you enclose its create statement between two LockWindowUpdate callslike so:

LockWindowUpdate(MyMDIMainForm.Handle);MyMDIChild := TMyMDIChild.Create(Application);LockWindowUpdate(0);
Pretty simple, huh? Notice that I locked the screen painting with respectto the MDI form, not the MDI child. That’s important, because if you tried tolock the update for the child, you’d get an error because the handle isinvalid. In any case, use this technique for all your MDI applications toavoid the initial flash.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several