在网页调用 WINDOWS 控件两例

一、这个是netmting的例子

 1<html>
 2<head>
 3<title>OCX</title>
 4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 5<script language="JavaScript">   
 6var flag=true   
 7function showall(){   
 8alist = new Array();   
 9newocx();   
10list1.value = "";   
11list2.value = "";   
12list1.value = ocxtype.outerHTML;   
13j = 0;   
14for (i in ocxtype)   
15{   
16alist[j] = i;   
17j++;   
18}   
19for (i = 0; i < alist.length; i++)   
20for (j = (alist.length-1); j > 0; j--)   
21{   
22if (alist[j] < alist[j-1])   
23{   
24temps = alist[j];   
25alist[j] = alist[j-1];   
26alist[j-1] = temps;   
27}   
28}   
29for (i = 0; i < alist.length; i++)   
30list2.value += alist[i] + "\n";   
31alert("共有 "+alist.length+" 个属性方法")   
32}   
33function newocx()   
34{   
35ocxfield.innerHTML = "<OBJECT ID='ocxtype' WIDTH='0px' HEIGHT='0px'" +   
36"CLASSID='CLSID:" + ocxid.value + "'></OBJECT>";   
37}   
38</script>
39</head>
40<body bgcolor="#FFFFFF" text="#000000">
41<div align="center">
42<p>classid   
43<input id="ocxid" onchange="jscript:flag=true" style="width:400" type="text" value="F3A614DC-ABE0-11d2-A441-00C04F795683"/>
44<input id="look" onclick="showall()" type="button" value="查看"/>
45</p>
46<table border="1" width="75%">
47<tr>
48<td height="24">
49<div align="center">html中的写法</div>
50</td>
51<td height="24">
52<div align="center">OCX中的属性事件</div>
53</td>
54</tr>
55<tr>
56<td>
57<textarea id="list1" readonly="" style="width: 500px; height: 400px;"></textarea>
58</td>
59<td>
60<textarea id="list2" readonly="" style="width:250px; height:400px;"></textarea>
61</td>
62</tr>
63</table>
64</div>
65<div id="ocxfield">
66</div>
67</body>
68</html>

二、

 1<script language="Javascript">   
 2function ShowMessenger() {   
 3if (messengerUI.object != null) {   
 4var MsgrWindow   
 5if (messengerUI.myStatus == 2) {   
 6MsgrWindow = messengerUI.window;   
 7MsgrWindow.show();   
 8}   
 9else   
10messengerUI.Signin(0,"","");   
11}   
12} 
13
14function ShowElement(element) {   
15element.style.display="";   
16document.msn.offline.value="ON";   
17}   
18function HideElement(element) {   
19//rowShow.style.visibility="hidden";   
20element.style.display="none";   
21document.msn.offline.value="OFF";   
22} 
23
24function ShowHide(element) {   
25if (document.msn.offline.value=="ON") {   
26HideElement(element);   
27}   
28else {   
29ShowElement(element);   
30} 
31
32}   
33</script>
1<style type="text/css">   
2<!--   
3.small { font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif}   
4body { font-family: Verdana, Arial, Helvetica, sans-serif}   
5a { color:#3D55C4 ; text-decoration: none}   
6a:link { color:#3D55C4 ; text-decoration: none}   
7a:hover { color:#000000 ; text-decoration: none}   
8\-->   
9</style>
  1<body bgcolor="#FFFFFF" onclick="(mUser.innerHTML)" text="#000000" vlink="##3D55C4">
  2<table bgcolor="#3D55C4" cellpadding="1" cellspacing="1" id="abc" width="150">
  3<script id="mcvbs" language="VBScript">   
  4' this script is loosely based on the original script from Microsoft.   
  5' Various flags and such for god-knows what...   
  6Dim A_   
  7A_=False   
  8Dim B_,C_,D_   
  9B_=False   
 10C_=False   
 11D_=False   
 12Dim E_,F_,G_   
 13E_=False   
 14F_=False   
 15G_=3000 ' Ooohhh! I know what this is! This is the amount of milliseconds for refresh   
 16Dim H_(),I_ ' H_() is an object array of users. This is also the cache   
 17I_=0   
 18' Variables for different links to different images representing state in Messenger... I think   
 19Dim J_,K_,L_,M_,N_,O_,P_,OffL   
 20J_="<OBJECT classid="""&"clsid:FB7199AB-79BF-11d2-8D94-0000F875C541"""&" codeType=application/x-oleobject id=MsgrApp width=0 height=0></OBJECT>"   
 21K_="<font class=""small"">"   
 22M_="<img align=absbottom width=16 height=17 border=0 src="   
 23L_="<br><b> <a href=""vbscript:op(-1)"" class=""color""><img src='msn_icons/msn_ppl.gif' border='0' alt=''>"&" Sign in now... "&"</a></b>"   
 24N_=M_&"msn_icons/online1.gif"&" ALT="""&"Online"&""">"   
 25O_=M_&"msn_icons/busy1.gif"&" ALT="""&"Busy"&""">"   
 26P_=M_&"msn_icons/idle1.gif"&" ALT="""&"Away"&""">"   
 27'Added by JH   
 28OffL = M_&"msn_icons/offline1.gif"&" ALT="""&"Offline"&""">"   
 29M_="<img align=absbottom width=16 height=17 border=0 src="   
 30Dim Q_   
 31Q_=False   
 32Dim ttl   
 33ttl=0   
 34' added arrays for online and offline contacts   
 35Dim OnA() ' online contacts   
 36Dim OffA() ' offline contacts   
 37' counters for amount of online and offline   
 38Dim OnCtr   
 39OnCtr=0   
 40Dim OffCtr   
 41OffCtr=0   
 42' Online/Offline? 
 43
 44Sub DrawInitialState   
 45On Error Resume Next   
 46Dim R_   
 47R_=MsgrObj.LocalState   
 48If Err Then   
 49A_=False   
 50Else   
 51A_=True   
 52End If   
 53Err.Clear   
 54If A_=True Then   
 55document.all.getmsgr.style.display="none"   
 56DrawContacts   
 57Else   
 58document.all.getmsgr.style.display="block"   
 59End If   
 60End Sub 
 61
 62Function HasMsgrApp()   
 63appload.innerHTML = J_   
 64On Error Resume Next   
 65Dim R_   
 66Set R_=MsgrApp   
 67If Err.description="" Then   
 68HasMsgrApp=True   
 69Else   
 70HasMsgrApp=False   
 71End If   
 72Err.Clear   
 73End Function 
 74
 75Sub RefreshMC()   
 76If A_ Then   
 77If C_ Then   
 78D_=True   
 79Else   
 80D_=False   
 81DrawContacts   
 82SetRefreshTimer   
 83End If   
 84End If   
 85End Sub 
 86
 87Sub SetRefreshTimer()   
 88If Not C_ Then   
 89C_=True   
 90setTimeout "DoRefresh",G_,"VBScript"   
 91End If   
 92End Sub 
 93
 94Sub DoRefresh()   
 95C_=False   
 96If D_ Then   
 97RefreshMC   
 98End If   
 99End Sub 
100
101Sub DrawContacts   
102'********************************************************************   
103' Modified by JH   
104' DrawContacts:   
105'   
106On Error Resume Next   
107' new list of contacts to iterate thru   
108' ctr for list loop   
109Dim i   
110i = 0   
111' strings for output   
112Dim z, zz   
113z=""   
114zz=""   
115' for div visibility   
116Dim mU,mO,msgL,noneL,notOn,onli   
117mU="none"   
118mO="none"   
119msgL="none"   
120noneL="none"   
121notOn="block"   
122onli="block"   
123If E_ Then   
124mcClearCache   
125End If   
126' The heart of the matter   
127If MsgrObj.LocalState And 2 Then   
128'Online   
129If Not F_ Then   
130mcLoadCache   
131End If   
132If I_>0 Then   
133For i = 0 To ttl   
134select case H_(i).State   
135case 1   
136OffCtr = OffCtr + 1   
137case else   
138OnCtr = OnCtr + 1   
139end select   
140Next   
141ReDim OnA(OnCtr)   
142ReDim OffA(OffCtr)   
143OnCtr = 0   
144OffCtr = 0   
145' loop to get FriendlyNames of contacts and put them in their respective arrays   
146For i = 0 To ttl   
147If H_(i).State=1 then   
148Set OffA(OffCtr)=H_(i)   
149OffCtr = OffCtr + 1   
150Else   
151Set OnA(OnCtr) = H_(i)   
152OnCtr = OnCtr + 1   
153End If   
154Next   
155' sort online users   
156SortUsers2 0,OnCtr-1,True   
157For i = 0 to OnCtr-1   
158Dim onl   
159Dim h   
160onl=""   
161h=""   
162h = " href='VBScript:op(" & i & ")'"   
163onl = fixName(OnA(i).FriendlyName,17)   
164z = z & "<a" & h & " class=""color"">" & getStateImage(OnA(i).State) & "</a> " & "<a " & h & " title="""   
165z = z & "Send an instant message to " & onl & "."   
166z = z & """ class=""color"">" & K_ & onl   
167z = z & "</font></a><br>"   
168Next   
169' sort offline users   
170SortUsers2 0,OffCtr-1,False   
171For i = 0 to OffCtr-1   
172Dim ofn   
173ofn=""   
174ofn = fixName(OffA(i).FriendlyName,17)   
175zz = zz & getStateImage(OffA(i).State) & " "   
176zz = zz & K_ & ofn & "<br>"   
177Next   
178if OnCtr > 0 Then   
179mU="block"   
180mO="block"   
181document.all.mUser.innerHTML=z   
182document.all.mOff.innerHTML=zz   
183else   
184mU="block"   
185mO="block"   
186document.all.mUser.innerHTML="<font class=""small"">None</font>"   
187document.all.mOff.innerHTML=zz   
188end if   
189Else   
190noneL="block"   
191document.all.noneol.innerHTML=K_&"Your contact list is empty. <br><a href=vbscript:op(-2) class=""color"">Add contacts to your list.</a>"&"</font>"   
192end if   
193Else   
194If MsgrObj.LocalState=256 Or MsgrObj.LocalState=512 Then   
195msgL="block"   
196notOn="none"   
197onli="none"   
198B_ = True   
199document.all.statu.innerHTML = "<br> <img src='msn_icons/msn_ppl.gif' border='0' alt=''> <b>Connecting...</b></div>"   
200Else   
201msgL="block"   
202notOn="none"   
203onli="none"   
204if Not B_ Then   
205document.all.statu.innerHTML = L_   
206End If   
207End If   
208End If   
209document.all.Online.style.display=onli   
210document.all.mUser.style.display=mU   
211document.all.notOnline.style.display=notOn   
212document.all.mOff.style.display=mO   
213document.all.msgrlogon.style.display=msgL   
214document.all.noneol.style.display=noneL   
215End Sub 
216
217Sub mcClearCache   
218I_=0   
219Erase H_   
220Erase OnA   
221Erase OffA   
222F_=False   
223E_=False   
224D_=True   
225End Sub 
226
227Sub mcLoadCache   
228Dim BB_ 
229
230Set BB_=MsgrObj.List(0) 
231
232Dim CB_   
233CB_=0   
234Dim DB_   
235DB_=BB_.Count   
236ttl=DB_ -1   
237Redim H_(DB_)   
238For Each u In BB_   
239Set H_(CB_)=u   
240CB_=CB_+1   
241Next   
242I_=CB_   
243SortUsers 0,I_-1   
244F_=True   
245End Sub 
246
247' Added by JH   
248' Sorts Online/Offline users   
249Sub SortUsers2(EB_,FB_,IsOn)   
250Dim GB_   
251if(IsOn) then   
252if FB_>EB_ then   
253GB_=ptnOn(EB_,FB_)   
254SortUsers2 EB_,GB_-1,True   
255SortUsers2 GB_+1,FB_,True   
256end if   
257else   
258if FB_>EB_ then   
259GB_=ptnOff(EB_,FB_)   
260SortUsers2 EB_,GB_-1,False   
261SortUsers2 GB_+1,FB_,False   
262end if   
263end if   
264End Sub 
265
266Sub SortUsers(EB_,FB_)   
267Dim GB_   
268if FB_>EB_ then   
269GB_=ptn(EB_,FB_)   
270SortUsers EB_,GB_-1   
271SortUsers GB_+1,FB_   
272end if   
273End Sub 
274
275' Added by JH   
276'   
277Function ptnOn(EB_,FB_)   
278Dim HB_,tmp   
279Randomize   
280HB_=Int(Rnd()Mod(FB_-EB_+1))+EB_   
281Set tmp=OnA(HB_)   
282Set OnA(HB_)=OnA(EB_)   
283Set OnA(EB_)=tmp   
284Dim a,b   
285a=EB_   
286b=FB_   
287While b>a   
288If StrComp(OnA(b).FriendlyName,tmp.FriendlyName,1)>=0 Then   
289b=b-1   
290Else   
291Set OnA(a)=OnA(b)   
292Set OnA(b)=OnA(a+1)   
293Set OnA(a+1)=tmp   
294a=a+1   
295End If   
296Wend   
297ptnOn=a   
298End Function 
299
300' Added by JH   
301'   
302Function ptnOff(EB_,FB_)   
303Dim HB_,tmp   
304Randomize   
305HB_=Int(Rnd()Mod(FB_-EB_+1))+EB_   
306Set tmp=OffA(HB_)   
307Set OffA(HB_)=OffA(EB_)   
308Set OffA(EB_)=tmp   
309Dim a,b   
310a=EB_   
311b=FB_   
312While b>a   
313If StrComp(OffA(b).FriendlyName,tmp.FriendlyName,1)>=0 Then   
314b=b-1   
315Else   
316Set OffA(a)=OffA(b)   
317Set OffA(b)=OffA(a+1)   
318Set OffA(a+1)=tmp   
319a=a+1   
320End If   
321Wend   
322ptnOff=a   
323End Function 
324
325SUB MsgrObj_OnLocalStateChangeResult(ByVal hr,ByVal mLocalState,pService)   
326If 0=hr And Err.description="" And A_ Then   
327If mLocalState=256 Or mLocalState=512 Then   
328B_=True   
329document.all.statu.innerHTML="Signing in..."   
330ElseIf mLocalState=1024 Then   
331B_=True   
332document.all.statu.innerHTML="Signing out..."   
333ElseIf mLocalState=1 then   
334B_=True   
335document.all.statu.innerHTML=L_   
336End If   
337RefreshMC   
338End If   
339END SUB 
340
341SUB MsgrObj_OnUserStateChanged(pUser,ByVal mPrevState,pfEnableDefault)   
342'If Err.description="" Then   
343mcClearCache   
344B_=False   
345RefreshMC   
346'End If   
347END SUB 
348
349SUB MsgrObj_OnListRemoveResult(ByVal hr,ByVal MLIST,ByVal pUser)   
350If 0=hr And 0=MLIST And Err.description="" Then   
351E_=True   
352RefreshMC   
353End If   
354END SUB 
355
356SUB MsgrObj_OnListAddResult(ByVal hr,ByVal MLIST,ByVal pUser)   
357If 0=hr And 0=MLIST And Err.description="" Then   
358E_=True   
359RefreshMC   
360End If   
361END SUB 
362
363SUB MsgrObj_OnLogonResult(ByVal hr,ByVal pService)   
364If 0=hr And Err.description="" Then   
365mcClearCache   
366B_=False   
367RefreshMC   
368Else   
369mcClearCache   
370B_=False   
371RefreshMC   
372End If   
373END SUB 
374
375SUB MsgrObj_OnLogoff()   
376mcClearCache   
377B_=False   
378RefreshMC   
379END SUB 
380
381SUB MsgrObj_OnAppShutdown()   
382RefreshMC   
383END SUB 
384
385  
386' Launches chat window for a given user, or   
387' launches the logon window, or simply brings up   
388' Messenger to show all contacts.   
389Function op(n)   
390If HasMsgrApp Then   
391If n>=0 Then   
392document.all.mctrack.src="P/6/"   
393On Error Resume Next   
394MsgrApp.LaunchIMUI OnA(n)   
395ElseIf-1=n Then   
396MsgrApp.LaunchLogonUI   
397Else   
398MsgrApp.Visible=1   
399End If   
400End If   
401End Function 
402
403Function htmlesc(str)   
404str=Replace(str,"&","&")   
405str=Replace(str,"<","<")   
406htmlesc=Replace(str,">",">")   
407End Function 
408
409Function fixName(s,max)   
410If Len(s)>max Then   
411s=Left(s,max-2)&"..."   
412End If   
413fixName=htmlesc(s)   
414End Function 
415
416Function getStateImage(t)   
417Select Case t   
418Case 1   
419getStateImage=OffL 'Offline   
420Case 2   
421getStateImage=N_ 'Online   
422Case 10   
423getStateImage=O_ 'Busy   
424Case 14   
425getStateImage=P_ 'BRB   
426Case 18   
427getStateImage=P_ 'Away   
428Case 34   
429getStateImage=P_ 'Away... as well.......   
430Case 50   
431getStateImage=O_ 'On The Phone   
432Case 66   
433getStateImage=O_ 'Out To Lunch   
434End Select   
435End Function   
436</script>
437<object classid="clsid:F3A614DC-ABE0-11d2-A441-00C04F795683" codetype="application/x-oleobject" height="0" id="MsgrObj" width="0">
438<span style="display:none;"> </span>
439</object>
440<script event="onReadyStateChange" for="mcvbs" language="VBScript">   
441If mcvbs.readyState="complete" And Not isDrawn_ Then   
442isDrawn_=True   
443DrawInitialState   
444End If   
445</script>
446<script event="onload" for="window" language="VBScript">   
447If Not isDrawn_ Then   
448isDrawn_=True   
449DrawInitialState   
450call HideElement(mOff)   
451End If   
452</script>
453<tr bgcolor="#3D55C4">
454<td class="small">
455<div align="center" class="small" id="msngrheading" style="width:100%; color: #eff7ff; background-color:#3D55C4; padding:3px; padding-left:0px;"><b>MSN Messenger</b></div>
456</td>
457</tr>
458<tr>
459<td bgcolor="#EFF7FF" class="small">
460<div align="center" class="small" id="getmsgr" style="DISPLAY:none;color:#000000;"><br/>Download<br/><a href=" http://messenger.msn.com/">Windows Messenger</a>
461<img alt="" height="1" id="mctrack" width="1"/>
462</div>
463<div class="small" id="msgrlogon" style="DISPLAY:none">
464<div class="small" id="statu" style="color:#000000"></div>
465</div>
466<!--ONLINE-->
467<div class="small" id="Online" style="DISPLAY:none;color:#000000"></div>
468<div class="small" id="noneol" style="DISPLAY:none;color:#000000"></div>
469<div class="small" id="mUser" style="DISPLAY:none;color:#000000"></div>
470<br/>
471<!--OFFLINE-->
472<div class="small" id="notOnline" style="DISPLAY:none;color:#000000">
473<b><a class="small" href="javascript:void(null)" onclick="ShowHide(mOff)"><img border="0" height="16" src="msn_icons/icon_messenger6.gif" width="16"/> Buddies offline</a></b>
474</div>
475<div class="small" id="mOff" style="DISPLAY:none; color:#000000"></div>
476<span class="small" id="appload" style="DISPLAY: none"></span>
477</td>
478<form name="msn">
479<input name="offline" type="hidden" value="ON"/>
480</form>
481</tr>
482</table>
483<br/></body>
Published At
Categories with 网页设计
Tagged with
comments powered by Disqus