4

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?

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • 3
    Not delphi but we have a similar question here http://stackoverflow.com/questions/280480/enabling-disabling-aero-from-a-windows-service – Shoban Jul 16 '09 at 12:59
  • 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 Jul 17 '09 at 07:07
  • I didn't say it "is" a property - I said it is "as easy as setting" a property. – Uwe Raabe Dec 05 '09 at 12:15
  • Can you give those of us, trying to solve the same problem, a hint? – Ian Boyd Dec 07 '09 at 21:14
  • A few lines below - look at my answer to my own question. – Uwe Raabe Dec 08 '09 at 07:41

4 Answers4

2

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);
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • 1
    i really don't like this solution; disabling Desktop Composition isn't something i would want anyone else who finds this question to do. i assume the animation time is configurable in the system, but assume it's 200ms. Start a 200ms timer during OnShow to take a screenshot then. If the timer is still running when OnClose fires, then take a screenshot then. – Ian Boyd Dec 04 '09 at 16:44
  • That is indeed a possibility. Althoug, I wouldn't do it in my case as it would increase the time used a lot, just because of the shear number od the screenshots to take. But at least it is an option. – Uwe Raabe Dec 05 '09 at 12:18
1

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.)

David
  • 13,360
  • 7
  • 66
  • 130
  • The screenshots are taken during an automated build. So the user won't bother at all. But the idea using PaintTo sounds interesting... – Uwe Raabe Jul 17 '09 at 06:50
1

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.

Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
0

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

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67