本帖最后由 3mile 于 2011-5-22 22:33 编辑
回复 4# lixiaolong
用个笨办法试试:
#include <GuiMenu.au3>
Opt('WinSearchChildren', 1)
HotKeySet('{ESC}', '_EXIT')
OnAutoItExitRegister('OnAutoItExit')
Global Const $MN_GETHMENU = 0x01E1
Global Const $EVENT_SYSTEM_MENUPOPUPSTART = 0x0006
Global Const $EVENT_SYSTEM_MENUPOPUPEND = 0x0007
Global $tPOINT, $tRECT[1], $hEventHook, $Index, $hMenu = 0, $itemtext[1]
Global $hFunc, $pFunc
Global $hWinHook
$hFunc = DllCallbackRegister('_WinEventProc', 'none', 'ptr;uint;hwnd;int;int;uint;uint')
$pFunc = DllCallbackGetPtr($hFunc)
$hWinHook = _SetWinEventHook(0x00000001, 0x7FFFFFFF, 0, $pFunc, 0, 0, BitOR(0x0002, 0x0000))
While 1
Sleep(20)
WEnd
Func _EXIT()
Exit
EndFunc ;==>_EXIT
Func OnAutoItExit()
_UnhookWinEvent($hWinHook)
DllCallbackFree($hFunc)
EndFunc ;==>OnAutoItExit
Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
Switch $iEvent
Case $EVENT_SYSTEM_MENUPOPUPSTART
$hMenu = _SendMessage($hWnd, 0x01E1)
$Index = _GUICtrlMenu_GetItemCount($hMenu)
ReDim $tRECT[$Index]
ReDim $itemtext[$Index]
For $i = 0 To $Index - 1
$tRECT[$i] = _GUICtrlMenu_GetItemRectEx($hWnd, $hMenu, $i)
$itemtext[$i] = _GUICtrlMenu_GetItemText($hMenu, $i)
Next
Case $EVENT_SYSTEM_MENUPOPUPEND
If $hMenu Then
$tPOINT = _WinAPI_GetMousePos()
For $i = 0 To UBound($tRECT) - 1
If _WinAPI_PtInRect($tRECT[$i], $tPOINT) Then
ToolTip($itemtext[$i], @DesktopWidth - 100, @DesktopHeight - 100, "点击的菜单项:", 1, 4)
EndIf
Next
Global $tRECT[1]
Global $itemtext[1]
$hMenu = 0
EndIf
EndSwitch
EndFunc ;==>_WinEventProc
Func _SetWinEventHook($ieventMin, $ieventMax, $hMod, $pCallback, $iProcID, $iThreadID, $iFlags)
Local $aRet
$aRet = DllCall('user32.dll', 'ptr', 'SetWinEventHook', 'uint', $ieventMin, 'uint', $ieventMax, _
'hwnd', $hMod, 'ptr', $pCallback, 'dword', $iProcID, 'dword', $iThreadID, 'uint', $iFlags)
If @error Or $aRet[0] = 0 Then Return SetError(1, 0, 0)
Return $aRet[0]
EndFunc ;==>_SetWinEventHook
Func _UnhookWinEvent($hWinEventHook)
Local $aRet
$aRet = DllCall('user32.dll', 'int', 'UnhookWinEvent', 'ptr', $hWinEventHook)
If @error Or $aRet[0] = 0 Then Return SetError(1, 0, 0)
Return $aRet[0]
EndFunc ;==>_UnhookWinEvent
|