指定された位置にどのメニューアイテムがあるかを判定します。
#Include <GuiMenu.au3>
_GUICtrlMenu_MenuItemFromPoint($hWnd, $hMenu[, $iX = -1[, $iY = -1]])
パラメータ
$hWnd | メニューを格納しているウィンドウのハンドル。 この値が0で$hMenuがポップアップメニューの場合、この関数はメニューウィンドウを見つけ出します。 |
$hMenu | ヒットテストをおこなうメニューアイテムを格納しているメニューのハンドル |
$iX | [オプション]テストするX座標。-1の場合、現在のマウスのX座標が使用されます。 |
$iY | [オプション]テストするY座標. -1の場合、現在のマウスのY座標が使用されます。 |
返し値
成功: | 指定された座標にあるメニューアイテムのゼロ始まりの位置 |
失敗: | -1 |
注意
$hMenuがメニューバーの場合は座標はウィンドウ座標です。それ以外の場合はクライアント座標です。
関連
こちらも参照
MSDNライブラリでMenuItemFromPointを検索して下さい。
例
#include <GuiMenu.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hWnd, $hMain, $hFile, $tRect, $tPoint, $iX, $iY, $iIndex
; メモ帳を開く
Run("Notepad.exe")
WinWaitActive("[CLASS:Notepad]")
$hWnd = WinGetHandle("[CLASS:Notepad]")
$hMain = _GUICtrlMenu_GetMenu($hWnd)
$hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0)
; ファイルメニューを開く
Send("!f")
Sleep(1000)
; マウスをメニューアイテム"開く"の上に移動
$tRect = _GUICtrlMenu_GetItemRectEx($hWnd, $hFile, 1)
$tPoint = _Lib_PointFromRect($tRect, True)
_Lib_GetXYFromPoint($tPoint, $iX, $iY)
MouseMove($iX, $iY, 1)
Sleep(1000)
; 現在のマウス位置のメニューアイテムを取得
$iIndex = _GUICtrlMenu_MenuItemFromPoint($hWnd, $hFile)
Send("{ESC 2}")
Writeln("Menu item under cursor was: " & $iIndex)
EndFunc ;==>_Main
; メモ帳にテキストを1行書き込む
Func Writeln($sText)
ControlSend("[CLASS:Notepad]", "", "Edit1", $sText & @CR)
EndFunc ;==>Writeln
Func _Lib_PointFromRect(ByRef $tRect, $fCenter = True)
Local $iX1, $iY1, $iX2, $iY2, $tPoint
$iX1 = DllStructGetData($tRect, "Left")
$iY1 = DllStructGetData($tRect, "Top")
$iX2 = DllStructGetData($tRect, "Right")
$iY2 = DllStructGetData($tRect, "Bottom")
If $fCenter Then
$iX1 = $iX1 + (($iX2 - $iX1) / 2)
$iY1 = $iY1 + (($iY2 - $iY1) / 2)
EndIf
$tPoint = DllStructCreate($tagPOINT)
DllStructSetData($tPoint, "X", $iX1)
DllStructSetData($tPoint, "Y", $iY1)
Return $tPoint
EndFunc ;==>_Lib_PointFromRect
Func _Lib_GetXYFromPoint(ByRef $tPoint, ByRef $iX, ByRef $iY)
$iX = DllStructGetData($tPoint, "X")
$iY = DllStructGetData($tPoint, "Y")
EndFunc ;==>_Lib_GetXYFromPoint