Asked by:
Visual Studio MFC dialog application , Press button to clicked

Question
-
I created a dialog application in Visual Studio MFC.
I create BN_CLICKED function to enable IDC_CHECK1.
I create DOUBLECLICKED function to other functoin.
When i call DOUBLECLICKED function will call BN_CLICKED function .
Any way to call DOUBLECLICKED function and don't call BN_CLICKED function .
==============================
void CMyTest1Dlg::DoStaticFunc(int iSelectIndex)
{
BOOL boCState;
boCState = this->m_chk1[iSelectIndex].GetCheck();
this->m_chk1[iSelectIndex].SetCheck(!boCState);
}
void CMyTest1Dlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
DoStaticFunc(0);
}
void CMyTest1Dlg::OnBnDoubleclickedButton1()
{
// TODO: Add your control notification handler code here
// will do another
}
==============================
Friday, August 14, 2020 10:20 AM
All replies
-
If you want to receive the BN_DBLCLK notification from a button then you must set the BS_NOTIFY style.
However, note that double clicking the button will send both BN_CLICKED and BN_DBLCLK.
https://docs.microsoft.com/en-us/windows/win32/controls/bn-dblclk
BTW, BN_DOUBLECLICKED is the same as the BN_DBLCLK notification code.
- Edited by RLWA32 Friday, August 14, 2020 10:47 AM clarification of notification codes
Friday, August 14, 2020 10:36 AM -
Any way to call DOUBLECLICKED function and don't call BN_CLICKED function .
Hello,
no, this is not possible. BN_CLICKED is always called first when you double-click a button.
Regards, Guido
- Edited by Guido Franzke Friday, August 14, 2020 12:12 PM
Friday, August 14, 2020 12:12 PM -
Its a bit of a hack, but you can use a timer to avoid handling the BN_CLICK notifcation if it is followed by a BN_DOUBLECLICKED notification.
For example
void CMFCApplication5Dlg::OnClickedButton1() { // TODO: Add your control notification handler code here if (!m_bTimer && !m_bDouble) { SetTimer(42, 500, nullptr); m_bTimer = true; TRACE(_T("Timer set on BN_CLICKED\n")); } else { m_bTimer = false; if (!m_bDouble) TRACE(_T("Do Single Click Action on reposted notification\n")); else { m_bDouble = false; TRACE(_T("Ignore reposted notification\n")); } } } void CMFCApplication5Dlg::OnDoubleclickedButton1() { // TODO: Add your control notification handler code her m_bDouble = true; TRACE(_T("Do Double Click Action\n")); } void CMFCApplication5Dlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default KillTimer(nIDEvent); // Re-post the BN_CLICKED notification PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON1, BN_CLICKED), (LPARAM)GetDlgItem(IDC_BUTTON1)->GetSafeHwnd()); }
- Edited by RLWA32 Friday, August 14, 2020 12:22 PM
Friday, August 14, 2020 12:22 PM -
Did you try the timer workaround?Tuesday, August 18, 2020 5:07 PM