5

I have looked everywhere to see how to use Aero in my program. I fail to find any C function that previews the windows behind your own, like File Explorer or any mainstream browser does on their title bars.

Some programs fake it by just adding an image that looks like the Windows 7 title bar -- without Aero -- but I consider it kind of cheating. I found this code on the link below:

[DllImport ("dwmapi.dll" Entry Point = "# 113", SetLastError = true)] 

internal static external DwmpActivateLivePreview uint (uint a, IntPtr b, uint c, uint d); 

[DllImport ("dwmapi.dll" Entry Point = "# 105", SetLastError = true)]

internal static bool external DwmpStartOrStopFlip3D (); 

// Activate Aero peek into the desired Handle 
DwmpActivateLivePreview (1, Handle, 0, 1);

// Disable Aero peek
DwmpActivateLivePreview (0, Handle, 0, 1);

// start or stop the Aero Flip 3D
DwmpStartOrStopFlip3D ();

But have no idea what it means. Is the implementation of Aero Peek, automatically function with the PreviewWindows(or whatever) function?

I'm lost.

This link is in Dutch, just run it through Google Translate

I am not trying to toggle whether or not Aero Peek and/or Flip is activated, or change the icon for my application when the mouse hovers on its taskbar icon. I am instead looking for a function that takes the current screen state of applications behind my own and returns it as an image for display in my application. As a bonus, does the (presumably) returned image come blurred, or is that effect that is separately applied? I think the name for it is Aero Glass.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Code Monkey
  • 889
  • 3
  • 11
  • 27
  • 1
    I'm still trying to figure out why this all works fine in C#, but I can't for the life of me get any working in C++ (via `LoadLibrary` and `GetProcAddress`). – chris Oct 04 '12 at 02:08
  • 1
    Are you referring to the images that are returned when you mouse over their thumbnail previews and when you Alt+Tab between windows? – BoltClock Oct 28 '12 at 18:52
  • @BoltClock No, I believe the more accurate name of what I am looking for is Aero Glass. – Code Monkey Oct 28 '12 at 18:54
  • 1
    Ah. Aero Peek is what happens when you reveal the desktop behind all open windows, and those images are window previews. The part of the window frame that's blurred is indeed Aero Glass, but I'm not aware if there's a function that returns the region that's covered by your window's glass area... – BoltClock Oct 28 '12 at 18:56
  • There is screen capture software that is able to capture only those specific areas, but I believe they're simply taken from the screen as they were rendered (complete with blur and window colorization color). – BoltClock Oct 28 '12 at 18:59
  • @BoltClock How do you specify the "glass area"? I think Aero would do the rest if the glass area is truly a rectangle that Aero draws the background windows to. – Code Monkey Oct 28 '12 at 18:59
  • That is something I'm not too sure about either. – BoltClock Oct 28 '12 at 19:00
  • 1
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa969537%28v=vs.85%29.aspx – Hans Passant Oct 28 '12 at 19:13
  • Actually, I think http://msdn.microsoft.com/en-us/magazine/cc163435.aspx might be exactly what I'm looking for. Any additions to that article? – Code Monkey Oct 28 '12 at 19:20
  • @HansPassant That's another enable/disable function, I'm looking for a call. It was very helpful, though. +1. – Code Monkey Oct 28 '12 at 19:22

2 Answers2

1

As I understand you want to get the state (in terms of the display) of the windows behind your application. You can achieve it by doing the following,

HWND hwnd_behind = GetNextWindow(your_window_handle, GW_HWNDNEXT);

HDC hdc = GetWindowDC(hwnd_behind);

RECT rect;
GetWindowRect(hwnd_behind,rect);

HDC bitmap = MakeABitMapDC();

StretchBlt(bitmap,0,0,dW,dH,hdc,0,0,rect.width,rect.height,SRCCOPY);

You can plug this code into handlers which returns the bitmap when windows asks applications for a preview bitmap.

Left the details like "MakeABitMapDC" for the sake of brevity.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
nanda
  • 804
  • 4
  • 8
  • No. GetWindowDC, in non-aero mode, would return some virtual DC which would basically refers to the portion of the screen that is occupied by that window. That means if window 1 is on top and window 2 is below it at the same XY, GetWindowDC of both the window would return a DC whose content would be the same - which is content of window 1. – nanda Oct 31 '12 at 17:04
0

I am lost is kinda a big area to see what you don't understand but I will try anyway.

If mean that you don't know what the parameters do in the:

[DllImport ("dwmapi.dll" Entry Point = "# 113", SetLastError = true)] 
internal static external DwmpActivateLivePreview uint (uint a, IntPtr b, uint c, uint d); 

It is basically like this:

  • a: Is the parameter for activating Aero Peek.
  • b: Is the handle the AeroPeek focusses too.
  • c: Is a tricky one. If you pass a handle of a window to that parameter and the TopMost property is set it will appear on top of the AeroPeek.
  • d: I have no idea what d does but the times i have used DwmpActivateLivePreview I always put it on 1.

So the signature is like this:

internal static extern uint DwmpActivateLivePreview(uint active, IntPtr handle, IntPtr onTopHandle, uint d);

The DwmpStartOrStopFlip3D method activates the "Windows + Tab" effect.

[DllImport("dwmapi.dll", EntryPoint = "#105", SetLastError = true)]
internal static extern bool DwmpStartOrStopFlip3D();

Remember though that there is a reason that they are undocumented since they were not meant for us to use them.

If by chance you want to have the Aero Peek effect inside your application you can look at the DwmSetIconicLivePreviewBitmap function located in DWM.

More information here: MSDN: DwmSetIconicLivePreviewBitmap function

Rutix
  • 861
  • 1
  • 10
  • 22
  • 1
    Yeah, undocumented functions are great for playing around with, but please don't ever use them in anything beyond that. Windows has a ton of dead and/or useless code hanging around because they need to keep people's apps running when they don't listen. – chris Oct 06 '12 at 01:47