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 » CExtEditBase and m_bAltKeyCodeMode Collapse All
Subject Author Date
Rolf Boerkoel Nov 20, 2009 - 9:40 AM

Dear support,



Could you please explain a little about the Alt Key Code Mode in CExtEditBase (m_bAltKeyCodeMode)? I can’t find any info on it, and analyzing the source code doesn’t make me any wiser.



I bumped into this feature by accident (pressing arrow keys while holding down ALT) and saw strange characters appear or even clipboard text being pasted into edit controls. As regular edit controls do not behave like this I was wondering if this is something useful, because it is enabled by default.





Kind regards,


Marco

Technical Support Nov 23, 2009 - 9:36 AM

Yes, you are right. To fix this issue please update the source code for the following method:

LRESULT CExtEditBase::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
            switch( message )
            {
            case WM_KEYDOWN:
            case WM_KEYUP:
            case WM_SYSKEYDOWN:
            case WM_SYSKEYUP:
                        { // block - clipboard commands
                                    bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
                                    bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
                                    bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
                                    if( ! bAlt )
                                    {
                                                if(                     bCtrl && ! bShift 
                                                            &&        (           INT(wParam) == VK_INSERT 
                                                            ||           INT(wParam) == INT( _T(’C’) )
                                                            )
                                                            )
                                                {
                                                            if( message == WM_KEYDOWN )
                                                                        SendMessage( WM_COPY, 0, 0 );
                                                            return 0L;
                                                }
                                                
                                                if(                     ( bCtrl && (!bShift) && int(wParam) == int( _T(’V’) ) )
                                                            ||           ( (!bCtrl) && bShift && int(wParam) == VK_INSERT )
                                                            )
                                                {
                                                            if( message == WM_KEYDOWN && ( GetStyle() & ES_READONLY ) == 0 )
                                                            {
                                                                        //SendMessage( WM_PASTE, 0, 0 );
                                                                        Default();
                                                            }
                                                            return 0L;
                                                }
                                                if(                     ( bCtrl && (!bShift) && int(wParam) == int( _T(’X’) ) )
                                                            ||           ( (!bCtrl) && bShift && int(wParam) == VK_DELETE )
                                                            )
                                                {
                                                            if( message == WM_KEYDOWN )
                                                                        SendMessage( ( ( GetStyle() & ES_READONLY ) == 0 ) ? WM_CUT : WM_COPY, 0, 0 );
                                                            return 0L;
                                                }
                                    }
                        } // block - clipboard commands
//                      if( ( GetStyle() & ES_READONLY ) != 0 )
//                      {
//                                  bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
//                                  if( ! bAlt )
//                                  {
//                                              bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
//                                              bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
//                                              if(                     (           bCtrl
//                                                                      &&        (           wParam == WPARAM(’X’)
//                                                                                  ||           wParam == WPARAM(’x’)
//                                                                                  ||           wParam == WPARAM(’V’)
//                                                                                  ||           wParam == WPARAM(’v’)
//                                                                                  ||           wParam == WPARAM(’Z’)
//                                                                                  ||           wParam == WPARAM(’z’)
//                                                                                  )
//                                                                      )
//                                                          ||           (           bShift
//                                                                      &&        (           wParam == VK_INSERT
//                                                                                  ||           wParam == VK_DELETE
//                                                                                  )
//                                                                      )
//                                                          ||           (           ( ! ( bCtrl || bShift ) )
//                                                                      &&        ( wParam == VK_DELETE || wParam == VK_BACK )
//                                                                      )
//                                                          )
//                                                          return 0L;
//                                  }
//                                  else
//                                  {
//                                              if( wParam == VK_BACK )
//                                                          return 0L;
//                                  }
//                      }
                        if( m_bHandleAltKeyCodes )
                        {
                                    bool bKeyDown = ( message == WM_KEYDOWN || message == WM_SYSKEYDOWN ) ? true : false;
                                    switch( wParam )
                                    {
                                    case VK_MENU:
                                                if( bKeyDown )
                                                {
                                                            if( ( GetStyle() & ES_READONLY ) != 0 )
                                                            {
                                                                        m_bAltKeyCodeMode = false;
                                                                        if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                                                    g_hWndEditInAltKeyCodeMode = NULL;
                                                                        m_nTrackedAltKeyCode = 0L;
                                                                        break;
                                                            }
                                                            m_bAltKeyCodeMode = true;
                                                            g_hWndEditInAltKeyCodeMode = m_hWnd;
                                                            m_nTrackedAltKeyCode = 0L;
                                                            return 0L;
                                                } // if( bKeyDown )
                                                else if( m_bAltKeyCodeMode )
                                                {
                                                            m_bAltKeyCodeMode = false;
                                                            if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                                        g_hWndEditInAltKeyCodeMode = NULL;
                                                            if( m_nTrackedAltKeyCode > 0L )
                                                            {
                                                                        USES_CONVERSION;
                                                                        WCHAR wstr[2] = { WCHAR(m_nTrackedAltKeyCode), L’\0’ };
                                                                        LPCTSTR str = W2CT( wstr );
                                                                        //ReplaceSel( str );
                                                                        m_nTrackedAltKeyCode = 0L;
                                                                        for( MSG _msg; ::PeekMessage( &_msg, m_hWnd, WM_CHAR, WM_CHAR, PM_REMOVE ); );
                                                                        SendMessage( WM_CHAR, WPARAM(str[0]), 1L );
                                                            }
                                                            return 0L;
                                                } // else if( m_bAltKeyCodeMode )
                                    break;
                                    case VK_INSERT:
                                    case VK_END:
                                    case VK_DOWN:
                                    case VK_NEXT:
                                    case VK_LEFT:
                                    case 0x0C: // VK_CLEAR
                                    case VK_RIGHT:
                                    case VK_HOME:
                                    case VK_UP:
                                    case VK_PRIOR:
                                                if( m_bAltKeyCodeMode )
                                                {
                                                            if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
                                                            {
                                                                        m_bAltKeyCodeMode = false;
                                                                        if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                                                    g_hWndEditInAltKeyCodeMode = NULL;
                                                                        m_nTrackedAltKeyCode = 0L;
                                                                        break;
                                                            }
                                                            if( bKeyDown )
                                                            {
                                                                        LONG nAdd = -1L;
                                                                        bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
                                                                        if( bIsExtendedKey )
                                                                        {
                                                                                    switch( wParam )
                                                                                    {
                                                                                    case VK_INSERT:                     nAdd = 0L; break;
                                                                                    case VK_END:              nAdd = 1L; break;
                                                                                    case VK_DOWN:                       nAdd = 2L; break;
                                                                                    case VK_NEXT:                        nAdd = 3L; break;
                                                                                    case VK_LEFT:             nAdd = 4L; break;
                                                                                    case 0x0C:                                nAdd = 5L; break; // VK_CLEAR
                                                                                    case VK_RIGHT:                       nAdd = 6L; break;
                                                                                    case VK_HOME:                       nAdd = 7L; break;
                                                                                    case VK_UP:                            nAdd = 8L; break;
                                                                                    case VK_PRIOR:                       nAdd = 9L; break;
                                                                                    } // switch( wParam )
                                                                        } // if( bIsExtendedKey )
                                                                        if( nAdd >= 0L )
                                                                        {
                                                                                    m_nTrackedAltKeyCode *= 10;
                                                                                    ASSERT( 0L <= nAdd && nAdd <= 9L );
                                                                                    m_nTrackedAltKeyCode += nAdd;
                                                                        }
                                                            } // if( message == WM_KEYDOWN )
                                                            return 0L;
                                                } // if( m_bAltKeyCodeMode )
                                    break;
                                    case VK_NUMPAD0:
                                    case VK_NUMPAD1:
                                    case VK_NUMPAD2:
                                    case VK_NUMPAD3:
                                    case VK_NUMPAD4:
                                    case VK_NUMPAD5:
                                    case VK_NUMPAD6:
                                    case VK_NUMPAD7:
                                    case VK_NUMPAD8:
                                    case VK_NUMPAD9:
                                                if( m_bAltKeyCodeMode )
                                                {
                                                            if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
                                                            {
                                                                        m_bAltKeyCodeMode = false;
                                                                        if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                                                    g_hWndEditInAltKeyCodeMode = NULL;
                                                                        m_nTrackedAltKeyCode = 0L;
                                                                        break;
                                                            }
                                                            if( bKeyDown )
                                                            {
                                                                        bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
                                                                        if( bIsExtendedKey )
                                                                        {
                                                                                    m_nTrackedAltKeyCode *= 10;
                                                                                    LONG nAdd = LONG(wParam) - LONG(VK_NUMPAD0);
                                                                                    ASSERT( 0L <= nAdd && nAdd <= 9L );
                                                                                    m_nTrackedAltKeyCode += nAdd;
                                                                        } // if( bIsExtendedKey )
                                                            } // if( message == WM_KEYDOWN )
                                                            return 0L;
                                                } // if( m_bAltKeyCodeMode )
                                    break;
                                    case WPARAM(’0’):
                                    case WPARAM(’1’):
                                    case WPARAM(’2’):
                                    case WPARAM(’3’):
                                    case WPARAM(’4’):
                                    case WPARAM(’5’):
                                    case WPARAM(’6’):
                                    case WPARAM(’7’):
                                    case WPARAM(’8’):
                                    case WPARAM(’9’):
                                                if( m_bAltKeyCodeMode )
                                                {
                                                            if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
                                                            {
                                                                        m_bAltKeyCodeMode = false;
                                                                        if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                                                    g_hWndEditInAltKeyCodeMode = NULL;
                                                                        m_nTrackedAltKeyCode = 0L;
                                                                        break;
                                                            }
                                                            if( bKeyDown )
                                                            {
                                                                        bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
                                                                        if( bIsExtendedKey )
                                                                        {
                                                                                    m_nTrackedAltKeyCode *= 10;
                                                                                    LONG nAdd = LONG(wParam) - LONG(’0’);
                                                                                    ASSERT( 0L <= nAdd && nAdd <= 9L );
                                                                                    m_nTrackedAltKeyCode += nAdd;
                                                                        } // if( bIsExtendedKey )
                                                            } // if( message == WM_KEYDOWN )
                                                            return 0L;
                                                } // if( m_bAltKeyCodeMode )
                                    break;
                                    default:
                                                m_bAltKeyCodeMode = false;
                                                if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                            g_hWndEditInAltKeyCodeMode = NULL;
                                                m_nTrackedAltKeyCode = 0L;
                                    break;
                                    } // switch( wParam )
                        } // if( m_bHandleAltKeyCodes )
                        else
                        {
                                    m_bAltKeyCodeMode = false;
                                    if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                g_hWndEditInAltKeyCodeMode = NULL;
                                    m_nTrackedAltKeyCode = 0L;
                        } // else from if( m_bHandleAltKeyCodes )
            break;
            case WM_CANCELMODE:
            case WM_ACTIVATE:
            case WM_ACTIVATEAPP:
            case WM_KILLFOCUS:
            case WM_DESTROY:
            case WM_SETTINGCHANGE:
            case WM_DISPLAYCHANGE:
            case WM_SHOWWINDOW:
            case WM_SIZE:
            case WM_WINDOWPOSCHANGING:
            case WM_WINDOWPOSCHANGED:
            case EM_SETSEL:
            case EM_REPLACESEL:
            case EM_UNDO:
            case EM_REDO:
                        m_bAltKeyCodeMode = false;
                        if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                    g_hWndEditInAltKeyCodeMode = NULL;
                        m_nTrackedAltKeyCode = 0L;
            break;
            case WM_STYLECHANGED:
                        if( ( GetStyle() & ES_READONLY ) != 0 )
                        {
                                    m_bAltKeyCodeMode = false;
                                    if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                g_hWndEditInAltKeyCodeMode = NULL;
                                    m_nTrackedAltKeyCode = 0L;
                                    break;
                        }
            break;
            case WM_SYSCHAR:
            case WM_CHAR:
                        if(                     ( GetStyle() & ES_READONLY ) != 0
                                    &&        (! CExtPopupMenuWnd::IsKeyPressed( VK_CONTROL ) )
                                    )
                                    return 0L;
            break;
            case WM_PASTE:
                        {
                                    m_bAltKeyCodeMode = false;
                                    if( g_hWndEditInAltKeyCodeMode == m_hWnd )
                                                g_hWndEditInAltKeyCodeMode = NULL;
                                    m_nTrackedAltKeyCode = 0L;
                        }
            break;
            } // switch( message )
            if(                     message == WM_NOTIFY
                        &&        m_wndToolTip.GetSafeHwnd() != NULL
                        &&        IsWindow( m_wndToolTip.GetSafeHwnd() )
                        &&        ((LPNMHDR)lParam) != NULL
                        &&        ((LPNMHDR)lParam)->hwndFrom == m_wndToolTip.GetSafeHwnd()
                        &&        ((LPNMHDR)lParam)->code == TTN_SHOW
                        )
                        ::SetWindowPos(
                                    m_wndToolTip.GetSafeHwnd(),
                                    HWND_TOP,
                                    0,0,0,0,
                                    SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE
                                    );
LRESULT lResult = CEdit::WindowProc( message, wParam, lParam );
            return lResult;
}









Rolf Boerkoel Nov 25, 2009 - 1:21 AM

Thanks, works fine now.



The only remark I have left is that pressing ALT + regular keys 0-9 (case WPARAM(’0’) through WPARAM(’9’)) normally doesn’t allow entering characters in this way as far as I know. But this feature doesn’t bother me.

Technical Support Nov 20, 2009 - 2:43 PM

The CExtEditBase control implements the Alt-key based character input from scratch. The CExtEditBase::m_bAltKeyCodeMode flat is the internal protected property of the CExtEditBase class. It’s set to false if the Alt key is not pressed. It’s set to true if the Alt key was pressed and number characters are entered. The CExtEditBase class keeps it set to true in this case until the Alt key kept pressed. When the Alt key is released, then the CExtEditBase class inserts the character corresponding to the character entered code.
If you know any issues related to the Alt-key based character input in the CExtEditBase control, then please let us know exact sequence of steps to reproduce them.

Rolf Boerkoel Nov 23, 2009 - 3:56 AM

Ah wait a minute, this is for entering characters using ALT + numpad keys, of course! I did not expect to see this behaviour when pressing the regular arrow/pageup/pagedown etc. keys.



Perhaps it is an idea to test on the WM_KEYDOWN lParam bit 24 to see if it really is a numpad key?

BOOL bIsExtendedKey = ((lParam & 0x01000000) != 0);