Thank you for the test project. We handled the OK and Cancel button clicks in your test project:
void CTestUpDownDlg::OnOK()
{
// CDialog::OnOK();
AfxMessageBox("OnOK");
}
void CTestUpDownDlg::OnCancel()
{
// CDialog::OnCancel();
AfxMessageBox("OnCancel");
}
And both buttons correctly stay focused after the message box is closed. The up-down ActiveX control cannot be tested for focus restoring. It has much more serious problem. It does not release mouse capture when it fires its events. We understand it requires mouse capture for mouse click tracking. But this causes multiple message box displaying. Probably message box should not be displayed while handling these events or, at least, you should release mouse capture manually:
void CTestUpDownDlg::OnDownClickUpdownTest()
{
ReleaseCapture();
AfxMessageBox("OnDownClickUpdownTest");
}
void CTestUpDownDlg::OnUpClickUpdownTest()
{
ReleaseCapture();
AfxMessageBox("OnUpClickUpdownTest");
}
Even in this case the focused state of the up-down control is not restored correctly and you may need to focus it manually. So, we decided to make Prof-UIS message box force releasing the mouse capture in its code:
int CExtMsgBox::DoMsgBox(
HWND hWndParent,
__EXT_MFC_SAFE_LPCTSTR strMessageText,
__EXT_MFC_SAFE_LPCTSTR strCaption, // = NULL
UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
UINT nHelpID, // = 0
__EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
UINT nMsgBoxStyleEx, // = __EXT_MB_EX_DEFAULT_STYLES
UINT nTimeoutSeconds, // = 0
bool bIsDisabledTimeout, // = false
CExtBitmap * pBmpIcon // = NULL
)
{
__PROF_UIS_MANAGE_STATE;
if( ::GetCapture() != NULL )
::ReleaseCapture(); // force release mouse capture
CExtMsgBox dlg( hWndParent, strMessageText, strCaption, nMsgBoxStyle, nHelpID, strUniqueID, nMsgBoxStyleEx );
if( nTimeoutSeconds > 0 )
dlg.TimeoutSet( nTimeoutSeconds, bIsDisabledTimeout );
if( pBmpIcon != NULL && ( ! pBmpIcon->IsEmpty() ) )
dlg.m_bmpIcon = (*pBmpIcon);
return int( dlg.DoModal() );
}
This fixes behavior of the up-down control. Probably the
AfxMessageBox()
API force releases capture too. But both Prof-UIS and MFC message boxes does not set focus back to the up down control (we tried to comment the
IMPLEMENT_CWinAPP_DoMessageBox
line of code).