首页 > 编程资源分享区 > C/C++源代码共享 > Win32里如何用上下箭头控制输入焦点
2006
07-05

Win32里如何用上下箭头控制输入焦点

BOOL CXEdit::PreTranslateMessage(MSG* pMsg)
{
    // TODO: Add your specialized code here and/or call the base class
    if( pMsg->message == WM_CHAR ) return TRUE;

    if( pMsg->message == WM_KEYDOWN &&
        ( pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_RETURN ) )
    {
        int nextprev = GW_HWNDNEXT;
        int firstlast = GW_HWNDFIRST;
        if( pMsg->wParam == VK_UP ) {
             nextprev = GW_HWNDPREV;
             firstlast = GW_HWNDLAST;
        }
        HWND hWnd = m_hWnd;
        while( hWnd ) {
             HWND hWndx = hWnd;
             if( ( hWnd = ::GetWindow( hWnd,nextprev ) ) == NULL )
                 hWnd = ::GetWindow( hWndx,firstlast );
             long style = ::GetWindowLong( hWnd,GWL_STYLE );
             if( ( style & WS_TABSTOP && !( style & WS_DISABLED ) && style & WS_VISIBLE ) || hWnd == m_hWnd )
                 break;
        }
        ::SetFocus( hWnd );
        return TRUE;
    }
    return CEdit::PreTranslateMessage(pMsg);
}


留下一个回复