Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » ProfUISMsgBox default button always called Collapse All
Subject Author Date
Christan HIRIGOYEN Mar 27, 2009 - 2:52 AM

for example in case of YES NO CANCEL message box, when I change the focus button with the key "TAB", the default button YES is always called by pressing key "RETURN"


if it can help you, in a normal dialog box, pressing the key "TAB" change the m_nButtonType to BS_DEFPUSHBUTTON In case of MessageBox the style does not change by pressing "TAB", and when pressing "Return" in line 1151 of extButton.cpp, the function searches for default button even if it has the focus!!!!


 


 

Technical Support Mar 27, 2009 - 2:00 PM

We used the DRAWCLI sample for testing this issue. We painted several objects in it and pressed Ctrl+F4 to close the active document. The Yes | No | Cancel message box is displayed and the VK_RETURN key works right in it. The default button is Yes and pressing it will display file saving dialog. If the No</n> button is focused and VK_RETURN is pressed, then the IDNO command is invoked. The same is with <b>Cancel button.

We suspect the problem can depend on particular message box styles. Please show us how you initialize your message box so we will test it.

Christan HIRIGOYEN Mar 30, 2009 - 2:26 AM

I tested with DRAWCLI, and for me it does not work.


I work with VS2005 in MBCS debug on Window XP SP1.


I run drawcli, i create an objet, I press Ctrl+F4 and I press TAB (the NO button gets focus) I press RETURN and then few seconds after the Save As dialog open to prompt me for a filename to save.


It takes a few seconds probably because of the file selector initialisation.


run drawcli, Ctrl+O (wait the file selector) click Cancel. draw an item, press Ctrl+F4 press TAB and press RETURN. In that case the Saves AS file selector open immedialtly.


feel free to ask me any more information to reproduce the problem.


Regards,


 

Technical Support Mar 30, 2009 - 4:21 AM

We are sorry, we used arrow keys to switch focused button, not the tab key. You are right. We fixed this issue in the CExtButton::PreTranslateMessage() method:

BOOL CExtButton::PreTranslateMessage(MSG* pMsg) 
{
            if(                     (! CExtPopupMenuWnd::IsMenuTracking() )
                        &&        OnAdvancedPopupMenuTipWndGet() == NULL
                        )
            {
                        InitToolTip();
                        m_wndToolTip.RelayEvent( pMsg );
            }

            if(                     ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP )
                        &&        ( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_SPACE )
                        )
            {
                        bool bEnabled = OnQueryWindowEnabledState();
                        if(                     bEnabled
                                    &&        IsWindowVisible()
                                    )
                        {
                                    if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
                                    {
                                                HWND hWndFocus = ::GetFocus();
                                                if( hWndFocus != NULL && hWndFocus == m_hWnd )
                                                {
                                                            _OnClick( true, false );
                                                            return TRUE;
                                                }
                                                __EXT_MFC_LONG_PTR dwWndStyle = ::__EXT_MFC_GetWindowLong( m_hWnd, GWL_STYLE );
#ifdef BS_TYPEMASK
                                                ASSERT( BS_TYPEMASK == 0x0000000FL );
#endif
                                                __EXT_MFC_LONG_PTR dwWndType = ( dwWndStyle & 0x0000000FL );
                                                if(                     GetFocus() == this 
                                                            &&        dwWndType != BS_DEFPUSHBUTTON 
                                                            )
                                                {
                                                            HWND hWndParent = ::GetParent( m_hWnd ); 
                                                            HWND hWnd = ::GetWindow( hWndParent, GW_CHILD ); 
                                                            while( hWnd != NULL )  
                                                            {
                                                                        TCHAR szCompare[512] = _T("");
                                                                        ::GetClassName(
                                                                                    hWnd,
                                                                                    szCompare,
                                                                                    sizeof( szCompare )/sizeof( szCompare[0] )
                                                                                    );
                                                                        if( _tcsicmp( szCompare, _T("BUTTON") ) == 0 )
                                                                        {
                                                                                    bool bDefault = false;
                                                                                    CWnd * pWnd = CWnd::FromHandlePermanent( hWnd ); 
                                                                                    if(                     pWnd->GetSafeHwnd() != NULL 
                                                                                                &&        pWnd->IsKindOf( RUNTIME_CLASS( CExtButton ) ) 
                                                                                                )
                                                                                    {
                                                                                                CExtButton * pBtn = STATIC_DOWNCAST( CExtButton, pWnd );
                                                                                                ASSERT_VALID( pBtn );
                                                                                                bDefault = pBtn->GetDefault( false ) ? true : false;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                                bDefault = ( ( ::__EXT_MFC_GetWindowLong( hWnd, GWL_STYLE ) & 0x0000000FL ) == BS_DEFPUSHBUTTON ) ? true : false;
                                                                                    }

                                                                                    if( bDefault )
                                                                                    {
                                                                                                int nDlgCtrlID = ::GetDlgCtrlID( hWnd );
                                                                                                ::SendMessage(
                                                                                                            hWndParent,
                                                                                                            WM_COMMAND,
                                                                                                            MAKEWPARAM( nDlgCtrlID, BN_CLICKED ),
                                                                                                            (LPARAM)hWnd
                                                                                                            );
                                                                                                return TRUE;                                                                             
                                                                                    }
                                                                        }

                                                                        hWnd = ::GetWindow( hWnd, GW_HWNDNEXT );  
                                                            }
                                                }
                                                _OnClick( true, false );
                                                return TRUE;
                                    }

                                    if(                     pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_SPACE 
                                                &&        (!m_bPushTracking)
                                                )
                                    {
                                                bool bAnimationLocked = AnimationClient_CacheGeneratorIsLocked();
                                                if( ! bAnimationLocked )
                                                {
                                                            AnimationClient_CacheGeneratorLock();
//                                                          if( AnimationClient_StateGet(true).IsEmpty() )
                                                                        AnimationClient_CacheNextStateMinInfo(
                                                                                    false,
                                                                                    __EAPT_BY_PRESSED_STATE_TURNED_ON
                                                                                    );
                                                }
                                                m_bPushed = m_bPushTracking = m_bKeyTracking = true;
                                                if( ! bAnimationLocked )
                                                {
                                                            AnimationClient_CacheNextStateMinInfo(
                                                                        true,
                                                                        __EAPT_BY_PRESSED_STATE_TURNED_ON
                                                                        );
                                                            AnimationClient_CacheGeneratorUnlock();
                                                }
                                                Invalidate();
                                                return TRUE;
                                    }

                                    if(         pMsg->message == WM_KEYUP && pMsg->wParam == VK_SPACE )
                                    {
                                                bool bAnimationLocked = AnimationClient_CacheGeneratorIsLocked();
                                                if( ! bAnimationLocked )
                                                {
                                                            AnimationClient_CacheGeneratorLock();
//                                                          if( AnimationClient_StateGet(true).IsEmpty() )
                                                                        AnimationClient_CacheNextStateMinInfo(
                                                                                    false,
                                                                                    __EAPT_BY_PRESSED_STATE_TURNED_OFF
                                                                                    );
                                                }
                                                m_bPushed = m_bPushTracking = m_bKeyTracking = m_bMouseOver = false;
                                                if( ! bAnimationLocked )
                                                {
                                                            AnimationClient_CacheNextStateMinInfo(
                                                                        true,
                                                                        __EAPT_BY_PRESSED_STATE_TURNED_OFF
                                                                        );
                                                            AnimationClient_CacheGeneratorUnlock();
                                                }
                                                _OnClick( true, false );
                                                return TRUE;
                                    }
                        }
                        return TRUE;
            }
            if(                     m_bQuickActivationEnabled
                        &&        (           pMsg->message == WM_KEYUP
                                    ||           pMsg->message == WM_SYSKEYUP
                                    )
                        )
            {
                        if( _QuickActivationCheck( DWORD(pMsg->wParam) ) )
                        {
                                    if( _QuickActivationHandle() )
                                                return TRUE;
                        }
            }

            return CButton::PreTranslateMessage(pMsg);
}