24

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?

Community
  • 1
  • 1
Omer
  • 661
  • 7
  • 21
  • How do you notice a border less window is inactive? – Daniel Nov 15 '11 at 11:05
  • Added some photos to be more clear. – Omer Nov 15 '11 at 11:15
  • I wrote in the last paragraph "If the window has no client area the content is always rendered as inactive window", a borderless window would look like the inactive one, even if its active. – Omer Nov 15 '11 at 13:15
  • 2
    @Omer, since you want to mimic the taskbar I suppose your window has the `WS_EX_TOPMOST` and `WS_EX_TOOLWINDOW` styles? Are you calling `DwmExtendFrameIntoClientArea()` to extend glass into your client area when relying on the `WM_NCACTIVATE` trick? – Frédéric Hamidi Nov 16 '11 at 14:59
  • @Frederic, I don't use `DwmExtendFrameIntoClientArea`, I haven't got a non client area because the window has the `WS_POPUP` style. If I'll remove the `WS_POPUP` style, my window will have an unwanted caption. – Omer Nov 16 '11 at 15:10
  • @Omer, indeed, but that caption will always appear as active if you use the `WM_NCACTIVATE` trick, so maybe extending the frame will paint your client area the right color even if you don't have a visible frame to start with. You might also want to try calling `DwmExtendFrameIntoClientArea()` with `-1` margins to activate the "sheet of glass" effect and see if it changes anything. – Frédéric Hamidi Nov 16 '11 at 15:24
  • @FrédéricHamidi, I've already tried to remove the `WS_POPUP` flag and use `DwmExtendFrameIntoClientArea` and it did work good regarding color-wise but it appears really bad and not as a taskbar should be, it has rounded corners and it can be moved. My taskbar window has to be without a frame, exactly as the window's taskbar functions. – Omer Nov 16 '11 at 16:35
  • 1
    @Omer: You've said that you want to do, but you haven't said why. You seem to be trying really hard to subvert the way Windows was designed to work. What makes your app (or at least that window) special enough that users shouldn't be able to tell at a glance if it is active or not? – Merlyn Morgan-Graham Nov 17 '11 at 09:15
  • @MerlynMorgan-Graham, Just trying to create a modern desktop extension (based on an AppBar) . – Omer Nov 17 '11 at 10:28
  • You may be able to find something in the Windows 7 SDK to help you with this. – Him_Jalpert Nov 23 '11 at 17:53

1 Answers1

2

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);
    }
Jelle Vergeer
  • 1,018
  • 1
  • 17
  • 35