ATLÓëJavaScript½»»¥
ÔÌûµØÖ·£ºhttp://www.followman.com/bbs/Topic-B11-T262.aspx
JavaScript¶¯Ì¬ÏìÓ¦ATLʼþ
Ïà¹ØÌÖÂÛ:http://topic.csdn.net/t/20061012/21/5078729.html
ÖØ
µã£º½Å±¾´«¹ýÀ´µÄ¶ÔÏóÊÇIDispatch½Ó¿Ú£¬Ó¦¸ÃÓÃIDispatch::InvokeÀ´µ÷Óá£Èç¹û´«¹ýÀ´µÄÊǸöfunction£¬ÄÇôDISPID
Ϊ0£¬Èç¹ûÊǸö¶ÔÏó£¬ÄÇôҪÏÈÓÃGetIDsOfNamesµÃµ½DISPID£¬ÔÙInvoke¡£
Ïà¹ØÌÖÂÛ2:http://topic.csdn.net/u/20080418/12/3c09eb2c-fbb4-419f-8a6e-50d78ba8ff2d.html
¿Ø¼þҪʵÏÖʼþÀ´µ÷ÓÃJS½Å±¾£¬Ó¦¸ÃʹÓÃÊôÐÔ£¬ÒòΪJSÓïÑÔ±¾Éí²¢²»Ö§³ÖÁ¬½Óµã¡£¼ÙÉèÄãµÄ¿Ø¼þÊÇICtrl£¬ÒªÌí¼ÓÒ»¸öFirstEventʼþ£¬
ÏñÏÂÃæÕâÑù×ö£º
IDL£º
[propput]HRESULT FirstEvent(VARIANT* pEvent);
.h:
class CCtrl : public ICtrl
{
__stdcall HRESULT
put_FirstEvent(VARIANT* pEvent);
CComQIPtr <IDispatch>
m_spEvent;
void Fire_FirstEvent(VARIANT sType, VARIANT Msg);
}
.cpp:
HRESULT __stdcall CCtrl::put_FirstEvent(VARIANT*
pEvent)
{
assert(pEvent->vt == VT_DISPATCH);
m_spEvent = V_DISPATCH(pEvent);
return S_OK;
}
void
CCtrl::Fire_FirstEvent(VARIANT sType, VARIANT Msg)
{
if
(m_spEvent)
{
CComVariant args[2] = {sType, Msg};
DISPPARAMS dp = {args, NULL, 2, 0};
m_spEvent->Invoke(0,
IID_NULL, LOCALE_USE_DEFAULT, DISPATCH_METHOD, &dp, NULL, NULL,
NULL);
}
}
³É¹¦ÊµÀý:
IDL²¿·Ö:
[propget, id(2), helpstring("ÊôÐÔ OnShowText")]
HRESULT OnShowText([out, retval] IDispatchEx** pVal);
[propput,
id(2), helpstring("ÊôÐÔ OnShowText")] HRESULT OnShowText([in] IDispatchEx*
newVal);
JS²¿·Ö:
function
CreateATL()
{
this
.vv
=
"
ok
"
;
m
=
new
ActiveXObject(
"
ATLPro.AControl
"
);
m.OnShowText
=
function
()
//
OnShowText ÔÚATLÖÐÊÇÒ»¸ö IDispatchEx ¶ÔÏó
{
 
Ïà¹ØÎĵµ£º
µÚÎåÕ Êý×é JavaScriptµÄÊý×éÒ²ÊÇÒ»¸ö±È½ÏÓÐÒâ˼µÄÖ÷Ì⣬ËäÈ»ÃûΪÊý×é(Array)£¬µ«ÊǸù¾ÝÊý×é¶ÔÏóÉϵķ½·¨À´¿´£¬¸üÏñÊǽ«ºÜ¶à¶«Î÷»ìÔÚÔÚÒ»ÆðµÄ½á¹û¡£¶ø´«Í³µÄ³ÌÐòÉè¼ÆÓïÑÔÈçC/JavaÖУ¬Êý×éÄÚµÄÔªËØÐèÒª¾ßÓÐÏàͬµÄÊý¾ÝÀàÐÍ£¬¶ø×÷ΪÈõÀàÐ͵ÄJavaScript£¬ÔòûÓÐÕâ¸öÏÞÖÆ£¬ÊÂʵÉÏ£¬JavaScriptµÄͬһ¸öÊý×éÖУ¬¿ÉÒÔÓи÷ÖÖÍêÈ«²»Í ......
window.onload= someFunction();//Ò³Ã汨ÉÐδʵÏÖ´íÎóʱ²»·ÀÓÃÏÂÃæµÄÊÔÒ»ÏÂ
window.onload = someFunction;
window.onload = function (){someFunction();};
window.onload = Function("someFunction();"); ......
JavaScript¾ÍÕâô»ØÊÂ1£º»ù´¡ÖªÊ¶
1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </scri ......
<html>
<head>
<script language="javascript">
function overlay() {
xyz = document.getElementById("overlay");
&n ......
1£®ÔÚCOM×é¼þÖе÷ÓÃJavaScriptº¯Êý
// Á¬½Óµã·½Ê½Ò³Ãæjavascript½Å±¾
<object classid="CLSID:B568F111-DFE4-4944-B67F-0728AB2AB30F"
id="testCom" VIEWASTEXT></object>
<script language="JavaScript" for="testCom" event="staTe(s)">
&nbs ......