GuiControl Object

class Gui.Control extends Object

GUIコントロールを変更したり、コントロールに関する情報を取得するためのインターフェイスを提供します。Gui.AddGui.__ItemGuiCtrlFromHwndは、このタイプのオブジェクトを返します。

"GuiCtrl"は、Gui.Controlクラスのインスタンスのプレースホルダーとして、以下で使用されます。

Gui.ControlはすべてのGUIコントロールの基本クラスとして機能しますが、コントロールの種類によって独自のクラスが存在します。以下のメソッドの一部は、該当するクラスのプロトタイプ、またはGui.Listの基底クラスで定義されます。全リストは「組込クラス」をご覧ください。

Objectから継承されたメソッドとプロパティに加えて、GuiControlオブジェクトは、以下の定義済みのメソッドとプロパティを持つことができます。

目次

メソッド

Add

Appends items to a multi-item control (ListBox, DropDownList, ComboBox, or Tab).

GuiCtrl.Add(Items)

パラメータ

Items

型:配列

An array of strings to be inserted as items at the end of the control's list, e.g. ["Red", "Green", "Blue"].

備考

To replace (overwrite) the list instead, use the Delete method beforehand. To select an item, use the Choose method.

ListView.Add, TreeView.Add

Choose

Selects an item in a multi-item control (ListBox, DropDownList, ComboBox, or Tab).

GuiCtrl.Choose(Value)

パラメータ

型:整数または文字列

Specify 1 for the first item, 2 for the second, etc.

If Value is a string (even a numeric string), the item whose leading name part matches Value will be selected. 検索では、大文字と小文字は区別されません。例えば、コントロールに「UNIXテキスト」という項目がある場合、unix(小文字)という単語を指定すれば、それだけで選択できます。複数選択リストボックスの場合、一致するすべての項目が選択されます。

Valueが0または空の場合、現在の選択項目は削除されます。

備考

多項目選択リストボックス全項目を選択または選択解除するには、次のようにします:

PostMessage 0x0185, 1, -1, ListBox  ; 全項目を選択。0x0185はLB_SETSELです。
PostMessage 0x0185, 0, -1, ListBox  ;すべてのアイテムの選択を解除します。
ListBox.Choose(0)  ; すべての項目の選択を解除します。

ControlChooseIndexとは異なり、このメソッドはChangeまたはDoubleClickイベントを発生させません。

Delete

Deletes one or all items from a multi-item control (ListBox, DropDownList, ComboBox, or Tab).

GuiCtrl.Delete(Value)

パラメータ

型:整数

If omitted, all items will be deleted. Otherwise, specify 1 for the first item, 2 for the second, etc.

備考

For Tab controls, a tab's sub-controls stay associated with their original tab number; that is, they are never associated with their tab's actual display-name. このため、タブの名前を変更したり削除しても、サブコントロールが属するタブ番号は変更されません。For example, if there are three tabs ["Red", "Green", "Blue"] and the second tab is removed by means of MyTab.Delete(2), the sub-controls originally associated with Green will now be associated with Blue. この動作のため、一般的には末尾のタブのみを削除する必要があります。この方法で削除されたタブは、後で再び追加することができ、その時は元の操作系を取り戻します。

ListView.Delete, TreeView.Delete

Focus

コントロールにキーボードフォーカスを設定します。

GuiCtrl.Focus()

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

To retrieve the focus state of the control, use the Focused property.

GetPos

コントロールの位置と大きさを取得します。

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

パラメータ

&X, &Y

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the X and Y coordinates (in pixels) of the control's upper left corner. These coordinates are relative to the upper-left corner of the window's client area, which is the area not including title bar, menu bar, and borders.

&Width, &Height

型:VarRef

省略したときは、対応する値は保存されません。Otherwise, specify references to the output variables in which to store the control's width and height (in pixels).

備考

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

MyEdit.GetPos(&x, &y, &w, &h)
MsgBox "The X coordinate is " x ". Y座標は" y "です。幅は" w "です。高さは " h "です。"

Move

コントロールの移動およびサイズ変更を行います。

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

パラメータ

X, Y

型:整数

If either is omitted, the control's position in that dimension will not be changed. Otherwise, specify the X and Y coordinates (in pixels) of the upper left corner of the control's new location. The coordinates are relative to the upper-left corner of the window's client area, which is the area not including title bar, menu bar, and borders.

幅、高さ

型:整数

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

備考

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

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

OnCommand

WM_COMMANDメッセージで制御通知を受信したときに呼び出される関数やメソッドを登録します。

GuiCtrl.OnCommand(NotifyCode, Callback , AddRemove)

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

OnEvent

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

GuiCtrl.OnEvent(EventName, Callback , AddRemove)

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

OnNotify

WM_NOTIFYメッセージで制御通知を受信したときに呼び出される関数やメソッドを登録します。

GuiCtrl.OnNotify(NotifyCode, Callback , AddRemove)

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

Opt

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

GuiCtrl.Opt(Options)

パラメータ

Options

型:文字列

Specify one or more control-specific or general options and styles, each separated from the next with one or more spaces or tabs.

備考

次の例では、コントロールが無効化され、その背景がシステムデフォルトに戻されています:

MyEdit.Opt("+Disabled -Background")

次の例では、OKボタンが新しいデフォルトボタンになります:

OKButton.Opt("+Default")

スタイルや拡張スタイルも認識されるが、コントロール作成後に適用・削除できないものもあります。変更が正常に適用されたとしても、コントロールはそれを無視することを選択するかもしれません。

Redraw

コントロールが占有するGUIウィンドウの領域を再描画します。

GuiCtrl.Redraw()

これは、繰り返し高速に呼び出された場合に不要なちらつきが発生する可能性がありますが、GroupBoxなどの特定のコントロールタイプの表示アーチファクトを解決することができます。

SetFont

コントロールのフォントの書体、サイズ、スタイル、色などを設定します。

GuiCtrl.SetFont(Options, FontName)

両方のパラメータを省略すると、Gui.SetFontで設定されたGUIのカレントフォントに設定されます。それ以外の場合、指定されていないフォント属性は、コントロールの以前のフォントからコピーされます。文字色は、オプションで指定した場合のみ変更されます。

両パラメータの詳細については、Gui.SetFontを参照してください。

属性

ClassNN

Retrieves the class name and sequence number (ClassNN) of the control.

ClassNN := GuiCtrl.ClassNN

コントロールのClassNNは、コントロールのウィンドウクラスの名前と、それを含むトップレベルウィンドウ内のシーケンス番号で構成されます。例えば、"Edit1"はウィンドウ上の最初のEditコントロール、"Button12"は2番目のボタンです。

関連:ControlGetClassNN

Enabled

Retrieves or sets the interaction state of the control.

CurrentSetting := GuiCtrl.Enabled
GuiCtrl.Enabled := NewSetting

CurrentSetting is NewSetting if assigned, otherwise 1 (true) by default unless overwritten by the Disabled option.

NewSetting is a boolean value that enables or disables this setting. If true, the control is enabled. If false, the control is disabled.

タブコントロールの場合、タブのサブコントロールもすべて有効または無効になります。ただし、GuiCtrl.Enabled := false で明示的に無効化されたサブコントロールは、その設定を記憶しているため、そのタブコントロールが再度有効化された後も無効のままです。

Focused

Retrieves the focus state of the control.

IsFocused := GuiCtrl.Focused

IsFocused is 1 (true) if the control has the keyboard focus, otherwise 0 (false).

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

To focus the control, use the Focus method.

Gui

Retrieves the Gui object of the control's parent window.

GuiObj := GuiCtrl.Gui

Hwnd

コントロールのウィンドウハンドル(HWND)を取得します。

Hwnd := GuiCtrl.Hwnd

コントロールのHWNDは、PostMessageSendMessageDllCallでよく使用されます。It can also be used directly in a Control parameter.

名前

コントロールの明示的な名前を取得または設定します。

CurrentName := GuiCtrl.Name
GuiCtrl.Name := NewName

CurrentName is NewName if assigned, otherwise an empty string by default unless overwritten by the V option.

NewName is the control's new name, which can be used with Gui.__Item to retrieve the GuiControl object. For most input-capable controls, the name is also used by Gui.Submit.

Text

コントロールのテキスト/キャプションを取得または設定します。

CurrentText := GuiCtrl.Text
GuiCtrl.Text := NewText

注:コントロールに可視キャプションテキストがなく、(単一の)テキスト値もない場合、このプロパティはコントロールの非表示キャプションテキストに対応します(ControlGetText/ControlSetTextのように)。

CurrentText and NewText depend on the control type:

Button / CheckBox / Edit / GroupBox / Link / Radio / Text

CurrentText and NewText are the caption/display text of the Button, CheckBox, Edit, GroupBox, Link, Radio or Text control. Since the control will not expand automatically, use GuiCtrl.Move(,, 300) or similar if the control needs to be widened.

DateTime

CurrentText and NewText are the formatted text displayed by the DateTime control. コントロールにフォーマットされた日付/時刻文字列を割り当てることはサポートされていません。To change the date/time being displayed, assign the Value property a date-time stamp in YYYYMMDDHH24MISS format.

DropDownList, ComboBox, ListBox, Tab

CurrentText and NewText are the text of the currently selected item/tab of the DropDownList, ComboBox, ListBox or Tab control.

NewText should be the full text (case-insensitive) of the item/tab to select.

コンボボックスの場合、選択された項目がない場合は、コントロールのエディットフィールドのテキストを代わりに取得します。For other controls, CurrentText is empty/blank. 同様に、NewTextが空/空白の場合は、現在のアイテム/タブが非選択になります。

For a multi-select ListBox, CurrentText is an array. NewTextは配列にはできませんが、複数の項目が一致した場合、すべて選択されます。To select multiple items with different text, call the Choose method repeatedly.

To select an item by its position number instead of its text, use the Value property.

Edit

CurrentText and NewText are the text of the Edit control. 他のコントロールと同様に、テキストはそのまま取得または設定され、行末の翻訳は行われません。To retrieve or set the text of a multi-line Edit control while also translating between `r`n and `n, use the Value property.

StatusBar

CurrentText and NewText are the text of the StatusBar control's first part only (use SB.SetText for greater flexibility).

Type

コントロールの種類を取得します。

CurrentType := GuiCtrl.Type

Depending on the control type, CurrentType is one of the following strings: ActiveX, Button, CheckBox, ComboBox, Custom, DateTime, DDL, Edit, GroupBox, Hotkey, Link, ListBox, ListView, MonthCal, Pic, Progress, Radio, Slider, StatusBar, Tab, Tab2, Tab3, Text, TreeView, UpDown.

Retrieves or sets the contents of a value-capable control.

CurrentValue := GuiCtrl.Value
GuiCtrl.Value := NewValue

注:If the control is not value-capable, CurrentValue will be blank and assigning NewValue will raise an error. 無効な値では例外が発生します。

CurrentValue and NewValue depend on the control type:

ActiveX

CurrentValue is the ActiveX object of the ActiveX control. 例えば、Shell.Explorerというテキストでコントロールが作成された場合、これはWebBrowserオブジェクトであることを示しています。毎回、同じラッパーオブジェクトが返されます。

NewValue is invalid and throws an exception.

CheckBox / Radio

CurrentValue is 1 if the CheckBox or Radio control is checked, 0 if it is unchecked, or -1 if it has a gray checkmark.

NewValueは、ボタンのチェックを外す場合は0、チェックする場合は1、グレーのチェックマークを付ける場合は-1です。ラジオボタンの場合、あるラジオボタンがチェックされている(オンになっている)場合、そのラジオボタンがマルチラジオグループのメンバーであれば、そのグループ内の他のラジオボタンは自動的にチェックされなくなります。

To get or set control's text/caption instead, use the Text property.

ComboBox / DropDownList / ListBox / Tab

CurrentValue is the position number of the currently selected item/tab in the ComboBox, DropDownList, ListBox or Tab control. 何も選択されていない場合は、0が返されます。ComboBoxにテキストが入力された場合、テキストが一致する最初の項目が使用されます。一致する項目がない場合、コントロール内にテキストがあっても結果は0となります。複数選択可能なリストボックスの場合、結果は数値の配列になります(項目が選択されていない場合は空です)。

NewValue is the position number of a single item/tab to select, or zero to clear the current selection (this is valid even for Tab controls). To select multiple items, call the Choose method repeatedly.

To get or set the selected item given its text instead of its position, use the Text property.

DateTime / MonthCal

CurrentValue is a date-time stamp in YYYYMMDDHH24MISS format currently selected in the DateTime or MonthCal control.

NewValueは、YYYYMMDDHH24MISS形式の日付-時間スタンプです。現在の日時(今日)を使用する場合は、A_Nowを指定します。DateTimeコントロールの場合、NewValueに空文字列を指定すると、(その能力で作成された場合)コントロールに日付/時刻が選択されないようにすることができる。MonthCalコントロールの場合、複数選択可能な場合は、範囲を指定することができます。

Edit

CurrentValue is the current content of the Edit control. 複数行のコントロールの場合、テキストの改行は、ControlGetTextControlSetTextなどの非GUI関数で使用される従来のCR+LF(`r`n)ではなく、プレーンラインフィード(`n)として表されます。

NewValueは新しいコンテンツです。複数行のコントロールの場合、NewValueの改行(`n)のうち、先行するキャリッジリターン(`r)がないものは、自動的にCR+LF(`r`n)に変換され、正しく表示されます。しかし、Gui.Submitを使用する際や、この値を取得する際には、CR+LFをLF(`n)に置き換えることで、この変換は自動的に逆転するので、通常は気にする必要はありません。

To retrieve or set the text without translating `n to or from `r`n, use the Text property.

Hotkey

CurrentValue is the modifiers and key name if there is a hotkey in the Hotkey control; otherwise blank. 例:^!C, ^Home, +^NumpadHome.

NewValueには、キー名を持つ修飾語のセット、またはコントロールをクリアするためのブランクを指定することができます。例:^!c, ^Numpad1, +Home. The only modifiers supported are ^ (Control), ! (Alt), and + (Shift). 使用可能なキー名については、キーリストを参照してください。

画像

CurrentValue is the picture's file name as it was originally specified when the Picture control was created. この名前は、新しい画像ファイル名が指定されても変わりません。

NewValueは、読み込む新しい画像のファイル名(またはハンドル)です(サポートされているファイルタイプはPictureを参照してください)。ファイル名の直前に、以下のオプションを0個以上指定することができます:*wN(幅N)、*hN(高さN)、*IconN(DLLまたはEXEファイル内のアイコン群番号N)です。次の例では、2番目のアイコングループのデフォルトアイコンが、幅100、「縦横比を保つ」による自動高さで読み込まれます:MyPic.Value := "*icon2 *w100 *h-1 C:\My Application.exe". 画像の実際の幅と高さを使用する場合は、*w0 *h0を指定します。whが省略された場合、画像はコントロールの現在のサイズに合うように拡大縮小されます。マルチアイコンの.ICOファイルから読み込む場合、幅と高さを指定することで、どのアイコンを読み込むかも決まります。注:最後のオプションとファイル名の間には、スペースまたはタブを1つだけ使用します。その他のスペースやタブは、ファイル名の一部として扱われます。

Progress / Slider / UpDown

CurrentValue is the current position of the Progress, Slider or UpDown control.

NewValueはコントロールの新しい位置で、例えばMySlider.Value := 10のようになります。相対的に値を調整する場合は、:=の代わりに演算子+=、-=、++、--を使用します。新しい位置がコントロールの範囲外になる場合、コントロールは一般的に最も近い有効値に設定されます。

Text

CurrentValue is the text/caption of the Text control.

NewValueは、コントロールの新しいテキストです。Since the control will not expand automatically, use GuiCtrl.Move(,, 300) if the control needs to be widened.

Visible

Retrieves or sets the visibility state of the control.

CurrentSetting := GuiCtrl.Visible
GuiCtrl.Visible := NewSetting

CurrentSetting is NewSetting if assigned, otherwise 1 (true) by default unless overwritten by the Hidden option.

NewSetting is a boolean value that enables or disables this setting. If true, the control is visible. If false, the control is hidden.

タブコントロールの場合、タブのサブコントロールの表示・非表示もすべて行います。また、コントロールのショートカットキー(下線文字)が効かないようにしたい場合は、GuiCtrl.Enabled := falseでコントロールを無効化します。

総論

Redraw

リストビューツリービューリストボックスなどのコントロールに多数のアイテムを追加する場合、変更中にコントロールが再描画されるのを防ぐことで、パフォーマンスを向上させることができます。これは、項目を追加する前にGuiCtrl.Opt("-Redraw")、追加後にGuiCtrl.Opt("+Redraw")を使用することで実現しています。再描画を無効にする前にまだ表示されていなかったコントロールの変更は、通常、再描画が再有効になるまで表示されません。

パフォーマンス上の理由から、一般に、コントロールの内容を変更しても、再描画が有効であっても、コントロールが直ちに再描画されることはありません。その代わり、制御の一部が「無効化」され、通常、プログラムが内部メッセージキューをチェックする際に、短い遅延の後に再描画されます。スクリプトは、Sleep -1を呼び出すことで、これを直ちに強制的に実行させることができます。