Jump to content

how to get the pressed menu item with out variable


Recommended Posts

hello guys
how are you؟
I hope to be fine.
I have a question  please
how do I get the menu item that was pressed without that contains a variable؟
For example I have a menu  of Favorites and I want the script recognizes the existing path in the pressed item
i'll repeat to tell the item does not contain a variable
Is there any solution
if you want to explain more I could write an example of what I want.
Greetings to all,
thanks in advance

Link to comment
Share on other sites

  • Moderators

An example of what you want would be great, as I believe there is a language barrier issue. Please provide an example/screenshot that shows exactly what you're after.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

OK this is an example

i want when i pressed ani item from the favourites menu the script run the path

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <file.au3>
local $hGUI, $menu, $file, $path, $msg
$hGUI = GUICreate("menu item")
$menu = GUICtrlCreateMenu("Favourites")
GUISetState()
$file = @scriptDir & "\file.txt"
;Writing file
FileWrite($file, @systemDir & "\notepad.exe" & @crlf)
FileWrite($file, @systemDir & "\explorer.exe" & @crlf)
FileWrite($file, @systemDir & "\regedit.exe")
; add item to menu

for $i = 1 to _FileCountLines($file)
$add = GUICtrlCreateMenuItem(FileReadLine($file, $i), $menu)
next
FileDelete($file)

While 1
Switch GUIGetMSG()
case $GUI_event_close
exit
EndSwitch
Wend

Edited by nacerbaaziz
Link to comment
Share on other sites

#RequireAdmin

#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <file.au3>

Local $hGUI, $menu, $file

$hGUI = GUICreate("menu item")
$menu = GUICtrlCreateMenu("Favourites")
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$file = @ScriptDir & "\file.txt"
;Writing file
FileWrite($file, @WindowsDir & "\notepad.exe" & @CRLF)
FileWrite($file, @WindowsDir & "\explorer.exe" & @CRLF)
FileWrite($file, @WindowsDir & "\regedit.exe")

; add item to menu
For $i = 1 To _FileCountLines($file)
    GUICtrlCreateMenuItem(FileReadLine($file, $i), $menu)
Next
FileDelete($file)

While 1
    Switch GUIGetMsg()
        Case $GUI_event_close
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  Local $item = _GUICtrlMenu_GetItemSubMenu(_GUICtrlMenu_GetMenu($hGUI), 0)
  Run(_GUICtrlMenu_GetItemText($item, _GUICtrlMenu_MenuItemFromPoint($hGUI, $item)))
  Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

If you don't know how wm_command works then use native message loop

#RequireAdmin

#include <GUIConstantsEx.au3>
#include <file.au3>

Local $hGUI, $menu, $file, $item[3]

$hGUI = GUICreate("menu item")
$menu = GUICtrlCreateMenu("Favourites")
GUISetState()

$file = @ScriptDir & "\file.txt"
;Writing file
FileWrite($file, @WindowsDir & "\notepad.exe" & @CRLF)
FileWrite($file, @WindowsDir & "\explorer.exe" & @CRLF)
FileWrite($file, @WindowsDir & "\regedit.exe")

; add item to menu
For $i = 1 To _FileCountLines($file)
    $item[$i - 1] = GUICtrlCreateMenuItem(FileReadLine($file, $i), $menu)
Next
FileDelete($file)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_event_close
            Exit
        Case $item[0] To $item[2]
            Run(GUICtrlRead($msg, 1))
    EndSwitch
WEnd

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...