我用MFC开发了一个ocx控件,其中的界面上有哟个Edit编辑框。但这个编辑框存在这样的问题,在编辑框中输入后,键盘的左右方向键不能用。只有在我按了TAB键之后,再切换到Edit编辑框,这样左右键才能用。不知是什么原因,请各位高手指教,非常感谢!!

解决方案 »

  1.   

    http://www.microsoft.com/mind/0499/faq/faq0499.asp
      

  2.   

    谢谢jiangsheng(蒋晟.MSMVP2004Jan)的指教,但这段代码中的'LPCKFSEARCH' : undeclared identifier,一直找不到在哪里定义,请指教!非常感谢!!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);
     }
      

  3.   

    Here is the 7.0 ATL snippet of code that shows how to call WebBrowser's 
    IOleInPlaceActiveObject::TranslateAccelerator().
    When you hit Tab key on keyboard the focus is moved from control to
    control 
    on the aa.com page.---------------------------------------------------------------
    extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE 
    /*hPrevInstance*/, 
                                    LPTSTR /*lpCmdLine*/, int nShowCmd)
    {
    CMyWindow wndMain;
    MSG msg;
    if ( NULL == wndMain.Create ( NULL, CWindow::rcDefault, _T("ATL Browser 
    Window") ))
    {
            return 1;
    }
     
    wndMain.ShowWindow(nShowCmd);
    wndMain.UpdateWindow();

    while ( GetMessage(&msg, NULL, 0, 0) > 0 )
    {
    TranslateMessage(&msg);
    if ( msg.message == WM_KEYDOWN ) // is a key pressed? 
    ::SendMessage(wndMain.m_hWnd, msg.message, msg.wParam, msg.lParam); // 
    Send messge here DispatchMessage(&msg);
    }
    return (int)msg.wParam;
    }------------------------------------------------------------
    ------------------------------------------------------------#pragma once
    #include "atlwin.h"
    #include <mshtmhst.h>
    #include <mshtmdid.h>typedef CWinTraits <
    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN |
                        WS_CLIPSIBLINGS,
    WS_EX_APPWINDOW | WS_EX_WINDOWEDGE
    >MyFrameWindowTraits;class CMyWindow :
    public CWindowImpl<CMyWindow, CWindow, MyFrameWindowTraits>
    {
    public:
    CMyWindow(void);
    ~CMyWindow(void);
    public:
        DECLARE_WND_CLASS(_T("My Browser Window Class"))
     
        BEGIN_MSG_MAP(CMyWindow)
            MESSAGE_HANDLER(WM_CREATE, OnCreate)
            MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) // 1. catch message here        MESSAGE_HANDLER(WM_CLOSE, OnClose)
            MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        END_MSG_MAP()
     
    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
        {
    CAxWindow wnd(m_hWnd);
    HRESULT hr = wnd.CreateControl(OLESTR("Shell.Explorer"));  if (SUCCEEDED(hr))
    {
    hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);
    }
    if (m_spBrowser)
    {
    LPCOLESTR lpszTricsData = OLESTR("http://aa.com");
    CComVariant ve;
    CComVariant vurl(lpszTricsData);
    m_spBrowser->put_Visible(VARIANT_TRUE);
    m_spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve);
    }
            return 0;
        }
        LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& 
    bHandled) // 2. catch message here
        {
    CComQIPtr<IOleInPlaceActiveObject, &IID_IOleInPlaceActiveObject> 
    pIOIPAO(m_spBrowser);
    HRESULT hr = S_FALSE; if ( pIOIPAO )
    {
    MSG msg;
    msg.message = uMsg;
    msg.wParam = wParam;
    msg.lParam = lParam; // here call WebBrowser IOleInPlaceActiveObject::TranslateAccelerator
    hr = pIOIPAO->TranslateAccelerator(&msg); 
    }
            return hr;
        }
        LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
    bHandled)
        {
            DestroyWindow();
            return 0;
        }
     
        LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& 
    bHandled)
        {
            PostQuitMessage(0);
            return 0;
        }  CComPtr<IWebBrowser2> m_spBrowser;
    };
    ------------------------------------------------------------
      

  4.   

    没有示例工程呀!我把这个方法的这段代码添加到我的工程里面的,编译出的上面的错。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); 
      

  5.   

    我找不到原因,jiangsheng(蒋晟.MSMVP2004Jan),请求你的帮助
      

  6.   

    jiangsheng(蒋晟.MSMVP2004Jan)大侠,发表以下您的意见吧。还是搞不定,比较急呀,麻烦你抽空看一看。非常感谢!!!
      

  7.   

    Download the code (3KB) 
    这行你没看到?
      

  8.   

    我加载文章中的代码时的'LPCKFSEARCH' : undeclared identifier编译出错,下载的代码中根本就没有这段代码。搞不明白,希望jiangsheng(蒋晟.MSMVP2004Jan)大侠和用过此方法的大哥指教,郁闷呀!
      

  9.   

    谢谢jiangsheng(蒋晟.MSMVP2004Jan)大侠的回答,不知道您看过下载里面的代码(3k)没有。里面根本没有文章中所说的钩子程序,看不明白下载中代码的意思。郁闷呀!!