Windows Vista and 7 motion effects are applied only once when my form is displayed. What for?

I created an application with two forms. The first is the main form, and the second is hidden. I put the button in Form1 and I made ShowModal the second form. On Win7, a form with animation appears. Then I close the appeared form (Form2), and I press the button again. Form 2 appears without animation. I want animation every time. What should I do?

+4
source share
3 answers

The only thing I can think now is to create the form manually every time you want to display it in the text. To do this, go to the project settings and make sure that the form is not created automatically. Then do

procedure TForm1.Button1Click(Sender: TObject); begin with TForm2.Create(self) do try ShowModal; finally Free; end; end; 

In my opinion, most often modal forms should actually be created manually.

+3
source

Well, you could just not worry about that! Alternatively, a very quick hack would be to free the form every time it closes, since the animation only appears the first time the form is displayed.

EDIT: Another approach is to call DestroyHandle in your form whenever it closes. I suppose now, but I suppose that Windows is writing somewhere in the window a flag indicating that the animation has been shown. Once this flag is set, the animation is no longer displayed.

+1
source

As an alternative way, you can fool windows by sending a notification that the form style has been changed, which will reset the window to a "secret flag" for the current form handle. Thus, when showing the already created form, the animation of the show's spectacular effect will be applied again. However, I can’t say what negative consequences can be caused in this way.

 uses Winapi.Windows, Vcl.Controls; type TFormHelper = class helper for TForm public procedure Show; end; implementation procedure TFormHelper.Show; begin SendMessage(Handle,CM_CUSTOMSTYLECHANGED,0,0); inherited Show; end; 

Note : code provided using the class helper, this function / keyword may not be available in older IDEs.

0
source

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


All Articles