Tecman
Tecman

Reputation: 3009

Enabling Aero Glass in custom-drawn window title (WM_NCPAINT, DwmSetWindowAttribute)

Some years ago we developed an ActiveX component allowing the developers to place custom clickable graphical buttons into the window title bar. All works fine in any Windows except Vista and Windows 7 when Aero Glass is turned on - the title bar with our custom icons is drawn as if we used the Windows Basic theme without the transparency effect for the window borders.

People would like to use this ActiveX in the latest versions of the OS, but we cannot make it work. All searches on the Internet tell us we need to enable Aero Glass when we use custom drawing in the window title using the DwmSetWindowAttribute API call with the DWMWA_NCRENDERING_POLICY attribute, but we have not managed to make it work.

Our code that draws on the window's non-client surface looks like this (sorry - it's the old VB6 :):

Friend Function WindowProc(ByVal lPrevWndProc As Long, ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   
   Select Case iMsg

   Case WM_NCPAINT
      DoNCPaint lPrevWndProc, wParam
      WindowProc = 0
      Exit Function

   Case WM_...
      ' Other message handlers

   End Select
   
   WindowProc = CallWindowProc(lPrevWndProc, hwnd, iMsg, wParam, lParam)
End Function

We added the following call

DwmSetWindowAttribute m_hwnd, DWMWA_NCRENDERING_POLICY, DWMNCRP_ENABLED, 4

to many places in our code, but it does not have any effect. We can disable the Aero Glass effect if it is used by default in a window using DwmSetWindowAttribute, but cannot enable it.

What are we doing wrong? Do we need to add more API calls to our code, and if so where?

Upvotes: 1

Views: 2897

Answers (2)

Tecman
Tecman

Reputation: 3009

This old approach does not work in latest versions of Windows starting from Vista because of the new Desktop Window Manager (DWM) responsible for drawing the window frame. Here is also one interesting blog found in the web.archive.org that explains the nature of the problem:

Frequently asked questions about the Aero Basic window frame

The pertinent excerpt is the following:

The DWM doesn't have any legacy worries because applications cannot draw inside the glass frame, since it's rendered and managed by a totally different process. If an application tries to do it, Windows will detect it and remove the glass frame entirely (and therefore revert to the Basic frame), so that the application can draw what it wants to draw.

To modify the window title bar in Windows Vista, 7 and so on, we need to use the new DWM API.

Upvotes: 0

Dandy Cheung
Dandy Cheung

Reputation: 1

There may be a mistake on your calling, you should not pass a plain DWMNCRP_ENABLED value into the API, instead, you should pass a ref of a DWMNCRENDERINGPOLICY structure.

Upvotes: 0

Related Questions