I'm attempting to create a "dark mode" theme for my Windows app, and I'm experiencing some inconsistencies with overriding the OnNcPaint() function. Please pardon the giant red box. I'm only coloring it in that way to show the issue.

Here's my initial function:

void CSoftwareDlg::OnNcPaint() {
    Default(); //I can also use "CDialgoEx::OnNcPaint();" here for the same result because it just calls "Default..."

    CDC* pDC = GetWindowDC();
    CRect rect;
    GetWindowRect(&rect);
    rect.top = 0;
    rect.left = 0;
    rect.bottom = rect.Size().cy;
    rect.right = rect.Size().cx;
    pDC->FillRect(rect, &m_brushRed);
    
    ReleaseDC(pDC);
}

And the (usual) result: with Default

I can partially resolve this issue by removing the call to Default();: without Default

...But anytime the window is moved(or redrawn I guess): border redraws itself

I can also add a Sleep(1000); to achieve somewhat different results, but it's not worth posting a picture. Ultimately... My override isn't really "overriding" as it should based on the numerous pieces of sample code I've taken a look at. I know that Default(); is some kind of threaded callback function, but I have no idea how to troubleshoot this issue any further.

Do I need to perform some kind of wait for the Default(); command? Do I need to implement OnNcPaint() as some kind of callback function? Are there additional functions I need to be overriding?

1

There are 1 answers

0
Strive Sun On

As @dxiv said that, please handle WM_NCACTIVATE message,

Like this(under win32),

 case WM_NCACTIVATE:
    {
        // Paint the non-client area now, otherwise Windows will paint its own
        RedrawWindow(hWnd, NULL, NULL, RDW_UPDATENOW);
    }
        break;

Not sure if your client area also needs to maintain the same color.

If necessary, you can additionally handle the WM_ERASEBKGND message.