(This is not in the Other Utilities section because I'm really only interested in using it with AHK). Today I found WindowSystemObject. The binaries and source and be downloaded from there (32-bit and 64-bit DLLs, which for some reason get installed in "Program Files" and "Program Files (x86)", even though the dlls are the only file in either folder! The installer does register the COM objects, however.
From the project home page:
Main features:
Full set of features for creating window interfaces. Supports all standard windows controls.
ActiveX support (Internet Explorer, Windows Media Player and other).
It supports working with popular image formats that are BMP, JPEG, WMF, GIF.
WSO is a language-independent library. Only COM (Automation) support required.
Intuitive object model.
Events model. Rich set of Windows API constants is available as properties. An constant can be used by its name. Docking Framework. Visual Form Designer
Supports Windows 98SE, ME, NT 4, 2000, XP, 2003, Vista, 2008, 7, 2008 R2, 8, 8.1, 10.
Rich set of samples for different languages included in the distributive:
JScript
VBScript
Perl
Pascal
Java
Python
Ruby
HTML
WSH
WSC
Using ActiveScript.ahk it can be automated - I have tried to do it using only ComObjCreate, i.e.
which works, but I haven't figured out how deal with the event handlers yet. Any and all pointers (no pun intended) as to how to deal with WSO's event handlers purely in AHK will be vastly appreciated!
There is some extraneous testing code in the script below. An animated GIF is attached.
Perhaps of more interest is the information I got from running "tlibimp -P wso.dll" and "tlibimp -C wso.dll": If you're curious, see the dumps attached. There is a wealth of information.
The working code is below (as I mentioned, it needs ActiveScript.ahk, although you could probably do without it if you use a 32-bit ScriptControl - I haven't tried that, though).
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include ActiveScript.ahk
SetTitleMatchMode, 2
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try ; leads to having the script re-launching itself as administrator
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
wo := new ActiveScript("VBScript")
code =
(
'WindowSystemObject (WSO) example
'Copyright (C) Veretennikov A. B. 2004
Set o = CreateObject("Scripting.WindowSystemObject")
Set f = o.CreateForm(0,0,650,400)
f.CenterControl()
Sub MouseMove(this,x,y,flags)
this.Form.StatusBar.item(0).Text = CStr(x)+" x "+CStr(y)
End Sub
Sub MouseExit(this)
this.Form.StatusBar.item(0).Text = "No Mouse In Control"
End Sub
Sub MouseUp(this,x,y,Button,Flags)
this.Form.MessageBox "MouseUp "+CStr(x)+" x "+CStr(y)+", Button = "+CStr(Button)
End Sub
Sub KeyDown(this,Key,Flags)
If ((Key <> 27) And (Key <> 112)) Then this.Form.MessageBox "KeyDown "+CStr(Key)
End Sub
Sub ButtonClick(this)
this.Form.MessageBox "Button "+this.Text+": OnClick"
End Sub
int CanCloseVar
Sub OKResult(this)
CanCloseVar = 1
this.Form.Close()
End Sub
Function CanClose(Sender,Result)
CanCloseVar = 0
Set CanCloseDialog = f.CreateDialogForm(0,0,510,100)
CanCloseDialog.CenterControl()
CanCloseDialog.TextOut 10,10,"Do you really want to quit this program?"
Set YesButton = CanCloseDialog.CreateButton(10,30,75,25,"Yes")
YesButton.OnClick = GetRef("OKResult")
YesButton.Default = true
Set NoButton = CanCloseDialog.CreateButton(90,30,75,25,"No")
NoButton.OnClick = GetRef("CloseFormHandler")
NoButton.Cancel = true
Set HelpButton = CanCloseDialog.CreateButton(170,30,75,25,"Help")
HelpButton.OnClick = GetRef("HelpAbout")
CanCloseDialog.HelpButton = HelpButton
CanCloseDialog.Color = &H00FF00FF
CanCloseDialog.ShowModal()
CanCloseDialog.Destroy()
If CanCloseVar = 1 Then Result.Put(true) Else Result.Put(false)
End Function
Set Button = f.CreateButton(10,10,75,25,"Demo")
Button.AddEventHandler "OnClick",GetRef("ButtonClick")
Set CancelButton = f.CreateButton(100,10,75,25,"Close")
CancelButton.OnClick = GetRef("CloseFormHandler")
f.CreateStatusBar().Name = "StatusBar"
f.StatusBar.Add(100).AutoSize = true
f.OnMouseMove = GetRef("MouseMove")
f.OnMouseLeave = GetRef("MouseExit")
f.OnMouseUp = GetRef("MouseUp")
f.OnKeyDown = GetRef("KeyDown")
f.OnCloseQuery = GetRef("CanClose")
Set Text1 = f.TextOut(10,60,"WindowSystemObject")
Text1.Font.Size = 16
Text1.Color = 255
Text1.Font.Bold = true
f.TextOut 10,100,"This sample shows how to handle events from WindowsSystemObject using VBScript."+vbCr+vbCr+"Clicking any mouse button invokes OnMouseUp event handler."+vbCr+vbCr+"Moving mouse inside this window invokes OnMouseMove event handler."+vbCr+vbCr+"(The current mouse position is displayed in the status bar)"+vbCr+vbCr+"Moving mouse outside this window invokes OnMouseLeave event handler."+vbCr+vbCr+"Clicking Demo or Close buttons invokes OnClick event handler."+vbCr+vbCr+"Pressing any key invokes OnKeyDown event handler."+vbCr+vbCr+"Try to close this window to invoke OnCloseQuery event."
Set FileMenu = f.Menu.Add("File")
FileMenu.Add("Exit",27).OnExecute = GetRef("CloseFormHandler")
Set HelpMenu = f.Menu.Add("Help")
HelpMenu.Add("About","F1").OnExecute = GetRef("HelpAbout")
f.Show()
o.Run()
Sub HelpAbout(Sender)
o.About()
End Sub
Function StartupDir()
Dim s
s = WScript.ScriptFullName
s = Left(s,InStrRev(s,"\"))
StartupDir = s
End Function
Sub WSOHelp(Sender)
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run """"+StartupDir() + "..\..\wso.chm"+""""
End Sub
Sub AboutWSO_OnHitTest(Sender,x,y,ResultPtr)
ResultPtr.put(o.Translate("HTCAPTION"))
End Sub
Sub CloseFormHandler(Sender)
Sender.Form.Close()
End Sub
)
wo.Exec(code)
return
ShowInfo(object, objname) {
vartype := ComObjType(object)
name := ComObjType(object, "Name")
clsid := ComObjType(object, "CLSID")
cname := ComObjtype(object, "Class")
msgbox %objname%'s class is %cname%`r`nName is %name%`r`nCLSID is %clsid%`r`nVT is %vartype%
}
/*
[System.Windows.MessageBox]::Show('Would you like to play a game?','Game input','YesNoCancel','Error')
*/
Escape::ExitApp
;ATL:00000001801D89401 ; Button's ClassNN according to WindowSpy
/*
---------------------------
WSO4.ahk
---------------------------
button's class is Button
Name is IButton
CLSID is {0DE86A81-8827-4281-8C0C-965C34F25147}
VT is 9
---------------------------
OK
---------------------------
*/
in AHK. There are many examples of this in the code attached.
I was going to include the DLL in the attached archive, but it's probably better to install the thing if you're going work with WSO, so the COM gets registered. You can get WindowSystemObject at this link, look for WSO on the left.
Just another Notepad clone in AHK You need the file WSOConsts.ahk in the archive to be in script dir.
This is **Almost** working in AutoHotkey code also, instead of just executing JS as here, but I don't quite have it (95%). But I thought it was too wild to not share right away, so here is the JS version.
Using ActiveScript.ahk, attached just in case, the file 'ascript.ahk' runs 'littledoc.js'. I've included the WSO contants file again also, but the DLL is NOT here. See post above for installation links.
BTW, so far the JS version loads much faster than my AHK version, although I can't tell much difference between them after loading. I was surprised.
Regards,
burque505
P.S. Sorry about the artefacts (or artifacts, depending on which side of the pond you're on ) in the GIF.
;WindowSystemObject (WSO) example
;Copyright (C) Veretennikov A. B. 2004-2015
;This script by burque505, taken
;from a WSO stock demo in JScript
#Include WSOConsts.ahk
global Wso := ComObjCreate("Scripting.WindowSystemObject")
global Regions := Wso.Regions
; Form creation and init
global Form := Wso.CreateForm()
Form.SizeGrip := false
Form.Caption := false
Form.MaximizeBox := false
Form.Text := "Region Demo"
Form.ClientWidth := 300
Form.ClientHeight := 200
Form.CenterControl()
; "Close" button code
x := Form.CreateButton(120,90,75,25,"Close")
x.OnClick := func("Bail")
x.Default := true
x.Cancel := true
; The code here is really beyond me, especially the Wso.Translate stuff.
; But it does work :)
Ellipse := Regions.CreateEllipticRgn(20,20,260,160)
Ring := Regions.CombineRgn(Ellipse,Regions.CreateEllipticRgn(30,30,240,140),Wso.Translate("RGN_DIFF"))
Star := Regions.CreatePolygonRgn(150,0,220,200,0,60,300,60,80,200,Wso.Translate("WINDING"))
Region := Regions.CombineRgn(Ring,Star,Wso.Translate("RGN_OR"))
Form.Region := Region
; Note the color definition.
Form.Brush.Color := 0x00FF0000
Form.DrawRegion(0,0,Region)
global Text := Form.TextOut(40,70,"")
; must be global, apparently.
Text.Font.Bold := true
Text.Font.Color := 0x00FFFFFF
; This is to keep the clock ticking.
Timer1 := Wso.CreateTimer()
Timer1.Interval := 100
Timer1.Active := true
Timer1.OnExecute := Func("TimerExecute")
Form.Show()
Wso.Run()
TimerExecute(This) {
FormatTime, outvar, %A_Now%, HH:mm:ss tt MMM dd`, yyyy
Text.text := outvar
}
Bail(this) {
ExitApp
}