Trong Posted July 8, 2021 Posted July 8, 2021 (edited) Use when there is an unknown menu list: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global Const $Default_Value_Apache_ConfigFile = 'Apache\conf\httpd.conf|Apache\conf\extra\httpd-autoindex.conf|Apache\conf\extra\httpd-dav.conf|Apache\conf\extra\httpd-default.conf|Apache\conf\extra\httpd-info.conf|Apache\conf\extra\httpd-languages.conf|Apache\conf\extra\httpd-manual.conf|Apache\conf\extra\httpd-mpm.conf|Apache\conf\extra\httpd-multilang-errordoc.conf|Apache\conf\extra\httpd-ssl.conf|Apache\conf\extra\httpd-userdir.conf|Apache\conf\extra\httpd-vhosts.conf|Apache\conf\extra\proxy-html.conf' Global Const $Default_Value_Apache_LogsFile = 'Apache\logs\access.log|Apache\logs\apache_request.log|Apache\logs\Error.log' Global $Array_hWnd_Menu_ConfigFile[], $Array_hWnd_Menu_LogsFile[], $Array_Menu_ConfigFile[], $Array_Menu_LogsFile[] Example() Func Example() Local $hGui = GUICreate("MenuItem Click unknow list", 250, 40) Local $idConfigsBtn = GUICtrlCreateButton("&Configs", 10, 10, 70, 20, $BS_FLAT) ; At first create a dummy control for the Configs and a contextmenu for it Local $idConfigsDummy = GUICtrlCreateDummy() Local $idConfigsContext = GUICtrlCreateContextMenu($idConfigsDummy) If StringInStr($Default_Value_Apache_ConfigFile, '|') Then $Array_Menu_ConfigFile = StringSplit($Default_Value_Apache_ConfigFile, '|') For $i = 1 To UBound($Array_Menu_ConfigFile) - 1 $Array_hWnd_Menu_ConfigFile[$i] = GUICtrlCreateMenuItem($Array_Menu_ConfigFile[$i], $idConfigsContext) Next EndIf Local $idLogsBtn = GUICtrlCreateButton("&Logs", 90, 10, 70, 20, $BS_FLAT) ; Create a dummy control and a contextmenu for the Logs too Local $idLogsDummy = GUICtrlCreateDummy() Local $idLogsContext = GUICtrlCreateContextMenu($idLogsDummy) If StringInStr($Default_Value_Apache_LogsFile, '|') Then $Array_Menu_LogsFile = StringSplit($Default_Value_Apache_LogsFile, '|') For $a = 1 To UBound($Array_Menu_LogsFile) - 1 $Array_hWnd_Menu_LogsFile[$a] = GUICtrlCreateMenuItem($Array_Menu_LogsFile[$a], $idLogsContext) Next EndIf GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idConfigsBtn ShowMenu($hGui, $idMsg, $idConfigsContext) Case $idLogsBtn ShowMenu($hGui, $idMsg, $idLogsContext) Case Else EndSwitch For $z = 1 To UBound($Array_Menu_ConfigFile) - 1 If $Array_hWnd_Menu_ConfigFile[$z] = $idMsg Then MsgBox(0, '-Menu Clicked: ' & $z, $Array_Menu_ConfigFile[$z]) EndIf Next For $x = 1 To UBound($Array_Menu_LogsFile) - 1 If $Array_hWnd_Menu_LogsFile[$x] = $idMsg Then MsgBox(0, '+Menu Clicked: ' & $x, $Array_Menu_LogsFile[$x]) EndIf Next WEnd GUIDelete() EndFunc ;==>Example ; Show a menu in a given GUI window which belongs to a given GUI ctrl Func ShowMenu($hWnd, $idCtrl, $idContext) Local $aPos, $x, $y Local $hMenu = GUICtrlGetHandle($idContext) $aPos = ControlGetPos($hWnd, "", $idCtrl) $x = $aPos[0] $y = $aPos[1] + $aPos[3] ClientToScreen($hWnd, $x, $y) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc ;==>ShowMenu ; Convert the client (GUI) coordinates to screen (desktop) coordinates Func ClientToScreen($hWnd, ByRef $x, ByRef $y) Local $tPoint = DllStructCreate("int;int") DllStructSetData($tPoint, 1, $x) DllStructSetData($tPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint) $x = DllStructGetData($tPoint, 1) $y = DllStructGetData($tPoint, 2) ; release Struct not really needed as it is a local $tPoint = 0 EndFunc ;==>ClientToScreen ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc ;==>TrackPopupMenu Edited July 8, 2021 by VIP Image Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now