现在的位置: 首页 > 综合 > 正文

IE中ocx控件的无模式对话框不接收方向键等键盘消息的问题的解决办法

2012年09月12日 ⁄ 综合 ⁄ 共 1171字 ⁄ 字号 评论关闭
在ocx控件中如果含有无模式对话框,那么当ocx在ie中显示时,往往接收不到
诸如tab,方向键和退格键。所有这些消息都被IE容器给截取了,对于这个问题,ms给出了解决方法:
首先:
  int CMyActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
   {
      if (COleControl::OnCreate(lpCreateStruct) == -1)
         return -1;
      OnActivateInPlace (TRUE, NULL); // == UI-Activate the control
      return 0;
   }
 激活控件,以便能接收键盘消息。
其次 跟踪转发消息
  // trap keys and forward on to the control
   BOOL CMyActiveXCtrl::PreTranslateMessage(MSG* pMsg)
   {
      switch (pMsg->message)
      {
         case WM_KEYDOWN:
         case WM_KEYUP:
            switch (pMsg->wParam)
            {
               case VK_UP:
               case VK_DOWN:
               case VK_LEFT:
               case VK_RIGHT:
               case VK_HOME:
               case VK_END:
               case VK_TAB:
                 ::SendMessage (pMsg->hWnd, pMsg->message, pMsg->wParam, pMsg->lParam);
                  // Windowless controls won't be able to call SendMessage.
                  // Instead, just respond to the message here.
                  return TRUE;
            }
            break;
      }
      return COleControl::PreTranslateMessage(pMsg);
   }
注意用send而不要用post

抱歉!评论已关闭.