0

I’m handling the WM_NCPAINT WinEvent for draw a pushbutton at the non client area of my window. But as you can see at the following image, the aero glass border has disappeared, and my window has no border. So I've found this answer: Handling WM_NCPAINT "breaks" DWM glass rendering on Vista/Aero and I’ve tried to apply the solution proposed on that page on my project with no result. What I’m doing wrong?

Screenshot of my window:

enter image description here

On my .pro file I’ve added:

LIBS += -lGdi32
LIBS += -lUser32
LIBS += -lDwmApi
LIBS += -lUxTheme

And here my code:

#include <windows.h>
#include <dwmapi.h>
#include <Uxtheme.h>
#include <tmschema.h>
#include <Strsafe.h>
#include <limits.h>

HTHEME m_htheme;

bool MainWindow::winEvent(MSG *pMessage, long *result)
{
    UINT m = pMessage->message;
    if(m == WM_NCPAINT || m == WM_ACTIVATE)
    {
        draw();
        return true;
    }
    return QWidget::winEvent(pMessage, result);
}

void MainWindow::draw()
{
    HWND id = winId();

    DWMNCRENDERINGPOLICY policy = DWMNCRP_ENABLED;
    HRESULT hr = DwmSetWindowAttribute(id, DWMWA_NCRENDERING_POLICY, (void*)&policy, sizeof(DWMNCRENDERINGPOLICY));

    if(SUCCEEDED(hr))
    {
        m_htheme = OpenThemeData(id, L"Button");
        if (m_htheme)
        {
            HDC hDeviceContext = GetWindowDC(id);
            RECT rc = {10, 10, 100, 32};
            RECT rcContent;

            LPCWSTR caption = TEXT("text");
            size_t cch;
            StringCchLength(caption, MAX_PATH, &cch);

            hr = DrawThemeBackground(m_htheme, hDeviceContext, BP_PUSHBUTTON, CBS_NORMAL, &rc, 0);

            if (SUCCEEDED(hr))
                hr = GetThemeBackgroundContentRect(m_htheme, hDeviceContext, BP_PUSHBUTTON,
                                                   CBS_NORMAL, &rc, &rcContent);

            if (SUCCEEDED(hr))
                hr = DrawThemeText(m_htheme, hDeviceContext, BP_PUSHBUTTON, CBS_NORMAL,
                                   caption, cch, DT_CENTER | DT_VCENTER | DT_SINGLELINE, 0, &rcContent);
        }
    }
}
Community
  • 1
  • 1
Antonio Dias
  • 2,751
  • 20
  • 40
  • 1
    I don't know Qt, but I would imagine `DefWindowProc` is not getting called and should be. – chris May 20 '13 at 17:19
  • @chris how do you think it should be used? – Antonio Dias May 20 '13 at 17:24
  • 2
    I haven't worked with this much, but calling `DefWindowProc`, then rendering your button should work. I have no clue if there's a better way. – chris May 20 '13 at 17:25
  • 1
    @chris Calling `DefwindowProc` is the typical starting point. `DrawFrameControl` and `DrawCaption` can also be used to render various parts of the non-client area such as menus, captions bars and scrollbars. – Captain Obvlious May 20 '13 at 17:52
  • By calling `DefWindowProc(id, m, NULL, NULL);` inside the WM_NCPAINT event, enables the aero interface, but not enable glass, how can i enable it? – Antonio Dias May 20 '13 at 19:44
  • Update: With `DefWindowProc(pMessage->hwnd, pMessage->message, pMessage->wParam, pMessage->lParam);` the glass is established, but the button stays behind the window. – Antonio Dias May 20 '13 at 21:09

0 Answers0