EDIT: Lexikos-supplied test build (Updated 24/3/2017)
Code: Select all
Gui commands:
-------------
GuiCreate([Title, Options, FuncPrefixOrObj])
Creates a new Gui object (Same as v1 Gui, New).
The third parameter specifies the function prefix or object to bind events to.
If a function prefix is specified, Gui events such as OnClose or OnDropFiles are automatically bound.
If an object is specified, it is used as an event sink; meaning event names are used as method names
to invoke on the object.
This mechanism is both similar to that of ComObjConnect() and the old v1 +Label system.
GuiFromHwnd(Hwnd [, RecurseParent := false])
Returns the Gui object associated with the specified Gui HWND.
If RecurseParent is true, the closest parent to the specified HWND that is a Gui is automatically
searched for and retrieved.
GuiCtrlFromHwnd(Hwnd)
Returns the Gui Control object associated with the specified Gui Control HWND.
Gui object:
-----------
gui.Destroy()
Destroys the window. Same as v1 Gui, Destroy.
If the Gui is closed and there are no references to the Gui object, the Gui is destroyed.
gui.Add(Ctrl [, Text, Options])
gui.AddCtrl([Text, Options]) where Ctrl is a valid control type
Adds a new control to the Gui. (Text was renamed to Label).
In v1.x, some control types such as ListView accept a string with a changeable delimiter (by default |).
In v2, arrays are also supported, and this obviates the need to support changing the delimiter.
The g-label option now specifies the function or method name to call in order to receive
events from the control (equivalent to v1 g-labels).
The 'v' option is now repurposed to give an explicit name to the control, instead of binding a variable.
For Button controls, if the g-label is omitted, the same v1 transformation rules are applied to
automatically generate a function or method name (expanded to accomodate for stricter identifier
names).
Returns a GuiControl object.
gui.Show([Options, Title])
Same as v1 Gui, Show
gui.Submit([Hide := true])
Returns an associative array containing the values of all the controls that have been explicitly named.
Similar to v1 Gui, Submit
gui.Hide()
gui.Cancel()
Same as v1 Gui, Hide (Cancel)
gui.SetFont([Options, FontName])
Same as v1 Gui, Font
gui.BgColor := color
gui.CtrlColor := color
Same as v1 Gui, Color
gui.MarginX := value
gui.MarginY := value
Same as v1 Gui, Margin
gui.Opt(options)
gui.Options(options)
Same as v1 Gui +/-Option1 +/-Option2
gui.Menu := menuObj
Same as v1 Gui, Menu
gui.Hide()
gui.Minimize()
gui.Maximize()
gui.Restore()
Same as v1 Gui, Hide/Minimize/Maximize/Restore
gui.Flash([onOrOff := true])
Same as v1 Gui, Flash [, Off]
gui.Hwnd
Retrieves the Gui's Hwnd
gui.Title
Sets or retrieves the Gui's title
gui.Control[Name]
Retrieves the GuiControl object associated with the specified name, ClassNN or HWND.
Compare:
GuiControl,, Static1, SomeValue
gui.Control["Static1"].Value := "SomeValue"
gui.FocusedCtrl
Returns the GuiControl object of the focused control, or an empty string.
gui._NewEnum()
Iterates through the Gui's controls.
The first output variable is the HWND, and the second is the control object.
gui.OnClose
gui.OnEscape
gui.OnSize
gui.OnContextMenu
gui.OnDropFiles
These properties can be get/set in order to change the event handlers, especially for
binding an arbitrary callable object.
Events:
OnClose(gui)
OnEscape(gui)
OnSize(gui, eventInfo, width, height)
OnContextMenu(gui, control, eventInfo, isRightClick, x, y)
OnDropFiles(gui, fileArray, control, x, y)
OnClose now has a return value. If OnClose() returns a false value (such as nothing), the Gui is closed
(as if the OnClose event handler did not exist). If it returns a true value, the Gui is not closed.
GuiControl object
-----------------
ctrl.Type
Retrieves the type of the control. (Not implemented yet)
ctrl.Hwnd
Retrieves the HWND of the control.
ctrl.Name
Retrieves or sets the explicit name of the control.
ctrl.ClassNN
Retrieves the ClassNN of the control.
ctrl.Gui
Retrieves the control's Gui parent.
ctrl.Event
Retrieves or sets the control's event handler, which can be either a function/method name
or an arbitrary callable object.
ctrl.Opt(options)
ctrl.Options(options)
Same as v1 GuiControl, +/-Option1 +/-Option2
ctrl.Move(pos[, draw:=false])
Same as v1 GuiControl Move(Draw)
ctrl.Focus()
Same as v1 GuiControl Focus
ctrl.Choose(Value [, additionalActions := 0])
Same as v1 GuiControl Choose(String). If Value is a pure integer, it is an item index;
otherwise it is treated as the item text. additionalActions replaces the pipe-prepending
mechanism of the v1 command (instead of prepending N pipes, this parameter is set to N).
ctrl.UseTab([Value, exactMatch := false])
Same as v1 Gui Tab. If Value is a pure intege, it is a tab index; otherwise it is text.
Omit all parameters to stop adding controls inside this Tab control.
ctrl.Value
Same as v1 GuiControl/Get with no subcommand
ctrl.Text
Same as v1 GuiControl/Get Text
ctrl.Enabled
Specifies whether the user can interact with the control
ctrl.Visible
Same as v1 GuiControl/Get Visible
ctrl.Focused
Same as v1 GuiControlGet Focused. (Not implemented yet)
ctrl.Pos
Returns the position in an object containing x,y,w,h fields.
Control event function:
ControlEvent(ctrl, guiEvent, eventInfo, extra)
The 'extra' parameter is only passed on Link or Custom control events.
LV_/TV_/SB_ functions are now methods of LV/TV/SB control objects.
tv.GetText() and lv.GetText() now return the text directly instead of having an
OutputVar (failure results in an exception being thrown).
-------------------------------------------------------------------------------
; Converted Example: Simple image viewer:
GuiCreate gui, ImageViewer, Resize, MyGui_
gui.AddButton &Load New Image, Default
radio := gui.AddRadio("Load &actual size", "ym+5 x+10 checked")
gui.AddRadio Load to &fit screen, ym+5 x+10
pic := gui.AddPic(, "xm")
gui.Show()
; Due to v2's Persistence rules, it is no longer necessary to include a
; GuiClose() { ExitApp } event handler in order for the script to properly close.
MyGui_ButtonLoadNewImage() ; using automatic event handler name
{
global gui, radio, pic
FileSelect file, a,, Select an image:, Images (*.gif; *.jpg; *.bmp; *.png; *.tif; *.ico; *.cur; *.ani; *.exe; *.dll)
if !file
return
if radio.Value = 1 ; Display image at its actual size.
{
Width := 0
Height := 0
}
else ; Second radio is selected: Resize the image to fit the screen.
{
Width := A_ScreenWidth - 28 ; Minus 28 to allow room for borders and margins inside.
Height := -1 ; "Keep aspect ratio" seems best.
}
pic.Value := "*w%width% *h%height% %file%" ; Load the image.
gui.Show xCenter y0 AutoSize, %file% - Image Viewer ; Resize the window to match the picture size.
}
-----------------------------------------------------------------------
; Converted Example: A moving progress bar overlayed on a background image.
GuiCreate gui, Progress Example,, MyGui_
gui.BgColor := "White"
gui.AddPicture %A_WinDir%\system32\ntimage.gif, x0 y0 h350 w450
gui.AddButton Start the Bar Moving, Default xp+20 yp+250
MyProgress := gui.AddProgress(, "w416")
MyText := gui.AddLabel(, "wp") ; wp means "use width of previous".
gui.Show()
MyGui_ButtonStartTheBarMoving()
{
global MyProgress, MyText
Loop Files, %A_WinDir%\*.*
{
if A_Index > 100
break
MyProgress.Value := A_Index
MyText.Value := A_LoopFileName
Sleep 50
}
MyText.Value := "Bar finished."
}