当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

让CppWebBrowser响应回车健

      最近本人在研究CppWebBrowser的用法,发现这个控件最大的毛病就是不响应回车,即使用OleInitialize(NULL)来初始化也一样。经过在CSDN的一发查找,发现了Delphi的解决代码,先专成BCB的代码公布如下。

    先声明一个私有变量:
    IOleInPlaceActiveObject __RPC_FAR *FOleInPlaceActiveObject;

    然后在主窗体添加一个ApplicationEvents控件,在它的OnMessage事件里天加入下代码:

    void __fastcall TfmChildwin::ApplicationEvents1Message(tagMSG &Msg,
          bool &Handled)
    {
            IOleInPlaceActiveObject __RPC_FAR *iOIPAO;
            Idispatch __RPC_FAR *Dispatch;
            if(CppWebBrowser==NULL) //CppWebBrowser就是窗体上的CppWebBrowser控件
            {
                    Handled=false;
                    return;
            }
            Handled=(IsDialogMessage(CppWebBrowser->Handle,&Msg));
            if(Handled&&(!CppWebBrowser->Busy))
            {
                    if(FOleInPlaceActiveObject==NULL)
                    {
                            Dispatch=CppWebBrowser->Application;
                            if(Dispatch!=NULL)
                            {
                                    Dispatch->QueryInterface(__uuidof(IOleInPlaceActiveObject),(void**)&iOIPAO);
                                    if(iOIPAO!=NULL)
                                            FOleInPlaceActiveObject = iOIPAO;
                            }
                    }
                    if(FOleInPlaceActiveObject!=NULL)
                            if((Msg.message == WM_KEYDOWNMsg.message==WM_KEYUP)&&(Msg.wParam==VK_BACKMsg.wParam==VK_LEFTMsg.wParam==VK_RIGHT)){}
                            else
                                    FOleInPlaceActiveObject->TranslateAccelerator(&Msg);
            }
    }

 

相关内容
赞助商链接