看到这个,正好遇到个这方面的问题请教一下:如下代码创建的右键菜单,本来想让它建在explorer窗口的地址栏下方的,但怎么老是位置要靠上一点,定位不是那么准呢
Run("Explorer")
Sleep(500)
HotKeySet("^d", "DirHotList")
While 1
Sleep(200)
WEnd
Func DirHotList()
$hwdDirMenu = GUICreate("", 100, 100, -1000, -1000, -1, -1,WinGetHandle(AutoItWinGetTitle()))
$FileMenu = GUICtrlCreateContextMenu()
$Menu1 = GUICtrlCreateMenuItem("Menu1", $FileMenu)
$Exit = GUICtrlCreateMenuItem("Exit", $FileMenu)
GUISetState()
ShowMenu($hwdDirMenu, $FileMenu)
While True
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $Menu1
MsgBox(0,0,"ok")
Case $Exit
Exit
EndSwitch
WEnd
GUIDelete()
EndFunc
Func ShowMenu($hWnd, $nContextID)
Local $WinPos, $CtrlPos, $moPos[2], $hMenu, $hwdTopMost
$hwdTopMost = WinGetHandle("[CLASS:ExploreWClass]")
$WinPos = WinGetPos($hwdTopMost)
$CtrlPos = ControlGetPos($hwdTopMost, "", "Edit1")
$moPos[0] = $WinPos[0] + $CtrlPos[0]
$moPos[1] = $WinPos[1] + $CtrlPos[1] + $CtrlPos[3] ;<===加上这个$ctrlPos[3]:控件宽度,本来应该在控件下方了,结果还不是呢
$hMenu = GUICtrlGetHandle($nContextID)
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $moPos[0], "int", $moPos[1], "hwnd", $hWnd, "ptr", 0)
EndFunc
|