Jump to content

dynamic menu object clicking


 Share

Recommended Posts

Hi again I am trying to execute *.lnk file at desktop as you can see I have already made function to list shortcuts from desktop to menu. And now the final thing, CLICK on them to execute program. I got stuck here, How to do that if i click on shortcut name at menu then script executes that shortcut?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $failidritta = _FileListToArray(@DesktopDir, "*.lnk", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", @DesktopWidth, 20, 0, 0, $WS_POPUP, 0)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
For $i = 1 To $failidritta[0]
    $kiirteed = GUICtrlCreateMenuItem($failidritta[$i], $MenuItem2)
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
                For $n = 1 To UBound($kiirteed) - 1
                If $nMsg = $kiirteed[$n] Then
                    ShellExecute(@DesktopDir & "\" & $failidritta[$n])
                    ExitLoop
                EndIf
            Next
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

$kiirteed is not an array (Which I think is what you need). It's a normal variable. Declare $kiirteed as a variable with the same amount of subscripts as $failidritta, then do something like this untested code:

$kiirteed[0] = $failidritta[0]
For $i = 1 To $failidritta[0]-1
    $kiirteed[$i] = GUICtrlCreateMenuItem($failidritta[$i], $MenuItem2)
Next

Then you can reference each menu item by the subscript.

EDIT: This works:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $failidritta = _FileListToArray(@DesktopDir, "*.lnk", 1)
Global $kiirteed[$failidritta[0]]
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", @DesktopWidth, 20, 0, 0, $WS_POPUP, 0)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
For $i = 1 To $failidritta[0] -1
    $kiirteed[$i] = GUICtrlCreateMenuItem($failidritta[$i], $MenuItem2)
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
                For $n = 1 To UBound($kiirteed) - 1
                If $nMsg = $kiirteed[$n] Then
                    ShellExecute(@DesktopDir & "\" & $failidritta[$n])
                    ExitLoop
                EndIf
            Next
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by KentonBomb
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...