Some small ActiveX examples

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

garry
Posts: 3759
Joined: 22 Dec 2013, 12:50

Some small ActiveX examples

22 Dec 2013, 12:56

MODIFIED=20150214
combined 6 examples in 2 GUI

;- ActiveX example plays:
; Television TV
; Youtube
; Vimeo
; Radio
; Weather 'Current severe weather warnings for the Philippines'
; Picture

Code: Select all

MODIFIED=20150214/2
Title1=ActiveX_Example
;----------------------------------------------------------------------
;-  http://ahkscript.org/boards/viewtopic.php?f=6&t=6403   ;- this
;-  http://ahkscript.org/boards/viewtopic.php?f=28&t=1105

;   XP netbook AHK_L
;-  2 ActiveX GUI's
;-  creates templates weather.htm  and black.htm  ( a_scriptdir )
;-  downloads a test picture to desktop
;
;-  ActiveX example plays:
;     Television TV
;     Youtube
;     Vimeo
;     Radio
;     Weather 'Current severe weather warnings for the Philippines'
;     Picture
;
;     remarks : maybe url changes , then not works
;----------------------------------------------------------------------

;xxx=Shell.Explorer     ;- Microsoft windows browser
xxx=Mozilla.Browser    ;- mozilla firefox browser

a:=1
wa:=950
wg:=(wa+20)
ha:=650
hg:=(ha+70)
yb:=(ha+20)
numberofguis:=2
Loop % NumberOfGuis
{
b :=10
	Gui %A_Index%: Default
        Gui,%A_Index%:Color,Black
	gct := A_Index
        Gui,%gct%:Add,ActiveX, x10 y3 w%wa% h%ha% vWB%A_Index% ,%xxx%
        loop,3
         {
         Gui,%gct%:Add,Button , x%b% y%yb% h25 w140 v%gct%BT%A_Index% g%gct%Start%a_index%,
         b:=(b+150)
         }
Gui,%gct%:show,x%a% y3 w%wg% h%hg%,%title1%_%a_index%
a:=(a+wa+28)
wa:=700
wg:=(wa+20)
ha:=(650+70)
hg:=(ha+70)
yb:=(ha+20)
}
GuiControl,1:,1bt1, TV-SWISS
GuiControl,1:,1bt2, YouTube
GuiControl,1:,1bt3, VIMEO

GuiControl,2:,2bt1, Radio-Brazil-MPB
GuiControl,2:,2bt2, Weather-Philippines
GuiControl,2:,2bt3, Picture
;GuiControl,Disable,2Bt3

;-- 1st GUI
;gosub,1start1
;gosub,1start2
;gosub,1start3
;-- 2nd GUI
;gosub,2start1
gosub,2start2
gosub,2start3
return
;-------------

Guiclose:
fx=%a_scriptdir%\weather.htm
ifexist,%fx%
  filedelete,%fx%
exitapp

;-----------------------------
1start1:
f2:="http://www.srf.ch/livestream/player/srf-info"
WB1.Navigate(F2)
gosub,weather
WB2.Navigate(F1)
return

1start2:
id=nKKBmnIfQxg   ; portugal
;F2=https://www.youtube.com/v/%id%&index=1&list=RDnKKBmnIfQxg&autoplay=1         ; portugal
F2=https://www.youtube.com/v/%id%&autoplay=1
WB1.Navigate(F2)
gosub,weather
WB2.Navigate(F1)
return

1start3:
F2=https://player.vimeo.com/video/102051605#at=2  ;- Korea North
WB1.Navigate(F2)
gosub,weather
WB2.Navigate(F1)
return
;-------------------------

2start1:
f2:="http://www.collectors.com.br/radio/AS3/index.html"
;f2:="about:blank"
WB2.Navigate(F2)
gosub,black
WB1.Navigate(F1)
return

2start2:
gosub,weather
WB2.Navigate(F1)
return

2start3:
F0=http://i.imgur.com/pgCT683.jpg
F1=%a_desktop%\China_Canada_Joke.jpg
ifnotexist,%f1%
   urldownloadtofile,%f0%,%f1%
F2:= "file:///" RegExReplace(F1,"\\","/")
WB1.Navigate(F2)
return
;---------------------------


Black:
wa:=(950-20)
ha:=(650-20)
fx=%a_scriptdir%\black.htm
ifnotexist,%fx%
{
e5x=
(Ltrim Join`r`n
<div style="margin:0px;padding:0px;width:%wa%px;height:%ha%px;border:1px solid black;background-color: #000000;">
</div>
)
fileappend,%e5x%`r`n,%fx%
}
stringreplace,fx,fx,\,/,all
F1:="file:///" . fx
return
;-----------------------------


Weather:
wa:=(wa-20)
ha:=(ha-20)
;-http://weather.com.ph/swc
fx=%a_scriptdir%\weather.htm
;ifexist,%fx%                      ;- get newest or this is deleted when GUI-close
;  filedelete,%fx%
ifnotexist,%fx%                    ;- create once when GUI starts
{
e5x=
(Ltrim Join`r`n
<!-- Begin weather.com.ph map -->
<div style="margin:0px;padding:0px;width:%wa%px;height:%ha%px;border:1px solid black;background-color: #000000;">
<a href="http://weather.com.ph" alt="Current severe weather warnings for the Philippines" title="Current severe weather warnings for the Philippines">
<img src="http://weather.com.ph/layer/warningmaps/philippines_index.png" style="border:0px;margin:0px;padding:0px;width:680px;height:680px" alt="Current severe weather warnings for the Philippines" />
</a>
</div>
<!-- End weather.com.ph map -->
)
fileappend,%e5x%`r`n,%fx%
}
stringreplace,fx,fx,\,/,all
F1:="file:///" . fx
return
;================== end script ========================================================

play Youtube
蔡琴國語老歌 Chinese Old Songs
or
Television

Code: Select all

Modified =20131222
Filename1=YT_TV_test

/*
a small example ActiveX and Menu
shows youtube and TV  in a Gui
download AHK_L ( if notexist)  :
      http://l.autohotkey.net/AutoHotkey_L_Install.exe
and rename this text to xy.ahk
*/


#NoEnv                       ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1
Sendmode,input
Gui,2: Color, teal
Gui,2:Font,  S10 CDefault , FixedSys

gosub,check1

;- menu example
   Menu,S1,add,YT-Calypso             ,MH1
   Menu,S1,add,YT-Sunset              ,MH1
   Menu,S1,add,YT-ChineseOldies       ,MH1

   Menu,S2,add,TV-Nederland           ,MH2

   ;----------------------------
   menu,myMenuBar,Add,Youtube ,:S1
   menu,myMenuBar,Add,TV_NL   ,:S2

   ;----------------------------
   gui,2:menu,MyMenuBar
   ;----------------------------

h1=550
w1=820

h2=580
w2=840

Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1, Shell.Explorer
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Mozilla.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Chrome.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Maxthon.Browser

ComObjError(false)
F1:="file:///" RegExReplace(Fhtm,"\\","/")                               ;- black background
WB1.Navigate(F1)
gosub,test1           ;- for test
Gui,2: Show,x0 y0 w%w2% h%h2%,%filename1%
return

Test1:
;- Lisboa natal
WB1.Navigate("http://www.youtube.com/watch_popup?v=4JhkdUiY1ns")
return


2Guiclose:
exitapp

;---- menu ---------------
mh1:
if A_thisMenuItem=yt-calypso             ;- Grace Chang
   WB1.Navigate("http://www.youtube.com/watch_popup?v=a502on4D_1k")
if A_thisMenuItem=yt-Sunset  ;- Tsai Chin
   {
   id=XEvoFLbvXMc
   start=1500      ;- seconds
   endtm=1677
   F1=http://youtube.googleapis.com/v/%id%?start=%start%&end=%endtm%&autoplay=1&version=3
   WB1.Navigate(F1)
   }
if A_thisMenuItem=YT-ChineseOldies       ;- Tsai Chin full
   WB1.Navigate("http://youtube.googleapis.com/v/XEvoFLbvXMc?autoplay=1&version=3")
return


mh2:
WB1.Navigate("http://nos.nl/livestream/embed/journaal24/")
return


check1:
;--- create a black template for IE ---
fhtm=%a_scriptdir%\%a_scriptname%_template.htm
e4x=
(Ltrim Join`r`n
<style type="text/css">
  body {
       background-color: #000000;
       margin: 10px;
       padding: 100px;
       color: #fff;
       overflow-y: hidden;
       }
</style>
)
ifnotexist,%fhtm%
  fileappend,%e4x%`r`n,%fhtm%
return

;============ end script ===================================

can't use youtube in china (?)
another example with TV / Radio / Picture

Code: Select all

modified=20131224
; needs internet
; see   /TV_nederland /Radio_Brasil_mpb / Picture

#NoEnv                       ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1
Sendmode,input

filename1=TV-Nederland_Radio-Brasil_Joke_%modified%

Gui,2: Color, teal
Gui,2:Font,  S10 CDefault , FixedSys

gosub,createtemplate

;- menu example
   Menu,S1,add,TV-Nederland           ,MH1
   Menu,S2,add,RadioBrasil            ,MH2
   Menu,S3,add,Joke                   ,MH3

   ;----------------------------
   menu,myMenuBar,Add,TV_NL        ,:S1
   menu,myMenuBar,Add,RadioBrasil  ,:S2
   menu,myMenuBar,Add,Joke         ,:S3

   ;----------------------------
   gui,2:menu,MyMenuBar
   ;----------------------------

h1=550
w1=1080

h2=570
w2=1100

;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1, Shell.Explorer
Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Mozilla.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Chrome.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Maxthon.Browser

ComObjError(false)
FT:="file:///" RegExReplace(Fhtm,"\\","/")     ;- black background
WB1.Navigate(FT)
gosub,mh3                                      ;- show first a picture_joke
Gui,2: Show,x0 y0 w%w2% h%h2%,%filename1%
return
;-----------------------------------------------------

2Guiclose:
exitapp
;-----


;---- menu ---------------

mh1:
;- television nederland
WB1.Navigate("http://nos.nl/livestream/embed/journaal24/")
return
;-----

mh2:
;- radio brasil MPB oldies from 1940
mpb:="http://www.collectors.com.br/radio/AS3/index.html"
WB1.Navigate(mpb)
return
;-----

mh3:
;- save a picture to desktop
F0=http://i.imgur.com/pgCT683.jpg
F1=%a_desktop%\China_Canada_Joke.jpg
ifnotexist,%f1%
   urldownloadtofile,%f0%,%f1%
F2:= "file:///" RegExReplace(F1,"\\","/")
WB1.Navigate(F2)
return
;-------


createtemplate:
;--- create a black template for IE ---
fhtm=%a_scriptdir%\%a_scriptname%_template.htm
e4x=
(Ltrim Join`r`n
<style type="text/css">
  body {
       background-color: #000000;
       margin: 10px;
       padding: 100px;
       color: #fff;
       overflow-y: hidden;
       }
</style>
)
ifnotexist,%fhtm%
  fileappend,%e4x%`r`n,%fhtm%
return
;============ end script ===================================
Jokes Random

Code: Select all

;-- randomjoke with :  activeX / urldownloadtoVar
;-- AHK_L
;--------------------------------------------------
modified=20131226
filename1=RandomJoke_%modified%

setworkingdir,%a_scriptdir%
Filename1   =RandomJoke_%modified%

fx=http://www.randomfunnyjokes.com
f2=%a_scriptdir%\testjoke2.htm

Gui,2: Color, 000000

w1=750
h1=380

w2=770
h2=440

;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1, Shell.Explorer
Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Mozilla.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Chrome.Browser
;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Maxthon.Browser

hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")         ;Create the Object

Gui,2:add,button, x650 y400 h25 w100 gMh1,NEXT
Gui,2: Show,x0 y0 w%w2% h%h2%,%filename1%
gosub,mh1
return
;-----------------------------------------------------

2Guiclose:
exitapp
;-----

mh1:
Gui,2:submit,nohide

ComObjError(false)
hObject.Open("GET",fx)                    ;Open communication
hObject.Send()                            ;Send the "get" request
aac:=hObject.ResponseText                 ;Set the  "aac" variable to the response

T  := StrX( aac, "<table",1,0, "</table>",1,0 )
FileAppend, %t%, %f2%
F3:="file:///" RegExReplace(F2,"\\","/")
WB1.Navigate(F3)
t=
aac=
filedelete,%f2%
Return
;-----------------


;--- Function StrX by user SKAN --------------------------
;--- http://www.autohotkey.com/forum/viewtopic.php?t=51354
StrX( H,  BS="",BO=0,BT=1,   ES="",EO=0,ET=1,  ByRef N="" ) { ;    | by Skan | 19-Nov-2009
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO
 <0)?(1):(BO))))?(T+BT):(X+1)):(1)),(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z
 +(0-ET)):(X+P)):(X)))-P) ; v1.0-196c 21-Nov-2009 www.autohotkey.com/forum/topic51354.html
}
;===========================================================================================

another example , play radio Taiwan Nostalgia

Code: Select all

f1=%a_desktop%\Taiwan_Nostalgia.pls
ifnotexist,%f1%
  {
  e4x=
  (Ltrim Join`r`n
  [playlist]
  numberofentries=1
  File1=http://1.34.113.167:8000
  Title1=(#1 - 4/64) Nostalgia Taiwan Radio
  Length1=-1
  Version=2
  )
  fileappend,%e4x%,%f1%
  }
run,%f1%
exitapp
actual date and time in China ( UTC + 8 )

Code: Select all

modified=20140426

#NoEnv
SendMode,Input
SetWorkingDir,%A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1

filename1=China-CST-Time_UTC +8
f1=http://free.timeanddate.com/clock/i44gnm06/n33/tltw/fn6/fs16/fc9ff/tc000/ftb/bas2/bat1/bacfff/pa8/tt0/tw0/tm3/td2/th1/ta1
;- CST=ChinaStandardTime
;- DST=NO
;- http://www.timeanddate.com/worldclock/fullscreen.html?n=33#
;- http://www.timeanddate.com/worldclock/city.html?n=33
;- http://www.timeanddate.com/clocks/free.html?n=33

Gui,2: Color, teal
Gui,2:Font,  S10 CDefault , FixedSys
h1=40
w1=250
h2=60
w2=270

;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 , Shell.Explorer    ;- MS-IE
Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Mozilla.Browser    ;- FireFox
ComObjError(false)
WB1.Navigate(F1)
Gui,2: Show,x0 y0 w%w2% h%h2%,%filename1%
return
;-----------------------------------------------------

2Guiclose:
exitapp
;============ end script ===================================

Drag & Drop video audio text picture

Code: Select all

modified=20140630
;- ActiveX example
;- drag & drop video/audio/picture/text-files 
;- XP / netbook / Mozilla-Firefox / videolan / AHK_L

#NoEnv                       ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input               ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1
Sendmode,input

filename1=VideoPlay_Drag&Drop Video/Audio-Files here_%modified%

Gui,2: Color, teal
Gui,2:Font,  S10 CDefault , FixedSys

h1=550
w1=1080

h2=570
w2=1100

Gui,2:Add,Edit,    x10 y10 h0 w0 vF1,

;Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1, Shell.Explorer    ;- not works
Gui,2:Add,ActiveX, x10 y10 w%w1% h%h1% vWB1 ,Mozilla.Browser    ;- Firefox ok

Gui,2: Show,x0 y0 w%w2% h%h2%,%filename1%
return
;-----------------------------------------------------

2Guiclose:
exitapp
;-----

2GuiDropFiles:
Loop, parse, A_GuiEvent, `n
   GuiControl,2:,F1,%A_LoopField%
gosub,mh3
return


mh3:
Gui,2:submit,nohide
F1=%f1%
Extx := "flv,mp4,vob,wma,mp3,jpg,ico,pdf,txt,ini,ahk,ahl,"    ;- some extensions
SplitPath,F1,name, dir, ext, name_no_ext, drive
if ext in %extx%
 {
 Fx:="file:///" RegExReplace(F1,"\\","/")
 WB1.Navigate(Fx)
 return
 }
return
;============= end script =======================
Last edited by garry on 14 Feb 2015, 09:18, edited 8 times in total.
User avatar
amnesiac
Posts: 186
Joined: 22 Nov 2013, 03:08
Location: Egret Island, China
Contact:

Re: small ActiveX example

22 Dec 2013, 19:10

A good example. Thank you. Unfortunately, I can't connect to the youtube.
abs
Posts: 15
Joined: 06 Jan 2014, 01:28

Re: Some small ActiveX examples

12 Jan 2014, 21:03

Greate job!
I just get the idea that chrome.browser/firefox.browser can work as shell.explorer.

My question is, the real chrome has been really run or not?
Through task manager it can't be found a chrome.exe.
and I hope to control chrome for text&url save, auto password input, etc.
Can you show me how
abs
Posts: 15
Joined: 06 Jan 2014, 01:28

Re: Some small ActiveX examples

12 Jan 2014, 21:26

I tried to replace xxx.browser with any character .browser or even just browser itself, and it always works...
(just becoz I input firefox.browser rather than mozzila.browser above in mistake..)
and I believed that xxx.browser always used windows.browser..

Is it right?
garry
Posts: 3759
Joined: 22 Dec 2013, 12:50

Re: Some small ActiveX examples

15 Jan 2014, 16:26

sorry for late answer
I just realized , the WindowSpy function shows me for

-Mozilla.Browser =
ClassNN: MozillaWindowClass1

and for all others
-xxxx.Browser
-Maxthon.Browser
-Chrome.Browser
-Shell.Explorer
ClassNN:Internet Explorer_Server1

(which is always Shell.Explorer from MS_IE I think)

so in script above shoul'd only use :
-Mozilla.Browser
or
-Shell.Explorer

You can ask again in forum ( have lack of knowledge )

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 22 guests