//比較好的教程 ocx 在 win7 系統會出現註冊需要管理員權限的問題,這時候需要用管理員身份運行 cmd,然後運行 regsvr32註冊。 很麻煩 嘗試使用 nsis 做成安裝包, 採用 regdll 註冊 ocx, 成功。
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);
});這兩種功能都可以在類別檢視裡面選擇 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.