//比较好的教程
ocx 在 win7 系统会出现注册需要管理员权限的问题,这时候需要用管理员身份运行 cmd,然后运行 regsvr32注册。
很麻烦
尝试使用 nsis 做成安装包, 采用 regdll 注册 ocx, 成功。
方法属性可以提供给js调用,
事件可以给js 通过下面的方式进行回调注入
<object id="xxx"></object>
<script language="JavaScript" for="xx" Event="eventFunction(x)">
alert(x);
</script>
或者
document.getElementByIdx_x(xx).attachEvent("eventFunction",function(x,y){
alert(x);
});
alert(x);
});
这两种功能都可以在类视图里面选择 XXXCtrl,右键选择 add ,会出现 方法属性事件
按照wizard进行添加就好。
主要记录一下如果ocx创建了线程,想通过事件回调js的话,会出现问题。
这时候解决方法就是通过 PostMessage(WM_THREADFIREEVENT,(WPARAM)NULL,(LPARAM)NULL); 下面的看看应该懂了
//-------------------------
SAMPLE: Firing Events From a Second Thread
---------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual C++, 32-bit Edition versions 4.0, 4.1, 4.2
---------------------------------------------------------------------
SUMMARY
=======
MFC based ActiveX controls typically fire their events from the same thread
that implements the sink interface of the container that the events are
being fired to.
Sometimes, it is desirable to start a second thread in an ActiveX control
which will fire events to the container. Since MFC ActiveX controls
use the Apartment threading model, special consideration must be taken
into account when firing events from a secondary thread.
MORE INFORMATION
================
An MFC based ActiveX control supports events by implementing the
IConnectionPointContainer and IConnectionPoint interfaces, as well as
supplying information about it's event interface in it's type information.
When an MFC based ActiveX control is embedded in a container that supports
events, that container will dynamically construct a sink interface that has
all of the methods specified in the control's type information for it's
event interface. Once the container constructs it's sink interface, it
will pass a pointer to that interface to the ActiveX control. The ActiveX
control will use it's implementation of IConnectionPoint to communicate
through the now hooked up sink interface that was constructed by the
container. This sample will demonstrate how to call methods of the
container's sink interface from a second thread.
The two most important things to consider when starting a new thread to
fire events from in an ActiveX control are:
1. MFC based ActiveX controls are in-process objects (implemented in a
DLL).
2. MFC based ActiveX controls use the Apartment threading model.
The Apartment threading model specifies that all threads that want to use
OLE services must initialize OLE in their thread prior to using OLE
services. Also, if a thread wants to use a pointer to an interface that is
either implemented by a different thread of the same process or has been
previously marshaled to a different thread of the same process, that
pointer must be marshaled to the requesting thread. In the Apartment
threading model, hidden windows are created to synchronize requests from
other threads to the thread being called. This means that all
communication between threads will be done by using hidden windows and
Windows messages in the Apartment model.
There are two possible ways to fire events from a second thread in an
ActiveX control (or any other in-proc server that implements connection
points) under the Apartment threading model. The first is to make the
interface call from the second thread by calling the event sink's method
from the second
---------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual C++, 32-bit Edition versions 4.0, 4.1, 4.2
---------------------------------------------------------------------
SUMMARY
=======
MFC based ActiveX controls typically fire their events from the same thread
that implements the sink interface of the container that the events are
being fired to.
Sometimes, it is desirable to start a second thread in an ActiveX control
which will fire events to the container. Since MFC ActiveX controls
use the Apartment threading model, special consideration must be taken
into account when firing events from a secondary thread.
MORE INFORMATION
================
An MFC based ActiveX control supports events by implementing the
IConnectionPointContainer and IConnectionPoint interfaces, as well as
supplying information about it's event interface in it's type information.
When an MFC based ActiveX control is embedded in a container that supports
events, that container will dynamically construct a sink interface that has
all of the methods specified in the control's type information for it's
event interface. Once the container constructs it's sink interface, it
will pass a pointer to that interface to the ActiveX control. The ActiveX
control will use it's implementation of IConnectionPoint to communicate
through the now hooked up sink interface that was constructed by the
container. This sample will demonstrate how to call methods of the
container's sink interface from a second thread.
The two most important things to consider when starting a new thread to
fire events from in an ActiveX control are:
1. MFC based ActiveX controls are in-process objects (implemented in a
DLL).
2. MFC based ActiveX controls use the Apartment threading model.
The Apartment threading model specifies that all threads that want to use
OLE services must initialize OLE in their thread prior to using OLE
services. Also, if a thread wants to use a pointer to an interface that is
either implemented by a different thread of the same process or has been
previously marshaled to a different thread of the same process, that
pointer must be marshaled to the requesting thread. In the Apartment
threading model, hidden windows are created to synchronize requests from
other threads to the thread being called. This means that all
communication between threads will be done by using hidden windows and
Windows messages in the Apartment model.
There are two possible ways to fire events from a second thread in an
ActiveX control (or any other in-proc server that implements connection
points) under the Apartment threading model. The first is to make the
interface call from the second thread by calling the event sink's method
from the second