簡體   English   中英

在分層窗口的子對話框中時,未單擊CMFCButton

[英]CMFCButton not clicked when in a child dialog of a layered window

背景:

  • 使用WS_EX_LAYERED和GetDesktopWindow()作為父級創建CWnd
  • 使用分層窗口作為父級創建一個CDialogEx
  • 在對話框中添加一個按鈕,並使用DDX_Control使其成為CMFCButton

問題:

在分層的窗口區域內單擊,以使對話框沒有焦點,然后嘗試單擊對話框上的按鈕。 該按鈕將不響應事件。

備注:

如果按鈕只是CButton,則可以正常工作。 可能有人會說,對話框需要具有焦點才能起作用,但是在任何其他情況下並非如此。 通常,當我單擊對話框上的按鈕時,即使以前我的焦點位於完全不同的程序中,它也始終有效。

碼:

分層窗口的創建功能:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM