Gui Object

class Gui extends Object

Provides an interface to create a window, add controls, modify the window, and retrieve information about the window. このようなウィンドウは、データ入力フォームやカスタムユーザーインターフェイスとして使用することができます。

GuiオブジェクトはGui()で作成し、GuiFromHwndで取得することができます。

"Gui"はクラスそのものなので、以下ではあらゆるGuiオブジェクトのプレースホルダー(例では変数名)として "MyGui"を使用します。

Guiオブジェクトは、Objectから継承されたメソッドやプロパティに加え、以下のような定義済みのメソッドやプロパティを持ちます。

目次

静的メソッド

Call

Creates a new window.

MyGui := Gui(Options, Title, EventObj)
MyGui := Gui.Call(Options, Title, EventObj)

パラメータ

Options

型:文字列

Any of the options supported by Gui.Opt.

タイトル

型:文字列

If omitted, it defaults to A_ScriptName. Otherwise, specify the window title.

EventObj

型:Object

「イベントシンク」、つまりイベントをバインドするためのオブジェクトです。EventObjを指定した場合、OnEventOnNotifyOnCommandを使用して、イベントが発生したときに呼び出されるEventObjのメソッドを登録することができる。

戻り値

型:Object

This method or function returns a Gui object.

メソッド

Add

Creates a new control and adds it to the window.

GuiCtrl := MyGui.Add(ControlType , Options, Text)
GuiCtrl := MyGui.AddControlType(Options, Text)

パラメータ

ControlType

型:文字列

これは、以下のいずれかとなります:ActiveX, Button, CheckBox, ComboBox, Custom, DateTime, DropDownList (or DDL), Edit, GroupBox, Hotkey, Link, ListBox, ListView, MonthCal, Picture (or Pic), Progress, Radio, Slider, StatusBar, Tab, Tab2, Tab3, Text, TreeView, UpDown

事例:

MyGui := Gui()
MyGui.Add("Text",, "Please enter your name:")
MyGui.AddEdit("vName")
MyGui.Show
Options

型:文字列

If blank or omitted, the control starts off at its defaults. Otherwise, specify one or more of the following options and styles, each separated from the next with one or more spaces or tabs.

コントロールの位置づけとサイズ

オプションで寸法や座標が省略された場合、コントロールはその性質や内容に応じて、前のコントロールとの相対的な位置関係や大きさを自動的に決定します。

以下のオプションに対応しています:

Rn:Rows of text (where n is any number, even a floating point number such as r2.5). R is often preferable to specifying H (Height). If both the R and H options are present, R will take precedence. グループボックスの場合、ボックス内のスペースを確保するコントロールの数を設定します。For DropDownLists, ComboBoxes, and ListBoxes, it is the number of items visible at one time inside the list portion of the control (but it is often desirable to omit both the R and H options for DropDownList and ComboBox, as the popup list will automatically take advantage of the available height of the user's desktop). For other control types, R is the number of rows of text that can visibly fit inside the control.

Wn: Width (where n is any number in pixels). If omitted, the width is calculated automatically for some control types based on their contents; tab controls default to 30 times the current font size, plus 3 times the X-margin; vertical Progress Bars default to two times the current font size; and horizontal Progress Bars, horizontal Sliders, DropDownLists, ComboBoxes, ListBoxes, GroupBoxes, Edits, and Hotkeys default to 15 times the current font size (except GroupBoxes, which multiply by 18 to provide room inside for margins).

Hn:Height (where n is any number in pixels). If both the H and R options are absent, DropDownLists, ComboBoxes, ListBoxes, and empty multi-line Edit controls default to 3 rows; GroupBoxes default to 2 rows; vertical Sliders and Progress Bars default to 5 rows; horizontal Sliders default to 30 pixels (except if a thickness has been specified); horizontal Progress Bars default to 2 times the current font size; Hotkey controls default to 1 row; and Tab controls default to 10 rows. その他のコントロールタイプについては、その内容に基づいて高さが自動的に計算されます。Note that for DropDownLists and ComboBoxes, H is the combined height of the control's always-visible portion and its list portion (but even if the height is set too low, at least one item will always be visible in the list). Also, for all types of controls, specifying the number of rows via the R option is usually preferable to using H because it prevents a control from showing partial/incomplete rows of text.

WP±n, HP±n (where n is any number in pixels) can be used to set the width and/or height of a control equal to the previously added control's width or height, with an optional plus or minus adjustment. 例えば、wpはコントロールの幅を前のコントロールの幅に設定し、wp-50は前のコントロールの幅より50小さい幅に設定します。

Xn, Yn: X-position, Y-position (where n is any number in pixels). For example, specifying x0 y0 would position the control in the upper left corner of the window's client area, which is the area beneath the title bar and menu bar (if any).

X+n, Y+n (where n is any number in pixels):オプションのプラス記号は、先に追加されたコントロールの右端または下端(それぞれ)に対して相対的にコントロールを配置するために含めることができます。For example, specifying y+10 would position the control 10 pixels beneath the bottom of the previous control rather than using the standard padding distance. Similarly, specifying x+10 would position the control 10 pixels to the right of the previous control's right edge. Since negative numbers such as x-10 are reserved for absolute positioning, to use a negative offset, include a plus sign in front of it. 事例:x+-10.

For X+ and Y+, the letter M can be used as a substitute for the window's current margin. For example, x+m uses the right edge of the previous control plus the standard padding distance. xp y+m positions a control below the previous control, whereas specifying a relative X coordinate on its own (with XP or X+) would normally imply yp by default.

XP±n, YP±n (where n is any number in pixels) can be used to position controls relative to the previous control's upper left corner, which is often useful for enclosing controls in a GroupBox.

XM±n and YM±n (where n is any number in pixels) can be used to position a control at the leftmost and topmost margins of the window, respectively, with an optional plus or minus adjustment.

XS±n and YS±n (where n is any number in pixels):These are similar to XM and YM except that they refer to coordinates that were saved by having previously added a control with the word Section in its options (the first control of the window always starts a new section, even if that word isn't specified in its options). 事例:

MyGui := Gui()
MyGui.Add("Edit", "w600")  ;ウィンドウの上部にかなり広いエディットコントロールを追加します。
MyGui.Add("Text", "Section", "First Name:")  ; Save this control's position and start a new section.
MyGui.Add("Text",, "Last Name:")
MyGui.Add("Edit","ys")  ; このセクション内で新しいカラムを開始します。
MyGui.Add("Edit")
MyGui.Show

XS and YS may optionally be followed by a plus/minus sign and a number. Also, it is possible to specify both the word Section and XS/YS in a control's options; this uses the previous section for itself but establishes a new section for subsequent controls.

Omitting either X, Y or both is useful to make a GUI layout automatically adjust to any future changes you might make to the size of controls or font. 一方、すべてのコントロールに絶対位置を指定すると、拡大・縮小するコントロールの下や右側にあるすべてのコントロールの位置を手動で移動させる必要がある場合があります。

If both X and Y are omitted, the control will be positioned beneath the previous control using a standard padding distance (the current margin). 連続するテキストコントロールやリンクコントロールには垂直方向のパディングが追加され、編集、DDL、または同様のサイズのコントロールの列がその右に追加された場合に、通常より整列するようになります。To use only the standard vertical margin, specify y+m or any value for X.

片方のコンポーネントだけが省略された場合、そのデフォルト値は、もう片方のコンポーネントを指定するためにどのオプションが使用されたかに依存します:

指定されたXYのデフォルト
Xn or XM以前のすべてのコントロールの下(最大Y範囲+マージン)。
XSセクションオプションの直近の使用以降、以前のすべてのコントロールの下にある。
X+n or XP+nonzeroSame as the previous control's top edge (YP).
XP or XP+0前のコントロールの下(下端+マージン)。
指定されたYXのデフォルト
Yn or YM以前のすべてのコントロールの右側(最大X範囲+マージン)。
YSセクションオプションの直近の使用以降、以前のすべてのコントロールの右側にある。
Y+n or YP+nonzeroSame as the previous control's left edge (XP).
YP or YP+0前のコントロールの右側(右端+マージン)。

ユーザー入力の保存と対応

V: Sets the control's Name. 名前に含まれない文字「V」の直後を指定します。例えば、vMyEditを指定すると、コントロールに「MyEdit」という名前が付けられます。

Events: Event handlers (such as a function which is called automatically when the user clicks or changes a control) cannot be set within the control's Options. 代わりに、OnEventを使用して、関心のあるイベントごとにコールバック関数またはメソッドを登録することができます。

Common Options and Styles for Controls

注:先行する記号がない場合、プラス記号とみなされます。例えば、Wrap+Wrapと同じです。これに対して、-Wrapは、単語の折り返し特性を削除します。

AltSubmit: Uses alternate submit method. DropDownList、ComboBox、ListBox、Tabの場合、Gui.Submitに選択項目のテキストではなく、その位置が保存されるようになるためです。項目が選択されていない場合でも、コンボボックスはその編集フィールドのテキストを保存します。

C: Color of text (has no effect on buttons and status bars). Specify the letter C followed immediately by a color name (see color chart) or RGB value (the 0x prefix is optional). 例:cRed, cFF2211, c0xFF2211, cDefault.

Disabled: Makes an input-capable control appear in a disabled state, which prevents the user from focusing or modifying its contents. 後から有効にする場合は、GuiCtrl.Enabledを使用します。注:Editコントロールを読み取り専用にするには、代わりに文字列ReadOnlyを指定します。また、Disabledの直後に0または1を付加して、開始状態(0が有効、1が無効)を示すことも任意に可能です。つまり、Disabled"Disabled" VarContainingOneは同じです。

Hidden: The control is initially invisible. 後で表示する場合はGuiCtrl.Visibleを使用します。Hiddenの直後に0または1を付加して、開始時の状態を示すこともできる(0は可視、1は非表示)。つまり、Hidden「Hidden」VarContainingOneは同じです。

Left: Left-justifies the control's text within its available width. このオプションは、以下のコントロールに影響します:Text, Edit, Button, CheckBox, Radio, UpDown, Slider, Tab, Tab2, GroupBox, DateTime.

Right: Right-justifies the control's text within its available width. チェックボックスやラジオボタンの場合、ボックス自体もコントロールの左側ではなく、右側に配置されます。このオプションは、以下のコントロールに影響します:Text, Edit, Button, CheckBox, Radio, UpDown, Slider, Tab, Tab2, GroupBox, DateTime, Link.

Center: Centers the control's text within its available width. このオプションは、以下のコントロールに影響します:Text, Edit, Button, CheckBox, Radio, Slider, GroupBox.

Section: Starts a new section and saves this control's position for later use with the XS and YS positioning options described above.

Tabstop: Use -Tabstop (minus Tabstop) to have an input-capable control skipped over when the user presses Tab to navigate.

Wrap: Enables word-wrapping of the control's contents within its available width. ほぼすべての制御タイプは、最初にワードラッピングが有効になっているので、ワードラッピングを無効にするには、-Wrapを使用します。

VScroll: Provides a vertical scroll bar if appropriate for this type of control.

HScroll: Provides a horizontal scroll bar if appropriate for this type of control. この段落の続きは、ListBoxのみに適用されます。水平スクロールの幅は、デフォルトでListBoxの幅の3倍になっています。異なるスクロール幅を指定する場合は、HScrollという文字の直後に数字を含めてください。例えば、HScroll500を指定すると、ListBox内で500ピクセルのスクロールが可能になります。However, if the specified scrolling width is smaller than the width of the ListBox, no scroll bar will be shown (though the mere presence of HScroll makes it possible for the horizontal scroll bar to be added later via MyScrollBar.Opt("+HScroll500"), which is otherwise impossible).

Uncommon Options and Styles for Controls

BackgroundTrans: Uses a transparent background, which allows any control that lies behind a Text, Picture, or GroupBox control to show through. 例えば、ピクチャコントロールの上に透明なテキストコントロールを表示すると、テキストがピクチャの一部に見えるようになります。このオプションを後で削除するには、GuiCtrl.Opt("+Background")を使用します。透過画像については、ピクチャーコントロールのAltSubmitの項を参照してください。既知の制限:ListViewを含むTabコントロール内のコントロールで、BackgroundTransが正しく動作しない場合がある。制御型がこのオプションをサポートしていない場合、エラーが発生します。

BackgroundColor:コントロールの背景色を変更します。Colorを色名(カラーチャート参照)またはRGB値(0x接頭辞は任意)に置き換える。例:BackgroundSilver, BackgroundFFDD99. If this option is not used, or if +Background is used with no suffix, a Text, Picture, GroupBox, CheckBox, Radio, Slider, Tab or Link control uses the background color set by Gui.BackColor (or if none or other control type, the system's default background color). Specifying BackgroundDefault or -Background applies the system's default background color. For example, a control can be restored to the system's default color via LV.Opt("+BackgroundDefault"). 制御型がこのオプションをサポートしていない場合、エラーが発生します。

Border: Provides a thin-line border around the control. ほとんどのコントロールは、すでにタイプ固有のボーダーを持っているため、これは必要ありません。既存のコントロールにボーダーを追加する場合、コントロールの幅と高さを1ピクセルずつ大きくする必要がある場合があります。

Redraw: When used with GuiCtrl.Opt, this option enables or disables redraw (visual updates) for a control by sending it a WM_SETREDRAW message. 詳しくは「再描画」をご覧ください。

Theme: This option can be used to override the window's current theme setting for the newly created control. 既存のコントロールに使用しても効果はありませんが、将来のバージョンで変更される可能性があります。詳しくはGUIの+/-Themeオプションをご覧ください。

(Unnamed Style): Specify a plus or minus sign followed immediately by a decimal or hexadecimal style number. 符号を省略した場合は、プラス符号とします。

(Unnamed ExStyle): Specify a plus or minus sign followed immediately by the letter E and a decimal or hexadecimal extended style number. 符号を省略した場合は、プラス符号とします。例えば、E0x200では、WS_EX_CLIENTEDGE スタイルが追加され、画像やその他のコントロールに適した、縁がくぼんだボーダーを提供します。ここに書かれていない他の拡張スタイル(ほとんど使用されないため)については、「拡張ウィンドウスタイル|Microsoft Docs」を参照し、完全なリストを入手してください。

Text
指定された制御タイプに応じて、文字列、数値、配列のいずれかを指定します。

戻り値

型:Object

This method returns a GuiControl object.

Destroy

ウィンドウとそのすべてのコントロールを削除し、対応するメモリとシステムリソースを解放します。

MyGui.Destroy()

MyGui.Destroy()を使用しない場合、Guiオブジェクトが削除されるとウィンドウは自動的に破棄されます(詳細は「一般備考」を参照)。スクリプトが終了すると、すべてのGUIウィンドウは自動的に破棄されます。

Flash

タスクバーのウィンドウのボタンを点滅させます。

MyGui.Flash(Blink)

パラメータ

Blink

型:論理値

省略されたときは、デフォルトで>Trueになります。

If true, the window's button in the taskbar will blink. これは、ウィンドウのタイトルバーやタスクバーボタン(ある場合)の色を反転させることによって行われます。

If false, the original colors of the title bar and taskbar button will be restored (but the actual behavior might vary depending on OS version).

備考

下の例では、ウィンドウが3回点滅していますが、これは1回の点滅が反転して元に戻るからです:

Loop 6
{
    MyGui.Flash
    Sleep 500  ;この値にはかなり敏感で、変更すると予期せぬ形で動作が変化する可能性があります。
}

GetClientPos

ウィンドウのクライアントエリアの位置とサイズを取得します。

MyGui.GetClientPos(&X, &Y, &Width, &Height)

パラメータ

&X, &Y

型:VarRef

省略した場合は、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the X and Y coordinates of the client area's upper left corner.

&Width, &Height

型:VarRef

省略した場合は、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the width and height of the client area.

widthはクライアントエリアの左右の水平距離、heightは上下の垂直距離です(単位:ピクセル)。

備考

クライアント・エリアはウィンドウの一部で、コントロールを含むことができる。ウィンドウのタイトルバー、メニュー(標準のものがある場合)、ボーダーは除外されます。The position and size of the client area are less dependent on OS version and theme than the values returned by Gui.GetPos.

WinGetClientPosとは異なり、このメソッドはWidthHeightDPIスケーリングを適用します(-DPIScaleオプションが使用されていない場合)。

GetPos

ウィンドウの位置と大きさを取得します。

MyGui.GetPos(&X, &Y, &Width, &Height)

パラメータ

&X, &Y

型:VarRef

省略した場合は、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the X and Y coordinates of the window's upper left corner, in screen coordinates.

&Width, &Height

型:VarRef

省略した場合は、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the width and height of the window.

widthはウィンドウの左右の水平距離、heightは上下の垂直距離です(単位:ピクセル)。

備考

As the coordinates returned by this method include the window's title bar, menu and borders, they may be dependent on OS version and theme. To get more consistent values across different systems, consider using Gui.GetClientPos instead.

WinGetPosとは異なり、このメソッドはWidthHeightDPIスケーリングを適用します(-DPIScaleオプションが使用されていない場合)。

Hide

ウィンドウを隠します。

MyGui.Hide()

Maximize

ウィンドウの非表示を解除し(必要な場合)、最大化します。

MyGui.Maximize()

Minimize

ウィンドウの非表示を解除し(必要な場合)、最小化します。

MyGui.Minimize()

Move

Moves and/or resizes the window.

MyGui.Move(X, Y, Width, Height)

パラメータ

X, Y

型:整数

If either is omitted, the position in that dimension will not be changed. Otherwise, specify the X and Y coordinates of the upper left corner of the window's new location, in screen coordinates.

幅、高さ

型:整数

If either is omitted, the size in that dimension will not be changed. Otherwise, specify the new width and height of the window (in pixels).

備考

WinMoveとは異なり、この方法ではWidthHeightDPIスケーリングを適用します(-DPIScaleオプションが使用されていない場合)。

MyGui.Move(10, 20, 200, 100)
MyGui.Move(VarX+10, VarY+5, VarW*2, VarH*1.5)

; 左右を10ピクセルずつ拡大します。
MyGui.GetPos(&x,, &w)
MyGui.Move(x-10,, w+20)

OnEvent

与えられたイベントが発生したときに呼び出される関数またはメソッドを登録します。

MyGui.OnEvent(EventName, Callback , AddRemove)

詳しくはOnEventを参照してください。

Opt

ウィンドウの外観や動作に関するさまざまなオプションやスタイルを設定します。

MyGui.Opt(Options)

パラメータ

Options

型:文字列

Zero or more of the following options and styles, each separated from the next with one or more spaces or tabs.

パフォーマンス上の理由から、すべてのオプションを1行で設定し、ウィンドウを作成する前に(つまり、Gui.Addなどの他のメソッドを使用する前に)設定することをお勧めします。

このパラメータの効果は累積的です。つまり、明示的に指定された設定のみを変更し、他の設定はすべて変更されないままです。

オプションを追加する場合はプラス記号を、削除する場合はマイナス記号を指定します。事例:MyGui.Opt("+Resize -MaximizeBox").

AlwaysOnTop: Makes the window stay on top of all other windows, which is the same effect as WinSetAlwaysOnTop.

Border: Provides a thin-line border around the window. これは一般的ではありません。

Caption(デフォルトで存在します):タイトルバーと太いウィンドウのボーダー/エッジを提供します。WinSetTransColorを使用するウィンドウからキャプションを削除する場合、TransColorを設定した後に削除してください。

Disabled: Disables the window, which prevents the user from interacting with its controls. 他のウィンドウを所有するウィンドウでよく使われます(「所有者」参照)。

DPIScale: Use MyGui.Opt("-DPIScale") to disable DPI scaling, which is enabled by default. DPIスケーリングが有効な場合、GuiおよびGuiControlのメソッド/プロパティに渡されたり、そこから取得された座標やサイズは、画面のDPIに基づいて自動的にスケーリングされます。For example, with a DPI of 144 (150 %), MyGui.Show("w100") would make the Gui 150 (100 * 1.5) pixels wide, and resizing the window to 200 pixels wide via the mouse or WinMove would cause MyGui.GetClientPos(,,&W) to set W to 133 (200 // 1.5). A_ScreenDPIは、システムの現在の DPI を含んでいます。

DPIスケーリングはGuiとGuiControlのメソッド/プロパティにのみ適用されるので、ControlGetPosやWinGetPosのような他のソースから直接得られる座標は動作しません。対処法はいくつもあります:

  • 可能な限り、ハードコードされた座標の使用を避けます。For example, use the XP, XS, XM and X+M options for positioning controls and specify height in rows of text instead of pixels.
  • 必要に応じて、スケーリングをその場で有効化(MyGui.Opt("+DPIScale"))、無効化(MyGui.Opt("-DPIScale"))することができます。設定を変更しても、すでに設定されている位置やサイズには影響しません。
  • 座標を手動でスケーリングします。例えば、x*(A_ScreenDPI/96)はxを論理/GUI座標から物理/非GUI座標に変換します。

LastFound: Sets the window to be the last found window (though this is unnecessary in a GUI thread because it is done automatically), which allows functions such as WinGetStyle and WinSetTransparent to operate on it even if it is hidden (that is, DetectHiddenWindows is not necessary). これは、ウィンドウを表示する前にウィンドウのプロパティを変更する場合に特に有効です。事例:

MyGui.Opt("+LastFound")
WinSetTransColor(CustomColor " 150", MyGui)
MyGui.Show()

MaximizeBox: Enables the maximize button in the title bar. これは、下記のResizeの一部としても含まれています。

MinimizeBox(デフォルトで存在):タイトルバーの最小化ボタンを有効にします。

MinSize および MaxSize:ユーザーがウィンドウの端をドラッグしてサイズを変更するときなど、ウィンドウの最小および最大サイズを決定します。Specify +MinSize and/or +MaxSize (i.e. without suffix) to use the window's current size as the limit (if the window has no current size, it will use the size from the first use of Gui.Show). または、幅の後にXを付け、その後に高さを付けます:MyGui.Opt("+Resize +MinSize640x480"). 寸法はピクセル単位で、ウィンドウのクライアント領域(ボーダー、タイトルバー、メニューバーを除く)の大きさを指定します。各数値を16進数ではなく、10進数で指定します。

幅または高さのどちらかを省略して変更しないことも可能です(例:+MinSize640x+MinSizex480)。さらに、Min/MaxSizeを複数回指定することで、一方の次元にウィンドウの現在のサイズを、他方の次元に明示的なサイズを使用することができます。例えば、+MinSize +MinSize640xは、高さにウィンドウの現在のサイズ、幅に640を使用します。

If MinSize and MaxSize are never used, the operating system's defaults are used (similarly, MyGui.Opt("-MinSize -MaxSize") can be used to return to the defaults). 注:the window must have +Resize to allow resizing by the user.

OwnDialogs: MyGui.Opt("+OwnDialogs") should be specified in each thread (such as a event handling function of a Button control) for which subsequently displayed MsgBox, InputBox, FileSelect, and DirSelect dialogs should be owned by the window. このようなダイアログはモーダルであり、ユーザーはダイアログを閉じるまでGUIウィンドウと対話することができません。By contrast, ToolTip windows do not become modal even though they become owned; they will merely stay always on top of their owner. いずれの場合も、所有するダイアログやウィンドウは、そのGUIウィンドウが破棄されると自動的に破棄されます。

他のスレッドに影響を与えないため、通常、この設定をオフに戻す必要はありません。ただし、スレッドが所有と未所有の両方のダイアログを表示する必要がある場合は、MyGui.Opt("-OwnDialogs")によってこの設定をオフにすることができます。

Owner: Use +Owner to make the window owned by another. 所有するウィンドウは、デフォルトではタスクバーボタンがなく、表示されているときは常に所有者の上に表示されます。また、所有者が破壊されると自動的に破壊されます。+Owner can be used before or after the owned window is created. There are two ways to use +Owner, as shown below:

MyGui.Opt("+Owner" OtherGui.Hwnd)  ;GUIをOtherGuiの所有にする。
MyGui.Opt("+Owner")  ; Make the GUI owned by the script's main window to prevent display of a taskbar button.

+Ownerは、任意のトップレベルウィンドウのHWNDにすぐに続くことができます。

オーナーウィンドウが表示されているときに、ユーザーがオーナーと対話できないようにするには、MyGui.Opt("+Disabled")でオーナーを無効化します。後で(所有するウィンドウをキャンセルしたり破棄するとき)、MyGui.Opt("-Disabled")で所有者を再有効化します。オーナーが自動的に再活性化されるように、キャンセル/破棄の前にこの操作を行います。

Parent: Use +Parent immediately followed by the HWND of any window or control to use it as the parent of this window. GUIをトップレベルのウィンドウに戻すには、-Parentを使用します。このオプションは、ウィンドウを作成した後でも機能します。既知の制限事項:

  • UIアクセスで実行すると、新しい親が常にトップで子ウィンドウがそうでない場合、+Parentオプションが既存のウィンドウで機能しない。
  • The +Parent option may fail during GUI creation if the parent window is external, but may work after the GUI is created. This is due to differences in how styles are applied.

Resize: Makes the window resizable and enables its maximize button in the title bar. 最大化ボタンを有効にしない場合は、+Resize -MaximizeBoxを指定します。

SysMenu(デフォルトで存在):ウィンドウ左上のシステムメニューとアイコンを省略する場合は、-SysMenu(マイナスSysMenu)を指定します。これにより、タイトルバーの最小化、最大化、および閉じるボタンも省略されます。

Theme: By specifying -Theme, all subsequently created controls in the window will have the Classic Theme appearance. 現在のテーマに従った制御を後から追加で作成する場合は、+Themeでオンに戻してください。注:このオプションは、「クラシックテーマ」が有効な場合は効果がありません。この設定は、コントロールの作成時にオプションで+Themeまたは-Themeを指定することで、個々のコントロールに対して変更することができます。

ToolWindow: Provides a narrower title bar but the window will have no taskbar button. WS_MAXIMIZEBOXWS_MINIMIZEBOXのスタイルが存在するかどうかに関わらず、常に最大化、最小化ボタンを非表示にします。

(Unnamed Style): Specify a plus or minus sign followed immediately by a decimal or hexadecimal style number.

(Unnamed ExStyle): Specify a plus or minus sign followed immediately by the letter E and a decimal or hexadecimal extended style number. 例えば、+E0x40000は、WS_EX_APPWINDOWスタイルを追加し、タスクバーボタンがないウィンドウに、タスクバーボタンを提供します。ここに書かれていない他の拡張スタイル(ほとんど使用されないため)については、「拡張ウィンドウスタイル|Microsoft Docs」を参照し、完全なリストを入手してください。

Restore

Unhides the window (if necessary) and unminimizes or unmaximizes it.

MyGui.Restore()

SetFont

これ以降にウィンドウに追加されるコントロールのフォントの書体、サイズ、スタイル、カラーを設定します。

MyGui.SetFont(Options, FontName)

パラメータ

Options

型:文字列

選択肢は0個以上。各オプションは、1文字に続けて値を指定するか、1つの単語を指定します。複数のオプションを指定する場合は、各オプションの間にスペースを入れてください。事例:cBlue s12 bold.

以下の単語に対応しています:bold, italic, strike, underline, および norm. Normは、フォントを通常のウェイト/太さに戻し、イタリック、ストライク、アンダーラインをオフにします(ただし、既存の色とサイズは保持されます)。ノームを使ってすべての属性をオフにし、他の属性を選択的にオンにすることが可能です。例えば、norm italicを指定すると、フォントはノーマルに設定された後、イタリックに設定されます。

C: Color name (see color chart) or RGB value -- or specify the word Default to return to the system's default color (black on most systems). 例値:cRed, cFFFFAA, cDefault. 注:Buttons and status bars do not obey custom colors. また、Cオプションを含めることで、現在のフォントカラー以外のフォントカラーを持つ個別コントロールを作成することができます。事例:MyGui.Add("Text", "cRed", "My Text").

S: Size (in points). 事例:s12(16進数ではなく、10進数を指定します。)

W: Weight (boldness), which is a number between 1 and 1000 (400 is normal and 700 is bold). 事例:w600(16進数ではなく10進数で指定してください。)

Q: Text rendering quality. 事例:q3. Qの後には、次の表から番号を選んでください:

Number ウィンドウズ定数 説明
0 DEFAULT_QUALITY フォントの外観は問いません。
1 DRAFT_QUALITY フォントの外観は、PROOF_QUALITY 値を使用する場合よりも重要ではありません。
2 PROOF_QUALITY フォントの文字品質は、論理フォント属性の完全一致よりも重要です。
3 NONANTIALIASED_QUALITY フォントのアンチエイリアスは行われません。つまり、フォントスムージングは行われません。
4 ANTIALIASED_QUALITY フォントがアンチエイリアスをサポートしており、フォントのサイズが小さすぎたり大きすぎたりしない場合は、アンチエイリアス、またはスムージングが行われます。
5 CLEARTYPE_QUALITY 設定されている場合、テキストは(可能な限り)ClearTypeアンチエイリアシング方式でレンダリングされます。

これらの値の意味の詳細については、Microsoft Docs を参照してください:CreateFont.

通常、最高画質がデフォルトであるため、この機能は、アンチエイリアスを無効にすることで、テキストがより鮮明になる特定のケースで使用されることが一般的です。

FontName

型:文字列

FontNameには、フォントテーブルのような任意のフォントの名前を指定することができる。FontNameが省略された場合、またはシステム上に存在しない場合は、以前のフォントの書体が使用されます(存在しない場合は、システムのデフォルトのGUI書体が使用されます)。この動作は、GUIウィンドウが複数のシステムで同じようなフォントを持つようにするのに便利で、それらのシステムの一部が優先フォントを持たない場合であっても、この動作は有効です。For example, by using the following methods in order, Verdana will be given preference over Arial, which in turn is given preference over MS Sans Serif:

MyGui.SetFont(, "MS Sans Serif")
MyGui.SetFont(, "Arial")
MyGui.SetFont(, "Verdana")  ; Preferred font.

備考

両方のパラメーターを省略すると、フォントをシステムのデフォルトのGUI書体、サイズ、色に戻すことができます。それ以外の場合、指定されていないフォント属性は、前のフォントからコピーされます。

また、オペレーティングシステムには、フォント、色、アイコンを選択するダイアログボックスが標準装備されています。These dialogs can be displayed via DllCall in combination with comdlg32\ChooseFont, comdlg32\ChooseColor, or shell32\PickIconDlg. Search the forums for examples.

Show

デフォルトでは、ウィンドウを可視化し、(必要に応じて)最小化を解除し、アクティブ化します。

MyGui.Show(Options)

パラメータ

Options

型:文字列

以下のX、Y、W、Hのオプションを省略すると、ウィンドウは以前のサイズと位置を維持します。前の位置がない場合、後述のXおよびYオプションがなければ、ウィンドウは1次元または両次元で自動中心化されます。以前のサイズがない場合、ウィンドウは、それが含むコントロールのサイズと位置に応じて自動サイズになります。

オプションには、以下の文字列を0個以上指定することができます(各数値は16進数ではなく10進数で指定してください):

Wn: Specify for n the width (in pixels) of the window's client area (the client area excludes the window's borders, title bar, and menu bar).

Hn: Specify for n the height of the window's client area, in pixels.

Xn:Specify for n the window's X-position on the screen, in pixels. ポジション0は、画面上で見えるピクセルの一番左の列です。

Yn:Specify for n the window's Y-position on the screen, in pixels. ポジション0は、画面上で見える一番上の画素列です。

Center: Centers the window horizontally and vertically on the screen.

xCenter: Centers the window horizontally on the screen. 事例:MyGui.Show("xCenter y0").

yCenter: Centers the window vertically on the screen.

AutoSize: Resizes the window to accommodate only its currently visible controls. これは、新しいコントロールが追加されたり、既存のコントロールがサイズ変更されたり、隠されたり、隠されなかったりした後に、ウィンドウのサイズを変更するのに便利です。事例:MyGui.Show("AutoSize Center").

また、以下のいずれかが存在する場合があります:

Minimize: Minimizes the window and activates the one beneath it.

Maximize: Maximizes and activates the window.

Restore: Unminimizes or unmaximizes the window, if necessary. また、必要に応じてウィンドウを表示し、起動します。

NoActivate: Unminimizes or unmaximizes the window, if necessary. また、ウィンドウをアクティブにしなくても表示されます。

NA: Shows the window without activating it. ウィンドウが最小化された場合、その状態を維持しますが、おそらくzオーダー(alt-tabセレクタで見られる順序)でより高く上昇します。ウィンドウが以前は隠れていた場合、アクティブなウィンドウが非アクティブになっていないにもかかわらず、ウィンドウがアクティブなウィンドウの上に表示されてしまうことが考えられます。

Hide: Hides the window and activates the one beneath it. この機能はGui.Hideと同じですが、非表示のウィンドウを表示せずに移動したりサイズを変更したりすることができます。事例:MyGui.Show("Hide x55 y66 w300 h200").

Submit

名前付きコントロールから値を収集し、オブジェクトに合成します。オプションでウィンドウを非表示にすることができます。

NamedCtrlValues := MyGui.Submit(Hide)

パラメータ

Hide

型:論理値

省略されたときは、デフォルトで>Trueになります。

If true, the window will be hidden.

If false, the window will not be hidden.

戻り値

型:Object

This method returns an object that contains one own property per named control, like NamedCtrlValues.%GuiCtrl.Name% := GuiCtrl.Value, with the exceptions noted below. GuiCtrl.Valueをサポートし、名前が付与された入力可能なコントロールのみが含まれます。Use NamedCtrlValues.NameOfControl to retrieve an individual value or OwnProps to enumerate them all.

For DropDownList, ComboBox, ListBox and Tab, the text of the selected item/tab is stored instead of its position number if the control lacks the AltSubmit option, or if the ComboBox's text does not match a list item. それ以外の場合は、Value(アイテムの位置番号)が格納されます。

ラジオグループのラジオボタンに1つだけ名前がある場合、SubmitはコントロールのValueではなく、現在選択されているボタンの番号を保存します。1は1番目のラジオボタン(オリジナル作成順)、2は2番目のラジオボタン、といった具合に。選択されているボタンがない場合は、0が格納されます。

入力可能でないため除外:Text, Pic, GroupBox, Button, Progress, Link, StatusBar.

同様に除外:ListView, TreeView, ActiveX, Custom.

__Enum

Enumerates the window's controls.

MyGuiのCtrlの場合
MyGuiのHwnd、Ctrlの場合

新しい列挙者を返します。このメソッドは通常、直接呼び出されることはありません。その代わりに、Guiオブジェクトは直接for-loopに渡され、for-loopは__Enumを一度呼び出し、ループの各繰り返しで列挙器を一度呼び出します。列挙者を呼び出すたびに、次のコントロールが返されます。forループの変数は、列挙者のパラメータに対応しており、次のようになっています。

Hwnd

型:整数

コントロールのHWNDです。2パラメータモード時のみ存在します。

Ctrl

型:Object

The control's GuiControl object.

事例:

MyGuiのHwnd、GuiCtrlObjの場合
    MsgBox "Control #" A_Index " is " GuiCtrlObj.ClassNN

__New

新しいGuiインスタンスを構築します。

MyGui.__New(Options, Title, EventObj)

Guiのサブクラスは、__Newをオーバーライドして、独自のイベントを処理するためにsuper.__New(Options, Title, this)をコールすることができます。このような場合、メインウィンドウのイベント(閉じるなど)は、これはすでにGuiへの参照を含んでいるため、明示的なGuiパラメータを渡すことはありません。

The Gui retains a reference to EventObj for the purpose of calling event handlers, and releases it when the window is destroyed. If EventObj itself contains a reference to the Gui, this would typically create a circular reference which prevents the Gui from being automatically destroyed. However, an exception is made for when EventObj is the Gui itself, to avoid a circular reference in that case.

ウィンドウが既に構築または破棄されている場合は、例外が発生します。

属性

BackColor

ウィンドウの背景色を取得または設定します。

CurrentColor := MyGui.BackColor
MyGui.BackColor := NewColor

CurrentColor is a 6-digit RGB value of the current color previously set by this property, or an empty string if the default color is being used.

NewColorは、16の主要なHTMLカラー名、16進数のRGBカラー値(接頭辞0xはオプション)、純粋な数値のRGBカラー値、またはデフォルトカラーを表すDefault(または空の文字列)のいずれかです。例値:"Silver", "FFFFAA", 0xFFFFAA, "Default", "".

デフォルトでは、ウィンドウの背景色は、ボタンの表面のシステムの色になります。

この例のように、メニューバーと、そのサブメニューの色を変更することができます:MyMenuBar.SetColor "White".

背景を透明にする場合は、WinSetTransColorを使用します。ただし、Gui.BackColorでカスタムウィンドウを割り当てずにこの操作を行うと、ボタンも透明になります。これを防ぐには、まずカスタムカラーを割り当て、そのカラーを透明にします。事例:

MyGui.BackColor := "EEAA99"
WinSetTransColor("EEAA99", MyGui)

背景が透明なウィンドウから、ボーダーとタイトルバーを追加で削除するには、次のようにします:MyGui.Opt("-Caption")

上記を説明するために、本ページの下部付近にOSD(オンスクリーンディスプレイ)の例を掲載しています。

FocusedCtrl

Retrieves the GuiControl object of the window's focused control.

GuiCtrlObj := MyGui.FocusedCtrl

注:効果的に使用するためには、一般的にウィンドウを最小化または非表示にする必要はありません。

Hwnd

Retrieves the window handle (HWND) of the window.

CurrentHwnd := MyGui.Hwnd

GUIのHWNDは、PostMessageSendMessageDllCallで、よく使われます。また、WinTitleパラメータで直接使用することも可能です。

MarginX

側面とその後に作成されるコントロールの間の水平マージンのサイズを取得または設定します。

CurrentValue := MyGui.MarginX
MyGui.MarginX := NewValue

CurrentValue is the number of pixels of the current horizontal margin.

NewValueは、X座標が明示されていないコントロールを自動配置する際に、ウィンドウの左右に残すスペースのピクセル数です。また、マージンは、自動配置されたコントロール同士を隔てる水平方向の距離を決定するために使用されます。最後に、マージンはGui.Showの最初の使用でウィンドウのサイズを計算する際に考慮されます(サイズが明示的に指定されていない場合)。

デフォルトでは、このマージンは現在選択されているフォントのサイズに比例します(左と右はfont-heightの1.25倍)。

MarginY

側面とその後に作成されるコントロールの間の垂直マージンのサイズを取得または設定します。

CurrentValue := MyGui.MarginY
MyGui.MarginY := NewValue

CurrentValue is the number of pixels of the current vertical margin.

NewValueは、Y座標が明示されていないコントロールを自動配置する際に、ウィンドウの上側と下側に残すスペースのピクセル数です。また、マージンは、自動配置されたコントロール同士を分離する垂直距離を決定するために使用されます。最後に、マージンはGui.Showの最初の使用でウィンドウのサイズを計算する際に考慮されます(サイズが明示的に指定されていない場合)。

デフォルトでは、このマージンは現在選択されているフォントのサイズに比例します(上部と下部はフォントハイトの0.75倍)。

名前

Retrieves or sets a custom name for the window.

CurrentName := MyGui.Name
MyGui.Name := NewName

タイトル

Retrieves or sets the window's title.

CurrentTitle := MyGui.Title
MyGui.Title := NewTitle

__Item

指定された名前、テキスト、ClassNN、HWND に関連するGuiControl オブジェクトを取得します。

GuiCtrlObj := MyGui[Name]
GuiCtrlObj := MyGui.__Item[Name]

GUIウィンドウはTabで移動することができ、キーボードフォーカスは次の入力可能なコントロールに移動します(Tabstopスタイルが削除されたコントロールはスキップされます)。ナビゲーションの順序は、コントロールが最初に追加された順序によって決定されます。ただし、そのコントロールがボタンであり、かつデフォルトのボタンがある場合は、後者が代わりにフォーカスされます。

一部のコントロールには、キーボードショートカットを作成するためのアンパサンド(&)が含まれている場合があり、コントロールのテキストに下線文字として表示される場合があります(システム設定に依存)。Altを押しながら文字を入力することで、ショートカットを有効にすることができます。ボタン、チェックボックス、ラジオボタンの場合、ショートカットを押すことはコントロールをクリックすることと同じです。グループボックスとテキストコントロールの場合、ショートカットを押すと、その後に作成された最初の入力可能なタブストップコントロールにキーボードフォーカスが移動するようにします。ただし、複数のコントロールが同じショートカットキーを持つ場合、ショートカットキーを押すと、同じショートカットキーを持つすべてのコントロールの間でキーボードフォーカスが交互に変わります。

上記のコントロールタイプの中にリテラルなアンパサンドを表示するには、この例のように2つの連続したアンパサンドを指定します:MyGui.Add("Button",, "Save && Exit").

ウィンドウの外観

For its icon, a GUI window uses the tray icon that was in effect at the time the window was created. したがって、別のアイコンを持つには、ウィンドウを作成する前にトレイアイコンを変更します。事例:TraySetIcon("MyIcon.ico"). また、ウィンドウの大アイコンを小アイコンと異なるものにすることも可能です(大アイコンはalt-tabタスクスイッチャーに表示されます)。This can be done via LoadPicture and SendMessage; for example:

iconsize := 32  ; alt-tabの理想的なサイズは、システムやOSのバージョンによって異なる。
hIcon := LoadPicture("My Icon.ico", "Icon1 w" iconsize " h" iconsize, &imgtype)
MyGui := Gui()
SendMessage(0x0080, 1, hIcon, MyGui)  ; 0x0080はWM_SETICONで、1はICON_BIG(ICON_SMALLは0)を意味します。
MyGui.Show()

OSの制限により、デフォルト以外の文字色が指定されたチェックボックス、ラジオボタン、グループボックスは、クラシックテーマの外観となります。

関連トピックウィンドウのマージン

総論

GUIウィンドウの各コントロールを操作するには、GuiControlオブジェクトを使用します。

1つのGUIウィンドウには、最大11,000個のコントロールが可能です。ただし、コントロールの種類によってはシステムが不安定になる可能性があるため、5000個以上のコントロールを作成する場合は注意してください。

GUIウィンドウは、Guiオブジェクトが削除されたとき(参照カウントがゼロになったとき)に、自動的に破棄されます。ただし、ウィンドウが表示されている間は、Showが自動的に参照カウントを増加させるため、通常は発生しません。ウィンドウが表示されている間、ユーザーはウィンドウと対話し、スクリプトによって処理されるイベントを発生させることができます。ユーザーがウィンドウを閉じたり、HideShowSubmitでウィンドウが隠されたりすると、この余分な参照は解放されます。

Showを呼び出したり、Guiオブジェクトへの参照を保持することなくGUIウィンドウを「生かす」ために、スクリプトはObjAddRefでオブジェクトの参照カウントを増やすことができます(この場合、ウィンドウが不要になったときにObjReleaseが呼び出される必要があります)。例えば、非表示のGUIウィンドウを使用してメッセージを受信する場合や、WinShowなどの「外部」手段でウィンドウを表示する場合(このスクリプトや他のスクリプトによる)などに行われることがあります。

他の理由でスクリプトが持続しない場合、最後に表示されたGUIが閉じられた後に終了します。最後のスレッドが完了したとき、またはスレッドが実行されていない場合は直ちに終了します。

GuiControl object, GuiFromHwnd, GuiCtrlFromHwnd, Control Types, ListView, TreeView, Menu object, Control functions, MsgBox, FileSelect, DirSelect

ポップアップウィンドウを作成します。

MyGui := Gui(, "Title of Window")
MyGui.Opt("+AlwaysOnTop +Disabled -SysMenu +Owner")  ; +Ownerはタスクバーボタンを回避することができる。
MyGui.Add("Text",, "Some text to display.")
MyGui.Show("NoActivate")  ; NoActivateは、現在アクティブなウィンドウを非アクティブにすることを回避します。

姓と名を入力するシンプルな入力ボックスを作成します。

MyGui := Gui(, "Simple Input Example")
MyGui.Add("Text",, "First name:")
MyGui.Add("Text",, "Last name:")
MyGui.Add("Edit", "vFirstName ym")  ; ymオプションは、コントロールの新しい列を開始します。
MyGui.Add("Edit", "vLastName")
MyGui.Add("Button", "default", "OK").OnEvent("Click", ProcessUserInput)
MyGui.OnEvent("Close", ProcessUserInput)
MyGui.Show()

ProcessUserInput(*)
{
    Saved := MyGui.Submit()  ; 名前付きコントロールの内容を、オブジェクトに保存します。
    MsgBox("You entered '" Saved.FirstName " " Saved.LastName "'.")
}

複数のタブを持つタブコントロールを作成し、それぞれのタブには異なるコントロールが配置され、対話することができます。

MyGui := Gui()
Tab := MyGui.Add("Tab3",, ["First Tab","Second Tab","Third Tab"])
MyGui.Add("CheckBox", "vMyCheckBox", "Sample checkbox")
Tab.UseTab(2)
MyGui.Add("Radio", "vMyRadio", "Sample radio1")
MyGui.Add("Radio",, "Sample radio2")
Tab.UseTab(3)
MyGui.Add("Edit", "vMyEdit r5")  ; r5は5列の高さを意味します。
Tab.UseTab()  ; つまり、その後に追加されたコントロールは、タブコントロールに属さない。
Btn := MyGui.Add("Button", "default xm", "OK")  ; xmは左下に配置します。
Btn.OnEvent("Click", ProcessUserInput)
MyGui.OnEvent("Close", ProcessUserInput)
MyGui.OnEvent("Escape", ProcessUserInput)
MyGui.Show()

ProcessUserInput(*)
{
    Saved := MyGui.Submit()  ; 名前付きコントロールの内容を、オブジェクトに保存します。
    MsgBox("You entered:`n" Saved.MyCheckBox "`n" Saved.MyRadio "`n" Saved.MyEdit)
}

ディレクトリ内のファイルを含む ListBox コントロールを作成します。

MyGui := Gui()
MyGui.Add("Text",, "Pick a file to launch from the list below.")
LB := MyGui.Add("ListBox", "w640 r10")
LB.OnEvent("DoubleClick", LaunchFile)
Loop Files, "C:\*.*"  ; このフォルダとワイルドカードのパターンをお好みで変更してください。
    LB.Add([A_LoopFilePath])
MyGui.Add("Button", "Default", "OK").OnEvent("Click", LaunchFile)
MyGui.Show()

LaunchFile(*)
{
    if MsgBox("Would you like to launch the file or document below?`n`n" LB.Text,, 4) = "No"
        return
    ; それ以外の場合は、起動してみてください:
    try Run(LB.Text)
    if A_LastError
        MsgBox("Could not launch the specified file. Perhaps it is not associated with anything.")
}

ユーザーが特定のコントロールの上にマウスを移動すると、(ToolTipを介して)コンテキストセンシティブヘルプを表示させます。

MyGui := Gui()
MyEdit := MyGui.Add("Edit")
; カスタムプロパティにツールチップテキストを格納する:
MyEdit.ToolTip := "This is a tooltip for the control whose name is MyEdit."
MyDDL := MyGui.Add("DropDownList",, ["Red","Green","Blue"])
MyDDL.ToolTip := "Choose a color from the drop-down list."
MyGui.Add("CheckBox",, "This control has no tooltip.")
MyGui.Show()
OnMessage(0x0200, On_WM_MOUSEMOVE)

On_WM_MOUSEMOVE(wParam, lParam, msg, Hwnd)
{
    static PrevHwnd := 0
    if (Hwnd != PrevHwnd)
    {
        Text := "", ToolTip() ; Turn off any previous tooltip.
        CurrControl := GuiCtrlFromHwnd(Hwnd)
        if CurrControl
        {
            if !CurrControl.HasProp("ToolTip")
                return ; No tooltip for this control.
            Text := CurrControl.ToolTip
            SetTimer () => ToolTip(Text), -1000
            SetTimer () => ToolTip(), -4000 ; Remove the tooltip.
        }
        PrevHwnd := Hwnd
    }
}

透明なウィンドウでオンスクリーンディスプレイ(OSD)を作成します。

MyGui := Gui()
MyGui.Opt("+AlwaysOnTop -Caption +ToolWindow")  ; +ToolWindowは、タスクバーボタンとalt-tabメニュー項目を回避します。
MyGui.BackColor := "EEAA99"  ; Can be any RGB color (it will be made transparent below).
MyGui.SetFont("s32")  ; 大きなフォントサイズ(32ポイント)を設定します。
CoordText := MyGui.Add("Text", "cLime", "XXXXX YYYY")  ; XXとYYは、ウィンドウサイズを自動化する役割を果たします。
; この色のすべてのピクセルを透明にし、テキスト自体を半透明にする(150):
WinSetTransColor(MyGui.BackColor " 150", MyGui)
SetTimer(UpdateOSD, 200)
UpdateOSD()  ; 最初の更新をタイマー待ちではなく、即時更新します。
MyGui.Show("x0 y400 NoActivate")  ; NoActivateは、現在アクティブなウィンドウを非アクティブにすることを回避します。

UpdateOSD(*)
{
    MouseGetPos &MouseX, &MouseY
    CoordText.Value := "X" MouseX ", Y" MouseY
}

背景画像に重なるように動くプログレスバーを作成します。

MyGui := Gui()
MyGui.BackColor := "White"
MyGui.Add("Picture", "x0 y0 h350 w450", A_WinDir "\Web\Wallpaper\Windows\img0.jpg")
MyBtn := MyGui.Add("Button", "Default xp+20 yp+250", "Start the Bar Moving")
MyBtn.OnEvent("Click", MoveBar)
MyProgress := MyGui.Add("Progress", "w416")
MyText := MyGui.Add("Text", "wp")  ; wpは「前の幅を使え」という意味です。
MyGui.Show()

MoveBar(*)
{
    Loop Files, A_WinDir "\*.*", "R"
    {
        if (A_Index > 100)
            break
        MyProgress.Value := A_Index
        MyText.Value := A_LoopFileName
        Sleep 50
    }
    MyText.Value := "Bar finished."
}

シンプルなイメージビューアを作成します。

MyGui := Gui("+Resize")
MyBtn := MyGui.Add("Button", "default", "&Load New Image")
MyBtn.OnEvent("Click", LoadNewImage)
MyRadio := MyGui.Add("Radio", "ym+5 x+10 checked", "Load &actual size")
MyGui.Add("Radio", "ym+5 x+10", "Load to &fit screen")
MyPic := MyGui.Add("Pic", "xm")
MyGui.Show()

LoadNewImage(*)
{
    Image := FileSelect(,, "Select an image:", "Images (*.gif; *.jpg; *.bmp; *.png; *.tif; *.ico; *.cur; *.ani; *.exe; *.dll)")
    if Image = ""
        return
    if (MyRadio.Value)  ; 画像を実際の大きさで表示します。
    {
        Width := 0
        Height := 0
    }
    else ; 2番目のラジオが選択されている:画面に合わせて画像をリサイズします。
    {
        Width := A_ScreenWidth - 28  ; 内側にボーダーや余白のスペースを確保するため、28をマイナスします。
        Height := -1  ; "アスペクト比を保つ "が一番良さそうです。
    }
    MyPic.Value := Format("*w{1} *h{2} {3}", Width, Height, Image)  ; 画像を読み込みます。
    MyGui.Title := Image
    MyGui.Show("xCenter y0 AutoSize")  ; 画像サイズに合わせてウィンドウをリサイズします。
}

メニューバーを持つシンプルなテキストエディタを作成します。

; Create the MyGui window:
MyGui := Gui("+Resize", "Untitled")  ; ウィンドウをリサイズ可能にします。

; メニューバーのサブメニューを作成する:
FileMenu := Menu()
FileMenu.Add("&New", MenuFileNew)
FileMenu.Add("&Open", MenuFileOpen)
FileMenu.Add("&Save", MenuFileSave)
FileMenu.Add("Save &As", MenuFileSaveAs)
FileMenu.Add()  ;区切り線です。
FileMenu.Add("E&xit", MenuFileExit)
HelpMenu := Menu()
HelpMenu.Add("&About", MenuHelpAbout)

; サブメニューをくっつけてメニューバーを作成する:
MyMenuBar := MenuBar()
MyMenuBar.Add("&File", FileMenu)
MyMenuBar.Add("&Help", HelpMenu)

; メニューバーをウィンドウに貼り付ける:
MyGui.MenuBar := MyMenuBar

; メインのEditコントロールを作成します:
MainEdit := MyGui.Add("Edit", "WantTab W600 R20")

; イベントを適用します:
MyGui.OnEvent("DropFiles", Gui_DropFiles)
MyGui.OnEvent("Size", Gui_Size)

MenuFileNew()  ;デフォルトの設定を適用します。
MyGui.Show()  ; ウィンドウを表示します。

MenuFileNew(*)
{
    MainEdit.Value := ""  ; Editコントロールをクリアします。
    FileMenu.Disable("3&")  ;グレイアウトと保存.
    MyGui.Title := "Untitled"
}

MenuFileOpen(*)
{
    MyGui.Opt("+OwnDialogs")  ; メインウィンドウに戻る前に、FileSelectダイアログを強制終了させる。
    SelectedFileName := FileSelect(3,, "Open File", "Text Documents (*.txt)")
    if SelectedFileName = ""  ; ファイルが選択されていない。
        return
    global CurrentFileName := readContent(SelectedFileName)
}

MenuFileSave(*)
{
    saveContent(CurrentFileName)
}

MenuFileSaveAs(*)
{
    MyGui.Opt("+OwnDialogs")  ; メインウィンドウに戻る前に、FileSelectダイアログを強制終了させる。
    SelectedFileName := FileSelect("S16",, "Save File", "Text Documents (*.txt)")
    if SelectedFileName = ""  ; ファイルが選択されていない。
        return
    global CurrentFileName := saveContent(SelectedFileName)
}

MenuFileExit(*)  ; ユーザーはファイルメニューから "Exit"を選択しました。
{
    WinClose()
}

MenuHelpAbout(*)
{
    About := Gui("+owner" MyGui.Hwnd)  ; メインウィンドウを「アバウトボックス」のオーナーにする。
    MyGui.Opt("+Disabled")  ; メインウィンドウを無効にします。
    About.Add("Text",, "Text for about box.")
    About.Add("Button", "Default", "OK").OnEvent("Click", About_Close)
    About.OnEvent("Close", About_Close)
    About.OnEvent("Escape", About_Close)
    About.Show()

About_Close(*)
    {
        MyGui.Opt("-Disabled")  ; メインウィンドウを再度有効にします(次のステップの前に行う必要があります)。
        About.Destroy()  ;アバウトボックスを破棄します。
    }
}

readContent(FileName)
{
    try
        FileContent := FileRead(FileName)  ; ファイルの中身を変数に読み込みます。
    catch
    {
        MsgBox("Could not open '" FileName "'.")
        return
    }
    MainEdit.Value := FileContent  ; コントロールにテキストを入れる。
    FileMenu.Enable("3&")  ; 再度有効化および保存。
    MyGui.Title := FileName  ; タイトルバーにファイル名を表示します。
    return FileName
}

saveContent(FileName)
{
    try
    {
        if FileExist(FileName)
            FileDelete(FileName)
        FileAppend(MainEdit.Value, FileName)  ; 内容をファイルに保存します。
    }
    catch
    {
        MsgBox("The attempt to overwrite '" FileName "' failed.")
        return
    }
    ; 成功したら、タイトルバーにファイル名を表示する(MenuFileSaveAsから呼び出された場合のため):
    MyGui.Title := FileName
    return FileName
}

Gui_DropFiles(thisGui, Ctrl, FileArray, *)  ; ドラッグ&ドロップに対応。
{
    CurrentFileName := readContent(FileArray[1])  ; 最初のファイルだけ読み込む(複数ある場合)。
}

Gui_Size(thisGui, MinMax, Width, Height)
{
    if MinMax = -1  ;ウィンドウは最小化されました。何もする必要はない。
        return
    ; それ以外の場合は、ウィンドウのサイズが変更されたり、最大化されたりしています。それに合わせてEditコントロールのサイズを変更します。
    MainEdit.Move(,, Width-20, Height-20)
}

Demonstrates problems caused by reference cycles.

; Click Open or double-click tray icon to show another GUI.
; Use the menu items, Escape or Close button to see how it responds.
A_TrayMenu.Add("&Open", ShowRefCycleGui)
Persistent

ShowRefCycleGui(*) {
    static n := 0
    g := Gui(, "GUI #" (++n)), g.n := n
    g.MenuBar := mb := MenuBar()   ; g -> mb
    mb.Add("Gui", m := Menu())     ; mb -> m
    m.Add("Hide", (*) => g.Hide()) ; (*) -> g
    m.Add("Destroy", (*) => g.Destroy())
    ; For a GUI event, the callback parameter can be used to avoid a
    ; reference cycle (using the same name prevents accidental capture).
; However, Hide() doesn't break the *other* reference cycles.
    g.OnEvent("Escape", (g, *) => g.Hide())
    ; Capturing the variable can work out in our favour.
    g.OnEvent("Close", (*) => g := unset)
    g.Show("w300 h200")
    ; __Delete is not called due to the reference cycle:
;   g -> mb -> m -> (*) -> g
    ; unless g is unset by triggering the Close event,
    ; or MenuBar and event handlers are released by Destroy.
    g.__Delete := this => MsgBox("GUI #" this.n " deleted")
}