Example:
wso = new ActiveXObject("Scripting.WindowSystemObject") wso.EnableVisualStyles = true form = wso.CreateForm(0,0,0,0) form.ClientWidth = 150 form.ClientHeight = 100 form.CenterControl() button = form.CreateButton(10,10,75,25,"Close") button.OnClick = ButtonClick function ButtonClick(Sender) { form.Close() } form.Show() wso.Run()
wso = new ActiveXObject("Scripting.WindowSystemObject");
Next we need to create a form and controls.
We use Show method to show the form.
The Run method starts message loop.
Example 2:
//WindowSystemObject (WSO) example //Copyright (C) Veretennikov A. B. 2004-2015 use("Common.js") o = new ActiveXObject("Scripting.WindowSystemObject") f = o.CreateForm(0,0,650,400) f.CenterControl() function MouseMove(sender,x,y,flags) { sender.Form.StatusBar.item(0).Text = x+" x "+y } function MouseExit(sender) { sender.Form.StatusBar.item(0).Text = "No Mouse In Control" } function MouseUp(sender,x,y,Button,Flags) { sender.Form.MessageBox("MouseUp "+x+" x "+y+", Button = "+Button) } function KeyDown(sender,Key,Flags) { if ((Key != 27) && (Key!=112)) sender.Form.MessageBox("KeyDown "+Key) } function ButtonClick(sender) { sender.Form.MessageBox("Button "+sender.text+": OnClick") } var canCloseVar function OKResult(sender) { canCloseVar = true sender.Form.Close() } function CanClose(Sender,Result) { canCloseVar = false var canCloseDialog = f.CreateDialogForm(0,0,510,100) canCloseDialog.CenterControl() canCloseDialog.TextOut(10,10,"Do you really want to quit this program?") var yesButton = canCloseDialog.CreateButton(10,30,75,25,"Yes") yesButton.OnClick = OKResult yesButton.Default = true var noButton = canCloseDialog.CreateButton(90,30,75,25,"No") noButton.OnClick = CloseFormHandler noButton.Cancel = true var helpButton = canCloseDialog.CreateButton(170,30,75,25,"Help") helpButton.OnClick = HelpAbout canCloseDialog.HelpButton = helpButton canCloseDialog.Color = 0xFF00FF canCloseDialog.ShowModal() canCloseDialog.Destroy() Result.Put(canCloseVar) } Button = f.CreateButton(10,10,75,25,"Demo") Button.AddEventHandler("OnClick",ButtonClick) CancelButton = f.CreateButton(100,10,75,25,"Close") CancelButton.OnClick = CloseFormHandler f.CreateStatusBar().Name = "StatusBar" f.StatusBar.Add(100).AutoSize = true f.OnMouseMove = MouseMove f.OnMouseLeave = MouseExit f.OnMouseUp = MouseUp f.OnKeyDown = KeyDown f.OnCloseQuery = CanClose 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 JScript.\x0D\x0DClicking any mouse button invokes OnMouseUp event handler.\x0D\x0DMoving mouse inside this window invokes OnMouseMove event handler.\x0D\x0D(The current mouse position is displayed in the status bar)\x0D\x0DMoving mouse outside this window invokes OnMouseLeave event handler.\x0D\x0DClicking Demo or Close buttons invokes OnClick event handler.\x0D\x0DPressing any key invokes OnKeyDown event handler.\x0D\x0DTry to close this window to invoke OnCloseQuery event.") fileMenu = f.Menu.Add("File") fileMenu.Add("Exit",27).OnExecute = CloseFormHandler helpMenu = f.Menu.Add("Help") helpMenu.Add("About","F1").OnExecute = HelpAbout f.Show() o.Run() function HelpAbout(Sender) { WSOAbout(Sender,"Event Handler Sample") } function CloseFormHandler(Sender) { Sender.Form.Close() } function LibraryDir() {s = WScript.ScriptFullName; s = s.substring(0,s.lastIndexOf("Demo")); return s+"Demo\\JScript\\Common\\"; } function use(s){eval(new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(LibraryDir() + s,1,false).ReadAll()) }