VC6.0中对消息的特殊处理--PreTranslateMessage说明

 

首先看看MSDN对PreTranslateMessage的说明

 

 

Override this function to filter window messages before they are dispatched to the Windows functions TranslateMessage and DispatchMessage The default implementation performs accelerator-key translation, so you must call the CWinApp::PreTranslateMessage member function in your overridden version.

 
virtual BOOL PreTranslateMessage(
MSG* pMsg
);

Parameters

pMsg

A pointer to a MSG structure that contains the message to process.

Return Value

Nonzero if the message was fully processed in PreTranslateMessage and should not be processed further. Zero if the message should be processed in the normal way.

Requirements

Header: afxwin.h

 

------------------------------------------------------

再看看一个具体的例子.

BOOL MyDialog::PreTranslateMessage(MSG* pMsg)
{
    if(pMsg->message == WM_KEYDOWN)
    {
        //Return key
        if( pMsg->wParam == VK_RETURN )
        {  //若焦点在本页面上的一个名叫IDC_EDT_TEST_DATA_FILE的EditBox上,按回车键则焦点转移到下个控件
            if(GetFocus() == GetDlgItem(IDC_EDT_TEST_DATA_FILE))
            {
               
                GetFocus()->GetNextWindow()->SetFocus();
                return TRUE;
            }

//若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,按回车键时焦点转移到父窗口的IDC_BEXECUTE按钮上
            else if(GetFocus() == GetDlgItem(IDC_EDT_WAITTIME))
            {
                ((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXECUTE)->SetFocus();
                return TRUE;
            }
        }

        //[Shift] + [TAB]
        else if(GetKeyState(VK_SHIFT) & 0x8000 && pMsg->wParam == VK_TAB)
        {
            //若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,Shift + TAB是,焦点跳到窗口名叫IDC_RBTN_STEP4的Radio Button上
            if(pMsg->hwnd == (GetDlgItem(IDC_EDT_TEST_DATA_FILE))->m_hWnd )
            {
                (((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_RBTN_STEP4))->SetFocus();
                return TRUE;
            }
        }
        else if( pMsg->wParam == VK_TAB )
        {
            //[TAB]

//若焦点在本页面一个叫IDC_EDT_WAITTIME的EditBox上,TAB时焦点转移到父窗口的IDC_BEXECUTE按钮上
             if( pMsg->hwnd == GetDlgItem(IDC_EDT_WAITTIME)->GetSafeHwnd())
            {
                ((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXECUTE)->SetFocus();
                return TRUE;
            }
        }
        //Escape key
        else if( pMsg->wParam == VK_ESCAPE )
        {
            //按Esc键时,相当于按窗口上有的EXIT按钮.
            CButton* pBtnExit = (CButton*)((CArithmeticExpressionDlg*)this->GetParent())->GetDlgItem(IDC_BEXIT);
            ::SendMessage(pBtnExit->GetSafeHwnd(),WM_LBUTTONDOWN,0,0);
            ::SendMessage(pBtnExit->GetSafeHwnd(),WM_LBUTTONUP,0,0);
            return TRUE;
        }
        //other events

        /*********************some other code***************************/     
    }
    //others

    return CDialog::PreTranslateMessage(pMsg);
}

 

本例子的功能就是在父子窗口之前实现焦点的转移.

例如,当焦点位于子窗口的最后一个控件时,此时接着操作TAB键,就要注焦点转移到父窗口中,并且是紧跟着子窗口的那个控件.

 

 

闻香止步 收集于:http://blog.csdn.net/roofwei/archive/2009/02/18/3906112.aspx
淘宝店 摆件 饰品 *木雕系列*:海南黄花梨、越南黄花梨、草花梨、小叶紫檀、黑檀、绿檀木、黄杨木、桃木发簪  木梳 樟木壁挂 佛珠 车饰 摆件

http://shop36570193.taobao.com

朋友,有空来看看,喜欢的朋友请收藏

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值