Try a different language, like Python or Lua. The reason is pretty simple. MS decided that VBScript shouldn't have a way to expose events to the script, unless the object is created in a different way, since the script system was designed for IE. When you use CreateObject is links to all the outgoing commands, but not events, since it has no internal event handler. In something like IE the object are created 'by' IE, then you use a script command to tell IE to tie the event 'DoSomething' to 'sub DoIt'. in the script itself. This is a limitation of JScript, VBScript and possibly PHP.
The solution is to instead use one of the tools in Python or Lua to generate what is called a 'wrapper'. This is basically just a set of definitions, which tell Python or Lua what the internals of the object look like, including events, much the same way that Nick provides a .TLB file you can import into compilers, so they know how to talk to Mushclient. Once you have such a wrapper, you can then create the object and use the internal event system of the script engine. VBScript doesn't even let you define such external links, for security reasons, or you could do things like:
Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long
Private Sub Form_Load()
If InternetAttemptConnect(ByVal 0&) = 0 Then
MsgBox "You can connect to the Internet", vbInformation
Else
MsgBox "You cannot connect to the Internet", vbInformation
End If
End Sub
The critical 'Lib "wininet"' part of the above is not allowed in any MS scripting system, since it would let people bypass security features to talk directly to Windows. Others do support it, which is why they can also tie events, like your added menu items, to the scripts.
Now, in theory, if someone could figure out how to mimic the way IE handles such objects, then you might be able to do it anyway, by ignoring CreateObject and having Mushclient handle the object creation, etc. But since no one really knows how it does what it does (or more specifically can reproduce it), there is no way to do it in the Microsoft based scripts, like VBScript. |