<style type="text/css"> .sized1 { width: 20em; } .sized2 { width: 4em; } </style> </head> <body> <h1>MsgBox</h1> <p>指定されたテキストを、1つまたは複数のボタン(YesやNoなど)を含む小さなウィンドウに表示します。</p> <pre class="Syntax"><span class="func">MsgBox</span> <span class="optional">Text, Title, Options</span> Result := <span class="func">MsgBox</span>(<span class="optional">Text, Title, Options</span>)</pre> <h2 id="Parameters">パラメータ</h2> <dl> <dt>Text</dt> <dd> <p>型:<a href="../Concepts.htm#strings">文字列</a></p> <p>If omitted and "OK" is the only button present, it defaults to the string "Press OK to continue.". If omitted in any other case, it defaults to an empty string. Otherwise, specify the text to display inside the message box.</p> <p><a href="../misc/EscapeChar.htm">エスケープシーケンス</a>は、特殊文字を表すために使用することができます。例えば、`nは改行文字を示し、現在の行を終了して新しい行を開始します。したがって、<code>text1`n`ntext2</code>を使用すると、text1とtext2の間に空白行ができる。</p> <p><em>Text</em>が長い場合、<a href="../Scripts.htm#continuation">継続セクション</a>によっていくつかの短い行に分割することができ、読みやすさと保守性を向上させることができるかもしれません。</p> </dd> <dt>Title</dt> <dd> <p>型:<a href="../Concepts.htm#strings">文字列</a></p> <p>省略したときは、<a href="../Variables.htm#ScriptName">A_ScriptName</a>の現在の値がデフォルトとなります。Otherwise, specify the title of the message box.</p> </dd> <dt>Options</dt> <dd> <p>型:<a href="../Concepts.htm#strings">文字列</a></p> <p>If blank or omitted, it defaults to 0 (only an OK button is displayed). Otherwise, specify a combination (sum) of values or a string of one or more options from the tables below to indicate the type of message box and the possible button combinations.</p> <p>さらに、以下のオプションを0個以上指定することができます:</p> <p id="OwnerOption"><strong>Owner:</strong>メッセージボックスの<a href="#Owner">オーナーウィンドウ</a>を指定するには、Ownerという単語の直後にHWND(ウィンドウID)を使用します。</p> <p id="Timeout"><strong>T:</strong>タイムアウト。指定した時間内にユーザーがメッセージボックスを閉じなかった場合、自動的に閉じるようにするには、文字Tの後にタイムアウトを秒単位で指定します(小数点以下も可)。この値が2147483(24.8日)を超えた場合、2147483に設定されます。メッセージボックスがタイムアウトした場合、<a href="#Result">戻り値</a>はTimeoutという文字になります。</p> </dd> </dl> <h2 id="Options"><em>Options</em>パラメータに設定する値</h2> <p><em>Options</em>パラメータには、以下のグループからの数値の組み合わせ(合計)をオペレーティングシステムのMessageBox関数に直接渡すか、0個以上の大文字小文字を区別しないオプションを少なくとも1つのスペースまたはタブで区切った文字列を指定することができます。また、1つ以上の数値オプションを文字列に含めることができます。</p> <h3 id="Group_1_Buttons">グループ1:ボタン</h3> <p>メッセージボックスに表示されるボタンを指示するために、以下の値の<u>いずれか</u>を追加します:</p> <table class="info"> <tr> <th class="sized1">関数</th> <th class="sized2 right">十進法</th> <th class="sized2 right">十六進法</th> <th>文字列</th> </tr> <tr> <td>OK</td> <td class="right">0</td> <td class="right">0x0</td> <td><code>OK</code>または<code>O</code></td> </tr> <tr> <td>OK、キャンセル</td> <td class="right">1</td> <td class="right">0x1</td> <td><code>OKCancel</code>、<code>O/C</code>または<code>OC</code></td> </tr> <tr> <td>中止(A)、再試行(R)、無視(I)</td> <td class="right">2</td> <td class="right">0x2</td> <td><code>AbortRetryIgnore</code>、<code>A/R/I</code>または<code>ARI</code></td> </tr> <tr> <td>はい(Y)、いいえ(N)、キャンセル</td> <td class="right">3</td> <td class="right">0x3</td> <td><code>YesNoCancel</code>、<code>Y/N/C</code>または<code>YNC</code></td> </tr> <tr> <td>はい(Y)、いいえ(N)</td> <td class="right">4</td> <td class="right">0x4</td> <td><code>YesNo</code>、<code>Y/N</code>または<code>YN</code></td> </tr> <tr> <td>再試行(R)、キャンセル</td> <td class="right">5</td> <td class="right">0x5</td> <td><code>RetryCancel</code>、<code>R/C</code>または<code>RC</code></td> </tr> <tr> <td>キャンセル、再実行(T)、続行(C)</td> <td class="right">6</td> <td class="right">0x6</td> <td><code>CancelTryAgainContinue</code>、<code>C/T/C</code>または<code>CTC</code></td> </tr> </table> <h3 id="Group_2_Icon">グループ2:アイコン</h3> <p>メッセージボックスにアイコンを表示するには、次の値の<u>いずれか</u>を追加します:</p> <table class="info"> <tr> <th class="sized1">関数</th> <th class="sized2 right">十進法</th> <th class="sized2 right">十六進法</th> <th>文字列</th> </tr> <tr> <td>Icon Hand (stop/error)</td> <td class="right">16</td> <td class="right">0x10</td> <td><code>Iconx</code></td> </tr> <tr> <td>Icon Question</td> <td class="right">32</td> <td class="right">0x20</td> <td><code>Icon?</code></td> </tr> <tr> <td>Icon Exclamation</td> <td class="right">48</td> <td class="right">0x30</td> <td><code>Icon!</code></td> </tr> <tr> <td>Icon Asterisk (info)</td> <td class="right">64</td> <td class="right">0x40</td> <td><code>Iconi</code></td> </tr> </table> <h3 id="Group_3_Default_Button">グループ3:デフォルトボタン</h3> <p>デフォルトのボタンを示すには、以下の値の<u>いずれか</u>を追加します:</p> <table class="info"> <tr> <th class="sized1">関数</th> <th class="sized2 right">十進法</th> <th class="sized2 right">十六進法</th> <th>文字列</th> </tr> <tr> <td>第2ボタンをデフォルトにする</td> <td class="right">256</td> <td class="right">0x100</td> <td><code>Default2</code></td> </tr> <tr> <td>第3ボタンをデフォルトにする</td> <td class="right">512</td> <td class="right">0x200</td> <td><code>Default3</code></td> </tr> <tr> <td>第4ボタンをデフォルトにする<br>(<a href="#Help">ヘルプボタン</a>があることが必要です)</td> <td class="right">768</td> <td class="right">0x300</td> <td><code>Default4</code></td> </tr> </table> <h3 id="Group_4_Modality">グループ4:モダリティ</h3> <p>ダイアログボックスのモダリティを示すために、以下の値の<u>いずれか</u>を追加します:</p> <table class="info"> <tr> <th class="sized1">関数</th> <th class="sized2 right">十進法</th> <th class="sized2 right">十六進法</th> <th>文字列</th> </tr> <tr> <td>システムモーダル(常に上部に表示される)</td> <td class="right">4096</td> <td class="right">0x1000</td> <td>該当なし</td> </tr> <tr> <td>Task Modal</td> <td class="right">8192</td> <td class="right">0x2000</td> <td>該当なし</td> </tr> <tr> <td>常時トップ(スタイル WS_EX_TOPMOST)<br>(システムモーダル同様、タイトルバーアイコンが省略されています)</td> <td class="right">262144</td> <td class="right">0x40000</td> <td>該当なし</td> </tr> </table> <h3 id="Group_5_Other_Options">グループ5:その他のオプション</h3> <p>その他のオプションを指定する場合は、以下の値を<u>1つ以上</u>追加してください:</p> <table class="info"> <tr> <th class="sized1">関数</th> <th class="sized2 right">十進法</th> <th class="sized2 right">十六進法</th> <th>文字列</th> </tr> <tr id="Help"> <td>ヘルプボタンを追加します(下記備考参照)</td> <td class="right">16384</td> <td class="right">0x4000</td> <td>該当なし</td> </tr> <tr> <td>テキストを右寄せにします</td> <td class="right">524288</td> <td class="right">0x80000</td> <td>該当なし</td> </tr> <tr> <td>ヘブライ語/アラビア語の右から左への読み方</td> <td class="right">1048576</td> <td class="right">0x100000</td> <td>該当なし</td> </tr> </table> <h2 id="Result">戻り値</h2> <p>型:<a href="../Concepts.htm#strings">文字列</a></p> <p>この関数は、ユーザーがどのボタンを押したかを表すために、以下の文字列のいずれかを返します:</p> <ul> <li>OK</li> <li>Cancel</li> <li>Yes</li> <li>No</li> <li>Abort</li> <li>Retry</li> <li>Ignore</li> <li>TryAgain</li> <li>Continue</li> <li>Timeout(メッセージボックスがタイムアウトした場合、"timeout"という単語が返されます)</li> </ul> <p>ダイアログを表示できなかった場合は、空文字列が返されます。これは通常、<a href="#max">MsgBoxの制限</a>に達した場合にのみ発生しますが、その他の異常なケースでも発生する可能性があります。</p> <h2 id="Error_Handling">エラー処理</h2> <p>オプションが無効な場合、<a href="#max">MsgBoxの制限</a>に達した場合、またはその他の理由でメッセージボックスを表示できなかった場合など、失敗すると<a href="Error.htm">Error</a>がスローされます。</p> <h2 id="Remarks">備考</h2> <p>メッセージボックスは通常このように表示されます:</p> <img src="../static/dlg_message.png" alt="MsgBox" /> <p>ユーザーがどのボタンを押したかを判断するには、関数の<a href="#Result">戻り値</a>を使用します。事例:</p> <pre>Result := MsgBox("Would you like to continue?(press Yes or No)",, "YesNo") if Result = "Yes" MsgBox "You pressed Yes." else MsgBox "You pressed No." if MsgBox("Retry or cancel?",, "R/C") = "Retry" MsgBox("You pressed Retry.")</pre> <p>To customize the names of the buttons, see <a href="../scripts/index.htm#MsgBoxButtonNames">Changing MsgBox's Button Names</a>.</p> <p class="note"><strong>注意:</strong>メッセージボックスがアクティブな状態で<kbd>Ctrl</kbd>+<kbd>C</kbd>を押すと、そのテキストがクリップボードにコピーされます。これは、AutoHotkeyで作成されたメッセージボックスだけでなく、すべてのメッセージボックスに適用されます。</p> <p id="Owner"><strong>GUIウィンドウでMsgBoxを使用:</strong>GUIウィンドウは、<a href="Gui.htm#OwnDialogs">OwnDialogsオプション</a>により、<em>モーダルメッセージボックス</em>を表示することができる。<em>モーダルメッセージボックス</em>は、メッセージボックスが解除されるまで、ユーザーがGUIウィンドウと対話することを妨げます。この場合、上表からシステムモード、タスクモードのオプションを指定する必要はありません。</p> <p><a href="Gui.htm#OwnDialogs">OwnDialogsオプション</a>が有効で<em>ない</em>場合、Task Modalオプション(8192)を使用すると、ユーザーがメッセージボックスを解除するまで、スクリプトのすべてのウィンドウを無効にすることができます。</p> <p><code>Owner<i>HWND</i></code>オプションが指定されている場合は、他の設定より優先されます。<i>HWND</i>には、スクリプトが所有していないウィンドウのHWNDも指定することができます。</p> <p><strong>ヘルプボタン:</strong><em>Options</em>でヘルプボタンオプション(16384)がある場合、以下の両方が成立していないと、ヘルプボタンを押しても効果がありません:</p> <ol> <li>メッセージボックスは、<a href="Gui.htm#OwnDialogs">OwnDialogsオプション</a>により、GUIウィンドウに所有されます。</li> <li>スクリプトはWM_HELPメッセージ(0x0053)を監視しています。事例:<code><a href="OnMessage.htm">OnMessage</a>(0x0053, WM_HELP)</code>。WM_HELP関数が呼び出されると、別のウィンドウやメッセージボックスを表示するなどの手段でユーザーを誘導することができる。</li> </ol> <p><strong>閉じるボタン(メッセージボックスのタイトルバー内):</strong>メッセージボックスはOSの組み込み機能なので、そのXボタンは特定のボタンが存在する場合にのみ有効になります。OKボタンしかない場合は、XボタンをクリックするとOKを押したのと同じになります。それ以外の場合は、キャンセルボタンがない限りXボタンは無効で、その場合はXをクリックするとキャンセルを押したのと同じことになります。</p> <p id="max"><strong>最大で7回の通話が可能:</strong>メッセージボックスを表示している<a href="../misc/Threads.htm">スレッド</a>は、通常、中断することができ、前の呼び出しが戻る前に新しいスレッドが独自のメッセージボックスを表示することができます。MsgBoxの呼び出しは最大7回まで可能ですが、7回目を超えると<a href="Error.htm">Error</a>が投げられます。中断されたスレッドでMsgBoxを呼び出すと、スレッドが再開されるまで戻ることができないことに注意してください。</p> <h2 id="Related">関連</h2> <p><a href="InputBox.htm">InputBox</a>、<a href="FileSelect.htm">FileSelect</a>、<a href="DirSelect.htm">DirSelect</a>、<a href="ToolTip.htm">ToolTip</a>、<a href="Gui.htm">Guiオブジェクト</a></p> <h2 id="Examples">例</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> 特定のテキストを含むメッセージボックスを表示します。情報を素早く簡単に表示する方法です。ユーザーはOKボタンを押すことでメッセージボックスを閉じ、実行を継続することができます。</p> <pre>MsgBox "This is a string."</pre> </div> <div class="ex" id="ExTitle"> <p><a class="ex_number" href="#ExTitle"></a> 特定のテキストとタイトルを含むメッセージボックスを表示します。</p> <pre>MsgBox "This MsgBox has a custom title.", "A Custom Title"</pre> </div> <div class="ex" id="ExNoParams"> <p><a class="ex_number" href="#ExNoParams"></a> デフォルトのテキストでメッセージボックスを表示します。主にデバッグ用途で、スクリプトにブレークポイントを素早く設定する場合などに便利です。</p> <pre>MsgBox <em>; "Press OK to continue."</em></pre> </div> <div class="ex" id="ExContSec"> <p><a class="ex_number" href="#ExContSec"></a> 特定のテキスト、タイトル、情報アイコンを含むメッセージボックスが表示されます。そのほか、複数行のテキストをよりわかりやすく表示するために、<a href="../Scripts.htm#continuation">コンティニュアスセクションを</a>使用しています。</p> <pre> MsgBox " ( 最初のパラメーターがメッセージとして表示される。 2番目のパラメータはウィンドウのタイトルになります。 3番目のパラメータはメッセージボックスのタイプを決定します。 )", "ウィンドウタイトル", "iconi" </pre> </div> <div class="ex" id="ExRetValue"> <p><a class="ex_number" href="#ExRetValue"></a> 戻り値から、ユーザーがメッセージボックスのどのボタンを押したかを判断します。この場合、MsgBox関数呼び出しは<a href="../Language.htm#function-call-statements">括弧で</a>指定する必要があることに注意してください。</p> <pre>result := MsgBox("Do you want to continue?(Press YES or NO)",, "YesNo") if (result = "No") return</pre> </div> <div class="ex" id="ExTimeout"> <p><a class="ex_number" href="#ExTimeout"></a> T(タイムアウト)オプションを使用すると、一定の秒数後にメッセージボックスを自動的に閉じます。</p> <pre>result := MsgBox("This MsgBox will time out in 5 seconds. Continue?",, "Y/N T5") if (result = "Timeout") MsgBox "You didn't press YES or NO within the 5-second period." else if (result = "No") return</pre> </div> <div class="ex" id="ExExpr"> <p><a class="ex_number" href="#ExExpr"></a> メッセージに変数や部分式を含める。こちらも参照のこと:<a href="../Variables.htm#concat">連結</a></p> <pre> var := 10 MsgBox "The initial value is: " var MsgBox "The result is: " var * 2 MsgBox <a href="Format.htm">Format</a>("The result is: {1}", var * 2) </pre> </div> </body> </html>