• activex嵌入浏览器时线程触发事件


      在浏览器中嵌入activex后,线程中触发的事件就没有动静了,如果在调试的情况下,还能发现浏览器有非法错发生。而同样的activex如果使用应用程序来调用则正常。

    解决方法是取巧的方式,在线程中发出消息,控件响应消息后再FireEvent。

    1. 创建控件项目。
    2. 类向导, 使用 Add 方法将启动二线程并返回。 下面的代码显示方法启动二线程并立即返回 MFCActiveX 控件中。 全局函数以作为二线程工作函数还声明:
       LONG ThreadProc(LPVOID pParam);

    void CFireeventCtrl::StartLengthyProcess()
    {
    DWORD dwID;
    HANDLE threadHandle = CreateThread(NULL,NULL,
    (LPTHREAD_START_ROUTINE)ThreadProc,
    (LPVOID)this, NULL, &dwID);
    TRACE("Started the thread %x\n",dwID);
    }
    3. 添加任何要从使用类向导二线程激发事件。
    4. 定义要从二线程发送自定义邮件。 还, 将消息映射项添加到控件消息映射接收自定义消息时, 将调用消息处理函数。 此消息处理程序将触发需事件。 样本如何执行此 MFCActiveX 控件中的如下:
          //define a custom message:
    #define WM_THREADFIREEVENT WM_APP+101

    //add an entry for the message to the message map of the control
    BEGIN_MESSAGE_MAP(CFireeventCtrl, COleControl)
    //{{AFX_MSG_MAP(CFireeventCtrl)
    //}}AFX_MSG_MAP
    ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
    ON_MESSAGE(WM_THREADFIREEVENT,OnFireEventForThread) //custom handler
    END_MESSAGE_MAP()

    //add a handler for the custom message that will fire our event
    LRESULT CFireeventCtrl::OnFireEventForThread(WPARAM wParam,
    LPARAM lParam)
    {
    FireLengthyProcessDone();
    return TRUE;
    }
    5. 为二线程, 线程过程中当是二线程来触发事件, 时间张贴回主线程步骤 3 中定义自定义消息。 激发事件。 以下代码演示:
          LONG ThreadProc(LPVOID pParam)
    {
    Sleep(2000); //simulate lengthy processing
    CFireeventCtrl *pCtrl = (CFireeventCtrl*)pParam;
    PostMessage(pCtrl->m_hWnd,
    WM_THREADFIREEVENT,
    (WPARAM)NULL,
    (LPARAM)NULL);
    return TRUE;
    }

    同时因为浏览器貌似并不创建activex的窗口,所以还要增加创建窗口的代码。
    MFC 提供函数调用 COleControl::CreateControlWindow() 来创建控件窗口。 MFC 实现 IOleObject::SetClientSite() 调用 COleControl::OnSetClientSite()。 将以下到 - COleControl 派生类:
       // CMyControl is derived from COleControl.
    void CMyControl::OnSetClientSite()
    {
    if (m_pClientSite)
    // It doesn't matter who the parent window is or what the size of
    // the window is because the control's window will be reparented
    // and resized correctly later when it's in-place activated.
    VERIFY (CreateControlWindow (::GetDesktopWindow(), CRect(0,0,0,0),
    CRect(0,0,0,0)));
    COleControl::OnSetClientSite();
    }
    参考:
    http://topic.csdn.net/t/20040109/17/2650433.html#
    http://support.microsoft.com/kb/195188/zh-cn
    http://support.microsoft.com/kb/157437
  • 相关阅读:
    1.NopCommerce下载与安装
    DLT(Direct Linear Transform)算法
    向量叉乘与叉乘矩阵
    最小二乘与最大似然估计之间的关系
    最小二乘法
    Levenberg-Marquardt迭代(LM算法)-改进Guass-Newton法
    Newton法(牛顿法 Newton Method)
    自己所有博客汇总
    Unity 预制体烘焙光影丢失,Unity2018 预制嵌套
    XmlException: Text node canot appear in this state
  • 原文地址:https://www.cnblogs.com/lidabo/p/2815204.html
Copyright © 2020-2023  润新知