4
votes

My application does automated screenshots of several dynamically created forms. This works perfectly under Windows XP, but doesn't work well under Vista Aero. Most of the forms appear semitransparent in the screenshots. The problem lies in the window animation of Aero.

How can I check/disable/enable this animation from inside a Delphi (2007+) program?

Or as an alternative: How can I make sure the form is displayed properly before making the screenshot?

4
Not delphi but we have a similar question here stackoverflow.com/questions/280480/…Shoban
Thanks for the hint - made me search inside the VCL a bit until I found: As always, Delphi has an implementation of the DWMApi and things turned out to be as easy as setting a Boolean property.Uwe Raabe
I didn't say it "is" a property - I said it is "as easy as setting" a property.Uwe Raabe
Can you give those of us, trying to solve the same problem, a hint?Ian Boyd
A few lines below - look at my answer to my own question.Uwe Raabe

4 Answers

2
votes

The link in the comment from Shoban led me in the right direction. A quick check showed a wrapper for the DwmApi in the VCL and from that it went straight forward. Here is the code I successfully use now:

uses DwmApi;
...
  SaveDwmCompositionEnabled := DwmCompositionEnabled;
  if SaveDwmCompositionEnabled then
    DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
...
  if SaveDwmCompositionEnabled then
    DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
1
votes

Disabling Aero would be a pity - in general it's not a good idea to change the user's choice of UI style.

You may be able to draw the form another way. One thing that comes to mind is using the PaintTo method to paint it to a canvas. (In fact, if you're taking screenshots of the forms as a way of getting what it looks like you probably don't need to show the forms at all - created them with Visible set to false and paint them to a bitmap. Only show them if the user needs to interact with them.)

1
votes

I was trying to solve the same problem and found this question, but came up with a completely different solution. It doesn't disable the animation, but it allows you to make the window disappear without animation effect.

var oldWidth := Self.Width;
var oldHeight := Self.Height;
try
    if Visible and (Self.WindowState <> wsMinimized) then
    begin
        Self.BorderStyle := bsNone; // do this first
        Self.Width := 0;
        Self.Height := 0;
    end;

    //.. Do your screen capture here

finally
    if Visible and (Self.WindowState <> wsMinimized) then
    begin
        Self.BorderStyle := bsSizeable; // or whatever it was
        Width := oldWidth;
        Height := oldHeight;
    end;
end;

You could also move the window to -maxint for X & Y, but I like this better.

0
votes

You can add a manifest resource to the exe file, to notify Vista you want that the application runs without Aero http://www.google.be/search?q=vista+manifest+resource+delphi