在分层 window 的子对话框中时未单击 CMFCButton

CMFCButton not clicked when in a child dialog of a layered window

背景:

问题:

在分层 window 区域内单击,使对话框没有焦点,然后尝试单击对话框上的按钮。按钮不会响应事件。

备注:

如果按钮只是 CButton,那么它可以正常工作。有人可能会说对话框需要有焦点才能工作,但在任何其他情况下都不是这种情况。通常,当我单击对话框上的按钮时,它总是有效,即使我之前关注的是一个完全不同的程序。

代码:

分层的创建函数window:

bool CLayerWnd::Create()
{
    if (!__super::CreateEx(WS_EX_LAYERED, DEMOLAYEREDCLASS, _T("Layered Window"), WS_POPUP, 200, 200, 500, 500, ::GetDesktopWindow(), NULL))
        return false;

    m_childDlg.Create(this);
    m_childDlg.ShowWindow(SW_SHOW);
    ShowWindow(SW_SHOW);

    DrawWindow();

    return true;
}

对话框的创建函数:

bool CChildDlg::Create(CWnd *pParentWnd)
{
    if(!__super::Create(CChildDlg::IDD, pParentWnd))
        return false;

    return true;
}

演示 VS2015 项目:

https://www.dropbox.com/s/ha8o13hfz2kfn97/LayerDemo.zip?dl=0

添加以下代码即可。

BOOL CChildDlg::OnInitDialog()
{
    __super::OnInitDialog();

    m_btnMFCButton.m_bDontUseWinXPTheme = TRUE; //<-This line specifically

    return TRUE;
}