我用atl做的IE toolbar,然后想在用户输入时,捕捉按下enter的事件,我用了TranslateAcceleratorIO(LPMSG lpMsg),然后如果事件是wm_keydown而且是回车,就xxx,否则交还回去:
TranslateMessage(lpMsg);
DispatchMessage(lpMsg);
结果我发现,如果输入中文的话,输入完了就变了,比如输入'吃饭',变成'm',大部分情况下是空的,但是如果复制过去中文没有问题,英文及字符输入也没有问题,请问大家知不知道这个怎么回事儿呢?
多谢了~_~

解决方案 »

  1.   

    <H3>IInputObject Implementation </H3>
    <P>To get tabbing and input control to work correctly for any deskband is quite 
    simple. You need but to implement IInputObject. The host will query our deskband 
    to see if this interface is implemented and if it is will call the methods to 
    see if we require input focus and let us also process messages from the user 
    through the host. To do this, open the stockbar.h header file. To the stockbar 
    class declaration add the line below in bold, <PRE lang=c++>class ATL_NO_VTABLE CStockBar : 
       public CComObjectRootEx<CComSingleThreadModel>,
       public CComCoClass<CStockBar, &CLSID_StockBar>,
       public IDeskBand,
       public IObjectWithSite,
    <B>   public IInputObject,</B> 
       public IDispatchImpl<IStockBar, &IID_IStockBar, &LIBID_MOTLEYFOOLLib>
    {
    </PRE>Next scroll down to the COM Map and add an entry for IInputObject as shown 
    below in bold, <PRE lang=c++>BEGIN_COM_MAP(CStockBar)
       COM_INTERFACE_ENTRY(IStockBar)
    <B>   COM_INTERFACE_ENTRY(IInputObject)</B>
       COM_INTERFACE_ENTRY(IOleWindow)
       COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
       COM_INTERFACE_ENTRY(IObjectWithSite)
       COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
       COM_INTERFACE_ENTRY(IDispatch)
    END_COM_MAP()
    </PRE>Next add the following section of function declarations to your header 
    file, I placed mine before the IStockBar section. <PRE lang=c++>// IInputObject
    public:
       STDMETHOD(HasFocusIO)(void);
       STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg);
       STDMETHOD(UIActivateIO)(BOOL fActivate, LPMSG lpMsg);
    </PRE>All that remains is to implement these three functions. Add the function 
    implementations below to the end of the stockbar.cpp source file. <PRE lang=c++>STDMETHODIMP CStockBar::HasFocusIO(void)
    {
       // if any of the windows in our toolbar have focus then return S_OK else S_FALSE.
       if (m_ReflectWnd.GetToolBar().m_hWnd == ::GetFocus())
          return S_OK;
       if (m_ReflectWnd.GetToolBar().GetEditBox().m_hWnd == ::GetFocus())
         return S_OK;
       return S_FALSE;
    }
    STDMETHODIMP CStockBar::TranslateAcceleratorIO(LPMSG lpMsg)
    {
       // the only window that needs to translate messages is our edit box so forward them.
       return m_ReflectWnd.GetToolBar().GetEditBox().TranslateAcceleratorIO(lpMsg);
    }
    STDMETHODIMP CStockBar::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
    {
       // if our deskband is being activated then set focus to the edit box.
       if(fActivate)
       {
          m_ReflectWnd.GetToolBar().GetEditBox().SetFocus();
       }
       return S_OK;
    }http://www.codeproject.com/atl/ietoolbartutorial.asp
      

  2.   

    你可以这样,对于非回车消息不
    TranslateMessage(lpMsg);
    DispatchMessage(lpMsg);而是直接返回S_FALSE,让系统来处理,应该就可以了