Sign in to follow this  
Followers 0
au3scr

dynamic menu object clicking

3 posts in this topic

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

Share this post


Link to post
Share on other sites



I am trying to explain it in better way: I need on click action for "$kiirteed" elements.


Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$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

Share this post


Link to post
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
Sign in to follow this  
Followers 0