Recently, I helped my friends develop a things. I used ahk as the shell (the full screen untitled top window is easy to implement with ahk). The content is the loaded html (which includes some flash, communication with flash and html), but this is not the focus, the focus is that later html (js/flash) control to disable ahk, this demand is hard for me, I never imagined how to implement it.
Today, I accidentally read the section about activeX in the ahk help document. I found that the example shows how to use ComObjConnect to handle public events of objects. So I came up with a clever method, which is very simple to implement, I am so embarrassed to write an article to introduce this method, but I still want to record it, because it is really useful.
Ahk code:
# NoEnv
# SingleInstance focus
Gui, Add, ActiveX, w700 h400 vWB, Shell. Explorer
WB. Navigate (A_ScriptDir. "\ index.html ")
The focus is on
ComObjConnect (WB, WB_events)
Gui, Show
Return
Class WB_events
{
; Processing method, of course, you can also listen to other events
NavigateComplete2 (wb, url)
{
Simple parsing with SplitPath is very convenient
SplitPath, url, fullCmd, DISCARD, opt, cmd
If (cmd = "test ")
{
Traytip, Test, This is "test" command.
}
Else if (cmd = "_ CLOSE __")
{
ExitApp
}
Else
{
Traytip, % fullCmd %, cmd: % cmd % ', opt: % opt %
}
}
}
GuiEscape:
GuiClose:
Exitapp
Html code:
<Ul>
<Li> <a href = "test" target = "_ cp"> test </a> </li>
<Li> <a href = "command. options" target = "_ cp"> aaa. bbb </a> </li>
<Li> <a href = "_ CLOSE _" target = "_ cp"> close </a> </li>
</Ul>
<Iframe name = "_ cp" src = "about: blank" style = "display: none;"> </iframe>
Brief description: www.2cto.com
Put an iframe in html to receive the "command" and write the "command" to be sent on the link. ahk listens to the NavigateComplete2 event, parse the url in the processing function (the format is defined by myself. I think of a simple rule as command. options, so that the SplitPath method can be easily used to parse all parts and then hand over all the work to ahk ;)