ocx 中处理回车相应的问题



 There   is   one   other   option   you   can   use   to   fix   these   problems,   instead   of   creating   the   dialog   window   manually.   You   can   use   a   Windows   hook.   This   will   enable   you   to   retrieve   all   keyboard   messages   for   the   current   thread   and   then   call   TranslateAccelerator   so   that   accelerator   keys   will   be   processed.   There   is   one   problem   with   this   approach,   however.   When   the   focus   is   on   the   WebBrowser   control   and   you   attempt   to   change   focus   between   controls   on   the   Web   page   by   pressing   tab,   the   focus   will   never   leave   the   WebBrowser   window.   This   means   that   you   can   Tab   between   controls   on   the   Web   page   or   between   controls   in   your   application,   but   not   both.     
    
  There   are   four   steps   required   to   set   up   a   Windows   hook   to   work   around   the   keystroke   problems   in   a   Win32   SDK   dialog.   First,   declare   your   hook   procedure   in   your   header   file.     
    
  static   LRESULT   CALLBACK   GetMsgHookProc(int   nCode,   WPARAM   wParam,   LPARAM   lParam);   
    
  Next,   set   your   hook   procedure   during   initialization   by   calling   SetWindowsHookEx.   Also,   make   sure   to   save   the   returned   hook   handle   so   that   you   can   unhook   the   procedure   when   you   are   shutting   down   or   when   it   is   no   longer   needed.     

  //   Declare   this   global   handle   in   one   of   your   project   files.   
    HHOOK   g_hook;   
      
    //   Place   this   code   inside   an   initialization     
    //   method   in   your   implementation   file   (.cpp)   
    g_hook   =   SetWindowsHookEx(WH_GETMESSAGE,   GetMsgHookProc,   
                                                        NULL,   GetCurrentThreadId());   

    
  After   that,   implement   your   hook   procedure   and   call   TranslateAccelerator.     
    
    LRESULT   CALLBACK   CYourClass::GetMsgHookProc(int   nCode,   WPARAM   wParam,   
                                                                                            LPARAM   lParam)   
    {   
          LPCKFSEARCH   pThis   =   (LPCKFSEARCH)GetWindowLong(hwndMain,   DWL_USER);   
      
          if   (pThis   &&   nCode   >=   0)   
          {   
                MSG*   pMsg   =   (MSG*)lParam;   
      
                //   m_pOleInPlaceActObj   is   an   IOleInPlaceActiveObject   
                //   data   member   of   the   view   class   that   is   initialized   
                //   after   the   WebBrowser   control   is   loaded.   
      
                if   (pThis->m_pOleInPlaceActObj)   
                      pThis->m_pOleInPlaceActObj->TranslateAccelerator(pMsg);   

      
                //   This   causes   the   tab   to   work   in   the   WebBrowser   window.   If   you   do   not   do   
                //   this,   tabbing   will   happen   in   the   dialog   only.     You   have   the   choice   of   
                //   tabbing   in   the   dialog   or   the   WebBrowser   window,   not   both.   
      
                if   (pMsg->wParam   ==   VK_TAB)   
                      ZeroMemory(pMsg,   sizeof(MSG));   
          }   
      
          return   CallNextHookEx(g_hook,   nCode,   wParam,   lParam);   
    }   
    
  Finally,   when   your   application   is   shutting   down   or   when   you   no   longer   need   the   hook,   unhook   the   procedure.     
  UnhookWindowsHookEx(g_hook);   


注意:LPCKFSEARCH   我始终找不到在哪里定义,其实在ATL中可以

CComQIPtr<IOleControlSite, &IID_IOleControlSite>
   spCtrlSite(m_spClientSite);

起到相同的作用。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值