Thread-triggered event when ActiveX is embedded into the browser

Source: Internet
Author: User

8. Recommended

After ActiveX is embedded in the browser, the events triggered in the thread are no longer dynamic. If debugging is performed, the browser may be found to have an invalid error. If the same ActiveX is usedProgramIs normal.

The solution is to send a message in the thread, and the control responds to the message before fireevent.

1. Create a control project.
2. Class Wizard, use the add method to start the second thread and return. The followingCodeThe display method starts two threads and immediately returns to the mfcactivex control. The global function is also declared as a two-thread working function:
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. Add any event to be fired from the second thread using the Class Wizard.
4. Define to send custom emails from two threads. When you add a message ing entry to the Control Message ing to receive custom messages, the message processing function is called. This message processing program triggers a required event. Sample how to execute the following in the mfcactivex control:
// 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,
Lparam)
{
Firelengthyprocessdone ();
Return true;
}
5. It is a two-thread event that is triggered by a two-thread, and the time is posted back to the custom message defined in step 3 of the main thread. Trigger events. The following code demonstrates:
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;
}

At the same time, because the browser does not seem to create an ActiveX window, you need to add the code for creating the window.
MFC provides the function call colecontrol: createcontrolwindow () to create a control window. MFC implements ioleobject: setclientsite () to call colecontrol: onsetclientsite (). Convert the following to the-colecontrol derived class:

// Cmycontrol is derived from colecontrol.
Void cmycontrol: onsetclientsite ()
{
If (m_pclientsite)
// It doesn' t matter who the parent window is or what the size
// The window is because the control's window will be reparented
// And resized correctly later when it's in-place activated.
Verify (createcontrolwindow (: getshorttopwindow (), crect (0, 0, 0 ),
Crect (0, 0, 0 )));
Colecontrol: onsetclientsite ();
}

Refer:
Http://topic.csdn.net/t/20040109/17/2650433.html #
Http://support.microsoft.com/kb/195188/zh-cn
Http://support.microsoft.com/kb/157437

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.