简体   繁体   English

处理 ON_WM_NCPAINT() 消息和 OnNCPaint() 覆盖的问题。 (覆盖默认 MFC window 边框)[2020]

[英]Issues with handling ON_WM_NCPAINT() message and OnNCPaint() override. (Overriding default MFC window border) [2020]

I'm attempting to create a "dark mode" theme for my Windows app, and I'm experiencing some inconsistencies with overriding the OnNcPaint() function.我正在尝试为我的 Windows 应用程序创建一个“暗模式”主题,并且在覆盖 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:这是我最初的 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:和(通常的)结果: 默认

I can partially resolve this issue by removing the call to Default();我可以通过删除对Default(); : 没有默认值

...But anytime the window is moved(or redrawn I guess): ...但是任何时候 window 被移动(或重绘我猜): 边框重绘自身

I can also add a Sleep(1000);我还可以添加一个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();我知道Default(); is some kind of threaded callback function, but I have no idea how to troubleshoot this issue any further.是某种线程回调 function,但我不知道如何进一步解决此问题。

Do I need to perform some kind of wait for the Default();我是否需要等待Default(); command?命令? Do I need to implement OnNcPaint() as some kind of callback function?我是否需要将OnNcPaint()实现为某种回调 function? Are there additional functions I need to be overriding?我需要覆盖其他功能吗?

As @dxiv said that, please handle WM_NCACTIVATE message,正如@dxiv 所说,请处理WM_NCACTIVATE消息,

Like this(under win32),像这样(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.如有必要,您可以额外处理WM_ERASEBKGND消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM