COM Component Development Practices (eight)---multithreaded ActiveX controls and automatic resizing of ActiveX controls (bottom)

Source: Internet
Author: User
Tags thread

Disclaimer: This code is based on CodeProject's article, "A Complete ActiveX Web control Tutorial," and therefore also follows code Project Open License (Cpol).

In the previous article, COM Component Development Practice (VII)---Multithreaded ActiveX controls and automatic resizing of ActiveX controls (top) describes the basic requirements for using multithreading in ActiveX controls and presents a simple threading model, but there are unexpected problems. This article will try to give a feasible solution to the problem, and solve the second problem mentioned above.

In fact, the idea of the solution is also very simple, I have already thought of the beginning, is to use the thread postmessage to send a custom message to inform the main thread, the specific event has occurred, the demand main thread to respond. It's not a great idea, but I'm very scared of threading postmessage because it was the problem in a previous project that led to a memory leak, so the scheme was rejected by me at the outset.

All the way to find a solution can not be, had to CSDN forum on the post for the master, the specific discussion please refer to this thread:


See Jameshooo (Hu Pehua) after the reply, or decided to return to the starting point, try to use postmessage this scheme.

First, two events are customized to indicate operation success and operation failure

#define WM_OPTSUCCESS wm_app+101//Operation successful

#define WM_OPTFAILED wm_app+102//operation failed

Then the callback function becomes very simple and requires only the post corresponding event.

void CMyActiveXCtrl::OnSuccesful()

void CMyActiveXCtrl::OnFailed()

Overload the message-handling function WindowProc, in which you call an external JavaScript function or fire an event that the external page can respond to.

LRESULT CMyActiveXCtrl::WindowProc(UINT msg,WPARAM wParam,LPARAM lParam)
  switch (msg)
      CString strOnLoaded("OnLoaded");
      return 0;
  return  COleControl::WindowProc(msg,wParam,lParam);

To add the start work thread code to the OnCreate function:

int CMyActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  if (COleControl::OnCreate(lpCreateStruct) == -1)
    return -1;
  return 0;

Overload the OnClose function by adding code to close the worker thread:

void CMyActiveXCtrl::OnClose(DWORD dwSaveOption)

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: 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.