Click inside the layered window area so that the dialog doesn't have the focus then try to click on the button on the dialog. The button will not respond to the event.
If the button is just CButton, then it works fine. One might say that the dialog needs to have the focus for this to work but that's not the case in any other scenario. In general when I click a button on a dialog it always works even if my focus was previously in a completely different program.
The create function for the layered 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;
}
The create function for the dialog:
bool CChildDlg::Create(CWnd *pParentWnd)
{
if(!__super::Create(CChildDlg::IDD, pParentWnd))
return false;
return true;
}
Demo VS2015 project:
https://www.dropbox.com/s/ha8o13hfz2kfn97/LayerDemo.zip?dl=0
Add the following code and it will work.
BOOL CChildDlg::OnInitDialog()
{
__super::OnInitDialog();
m_btnMFCButton.m_bDontUseWinXPTheme = TRUE; //<-This line specifically
return TRUE;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.