PreTranslateMessage()(一些快捷键的屏蔽、父类消息传递给子类)

 
BOOL CTest::PreTranslateMessage(MSG* pMsg) 
{
 // 处理子类的消息
 if (m_pCtrl->m_hWnd == pMsg->hwnd)
  return m_pCtrl->PreTranslateMessage(pMsg);
 
 switch (pMsg->message)
 {
 case WM_KEYDOWN:
  {
   // 过滤一些快捷键
   if (m_pView->IsBrowseMode())
   {
    int nID = 0;
    switch (pMsg->wParam) 
    {
    case _T('V'): nID = ID_EDIT_PASTE; break;
    case _T('X'): nID = ID_EDIT_CUT; break;
    case _T('Y'): nID = ID_EDIT_REDO; break;
    case _T('C'): nID = ID_EDIT_COPY; break;
    case _T('Z'): nID = ID_EDIT_UNDO; break;
    case _T('A'): nID = ID_EDIT_SELECT_ALL;break;
    case _T('D'): nID = ID_FO_TAB_ORDER;break;
    }
    if (nID != 0 && HIBYTE(GetKeyState(VK_CONTROL)))
     return TRUE;
    if (HIBYTE(GetKeyState(VK_DELETE)))
     return TRUE;
   }
   m_pView->OnKeyDown((int) pMsg->wParam, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
  }
  break;
  
 case WM_KEYUP:
   m_pView->OnKeyUp((int) pMsg->wParam, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
  }
  break;
 }
 
 if(!m_pView->PreTranslateMessage(pMsg))
 {
  return COleControl::PreTranslateMessage(pMsg);
 }
 else
 {
  return TRUE;
 }
}
注意:1.此函数告诉我们,子类的消息均来自父类,只要在父类这里把好关,子类就任其摆布!
     2.这里的消息(pMsg->message),等同于这里
BEGIN_MESSAGE_MAP(CUCCDrawCtrl, COleControl)
//{{AFX_MSG_MAP(CUCCDrawCtrl)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_MBUTTONDBLCLK()
ON_WM_MBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_MBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_ACTIVATE()
ON_WM_MOUSEACTIVATE()
ON_WM_DESTROY()
ON_WM_GETDLGCODE()
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)  
//FX_MSG_MAP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW,0,0xFFFF,OnToolTipText)   
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA,0,0xFFFF,OnToolTipText)   
END_MESSAGE_MAP() 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值