Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force Aero to draw a borderless window as if it were active, even if it's not?

I'd like to have the same effect as the windows 7 taskbar.
I've looked in this question: Keep Window Looking Active
It works great but only if the window has a non-client area.

My window is border-less and the content of it (just a black background) is rendered as it is inactive, no matter what I do.

I've set my window flags just as Windows 7 taskbar but it didn't help.

My only thought at the moment is to draw it with borders and just clip them, is there a better way to achieve what I want?

EDIT 1:
Clipping didn't work, after clipping the borders the window content was rendered as inactive window. How the hell does windows 7 task-bar works then?

EDIT2:
Adding some photos to explain myself better, The following window content is a black background.

That's an inactive window (the content is rendered kinda dark): Inactive window

That's an active window:
Active window

If the window has no client area the content is always rendered as inactive window however the windows Taskbar is always rendered as active window and it doesn't have any NC area (at least according to spy++). That's what I'm trying to mimic.

EDIT3:
Sharing my recent discoveries. explorer.exe main window is frameless and has the following flags: Explorer image parameters

I dived into the explorer's process dwmapi.dll exported functions: Explorer dwmapi.dll exported functions

it uses DwmEnableBlurBehindWindow, just as I do.
I've checked the undocumented ordinal functions and none of them is related to rendering the aero glass as active.

Could it be the DWM rules don't apply to explorer?

like image 819
Omer Avatar asked Nov 15 '11 08:11

Omer


1 Answers

Tricky one..
set the NCRenderingPolicy to Enabled with the "DwmSetWindowAttribute" API.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa969524(v=vs.85).aspx

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

    [Flags]
    public enum DwmWindowAttribute
    {
        NCRenderingEnabled = 1,
        NCRenderingPolicy,
        TransitionsForceDisabled,
        AllowNCPaint,
        CaptionButtonBounds,
        NonClientRtlLayout,
        ForceIconicRepresentation,
        Flip3DPolicy,
        ExtendedFrameBounds,
        HasIconicBitmap,
        DisallowPeek,
        ExcludedFromPeek,
        Last
    }

    [Flags]
    public enum DwmNCRenderingPolicy
    {
        UseWindowStyle,
        Disabled,
        Enabled,
        Last
    }

    public static bool SetNCRenderingActive(IntPtr Handle)
    {
        int renderPolicy = (int)DwmNCRenderingPolicy.Enabled;            
        return (DwmSetWindowAttribute(Handle, (int)DwmWindowAttribute.NCRenderingPolicy, ref renderPolicy, sizeof(int)  ) == 0);
    }
like image 122
Jelle Vergeer Avatar answered Nov 14 '22 06:11

Jelle Vergeer