Jump to content

Dynamic menu


Recommended Posts

Why it dont dont run the *.exe program when i click on it?

#include <guiconstants.au3>
#include <File.au3>
#include <String.au3>
#include <GuiEdit.au3>



GUICreate("dynamic",640,480) 
$MenuItem0 = GUICtrlCreateMenu("Programs")

Dim $sourceFolder = @ScriptDir

 $Array = _FileListToArray($sourceFolder, "*.exe", 1)
For $i=1 To $Array[0]
 $MenuItem01 = GUICtrlCreateMenuItem($Array[$i], $MenuItem0)
Next
GUISetState (@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem01
            Run(@ScriptDir&"\"&$Array[$i])
    EndSwitch
Wend
Link to comment
Share on other sites

  • Developers

Have you check what you are trying to run? just add a debug statement to check what the script is trying to do, in that way you learn to debug the problems yourself!

This will be wrong: $Array[$i], because $i will not contain the correct value.

You need to read the correct Control.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This works better with EventMode, but if you must use a message loop, it will have to loop through the menu items:

#include <guiconstants.au3>

Global $Array = StringSplit("Test 1,Test 2,Test 3", ",")
Global $avMenuItems[ $Array[0] + 1 ]

GUICreate("dynamic", 640, 480)
$avMenuItems[0] = GUICtrlCreateMenu("Programs")
For $i = 1 To $Array[0]
    $avMenuItems[$i] = GUICtrlCreateMenuItem($Array[$i], $avMenuItems[0])
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    For $n = 1 To UBound($avMenuItems) - 1
        If $nMsg = $avMenuItems[$n] Then 
            MsgBox(64, "Run", "Run item: " & $Array[$n])
            ExitLoop
        EndIf
    Next
WEnd

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Have you check what you are trying to run? just add a debug statement to check what the script is trying to do, in that way you learn to debug the problems yourself!

This will be wrong: $Array[$i], because $i will not contain the correct value.

You need to read the correct Control.

What contains correct value then??
Link to comment
Share on other sites

Sorry, i am dump at dynamic items,I mixed what i needet and i took parts from this forum

This is the code what for i was looking more than 1 month.

=========================

===Sorry=for=my= bad=english===

=========================

#include <guiconstants.au3>

#include <File.au3>

#include <String.au3>

#include <GuiEdit.au3>

#include <guiconstants.au3>

Dim $sourceFolder = @DesktopDir

Global $Array = _FileListToArray($sourceFolder, "*.exe", 1)

Global $avMenuItems[ $Array[0] + 1 ]

GUICreate("dynamic", 640, 480)

$avMenuItems[0] = GUICtrlCreateMenu("Programs")

For $i = 1 To $Array[0]

$avMenuItems[$i] = GUICtrlCreateMenuItem($Array[$i], $avMenuItems[0])

Next

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

If $nMsg = $GUI_EVENT_CLOSE Then Exit

For $n = 1 To UBound($avMenuItems) - 1

If $nMsg = $avMenuItems[$n] Then

MsgBox(64, "Run", "Run item: " & $Array[$n])

Run($sourceFolder&"\"&$Array[$n])

ExitLoop

EndIf

Next

WEnd

Link to comment
Share on other sites

New problem i ported that source in my script, And in my script this source dont work

;~ Opt("OnExitFunc", "endscript")
HotKeySet("!{f4}", "noexit")
;~ AutoItSetOption("GUICloseOnESC", 0)
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <String.au3>
#include <GuiEdit.au3>

$read = FileReadLine (@ScriptDir&"\path",1)
$decrypted = _StringEncrypt(0,$read,"keerulinesalas6na",1)
$configfilepath = $decrypted
$fileget = FileExists($configfilepath)
If $fileget = 0 Then
    Defaults()
EndIf



$def = FileReadLine($configfilepath, 1)
If $def = "Rebindall" Then
    Defaults()
EndIf


Global $pass = FileReadLine($configfilepath, 1)
Global $pass2 = FileReadLine($configfilepath, 22)
Global $background = "Z:\My Documents\66.jpg"
Dim $sourceFolder = @DesktopDir
Global  $Array = _FileListToArray($sourceFolder, "*.exe", 1)
Global $avMenuItems[ $Array[0] + 1 ]
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("FluxBox", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
$taskbarbtn = GUICtrlCreateButton("<", @DesktopWidth - 10, @DesktopHeight / 2, 10, 30)
GUICtrlSetColor(-1, 0x0000ff)
GUICtrlSetFont(-1, 16, 500, 1, "terminal")
GUICtrlSetBkColor(-1, 0xFFFFE1)
GUISetBkColor(0x3A6EA5)

$avMenuItems[0] = GUICtrlCreateMenu("Programs")
For $i = 1 To $Array[0]
    $avMenuItems[$i] = GUICtrlCreateMenuItem($Array[$i], $avMenuItems[0])
Next
$MenuItem1 = GUICtrlCreateMenu("Exit")
$MenuItem11 = GUICtrlCreateMenuItem("exit", $MenuItem1)
$MenuItem12 = GUICtrlCreateMenuItem("Shutdown", $MenuItem1)
$MenuItem13 = GUICtrlCreateMenuItem("Restart", $MenuItem1)
$MenuItem14 = GUICtrlCreateMenuItem("Log Off", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Help")
$MenuItem20 = GUICtrlCreateMenuItem("About", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenu("Administration")
$MenuItem30 = GUICtrlCreateMenuItem("Wallpaper", $MenuItem3)
$MenuItem31 = GUICtrlCreateMenuItem("Taskmanager", $MenuItem3)
$MenuItem32 = GUICtrlCreateMenuItem("Run", $MenuItem3)
$MenuItem33 = GUICtrlCreateMenuItem("CMD", $MenuItem3)
$MenuItem34 = GUICtrlCreateMenuItem("Control", $MenuItem3)
Global $Pic = GUICtrlCreatePic($background, 0, 0, @DesktopWidth, @DesktopHeight - 15, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlCreateLabel(@YEAR & ":" & @MON & ":" & @MDAY, @DesktopWidth - 150, @DesktopHeight - 55, 150, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$time = GUICtrlCreateLabel(@HOUR & ":" & @MIN & ":" & @SEC, @DesktopWidth - 150, @DesktopHeight - 40, 150, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
AdlibEnable("Time", 1000)
;~ noexp()
;~ nodm()
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem11
            endscript()
Exit
    For $n = 1 To UBound($avMenuItems) - 1
        If $nMsg = $avMenuItems[$n] Then
            MsgBox(64, "Run", "Run item: " & $Array[$n])
            Run($sourceFolder&"\"&$Array[$n])
            ExitLoop
        EndIf
    Next
        Case $MenuItem12
            Shutdown(1)
        Case $MenuItem13
            Shutdown(2)
        Case $MenuItem14
            Shutdown(0)
        Case $MenuItem20
            MsgBox(64, "Version 1.02", "Version 1.02 !" & @CRLF & "Author: rain" & @CRLF & "Relased 23 feb 2008" & @CRLF & "Default settings:" & @CRLF & "All parameters are turned OFF" & @CRLF & " " & @CRLF & "Try hack it" & @CRLF & " " & @CRLF & "History" & @CRLF & "Version 0.97 - help added" & @CRLF & "Version 0.99 - Esc exit bub fixed" & @CRLF & " Able to use wallpaper"& @CRLF & "Version 1.00 CMD added" & @CRLF & " Control added" & @CRLF & " Taskbar added" & @CRLF & " Version 1.01 taskmanager disabled " & @CRLF & " Version 1.02 Extended security")
        Case $MenuItem30
            wallpaperset()
        Case $MenuItem31
            taskman()
        Case $MenuItem32
            runother()
            Case $MenuItem33
            cmd()
            Case $MenuItem34
            control()
        Case $taskbarbtn
            $load = FileReadLine($configfilepath, 24)
            Run($load)
    EndSwitch
WEnd

Func endscript()
    $Password = InputBox("Enter Password", "You must enter password to close this window", "", "*")
    If $Password = $pass Then
;~ If $Password = "toor" Then
        ProcessClose("sticky.exe")
        ProcessClose("taskmgr.exe")
        ProcessClose("DisableTaskManager.exe")
        Run("explorer")
        ProcessClose("flux.exe")
        Exit
    Else
    EndIf
EndFunc   ;==>endscript


Func noexp()
    $noexp = FileReadLine($configfilepath, 3)
    If $noexp = "Yes" Then
        $pid = ProcessExists("explorer.exe")
        $handle = _WinAPI_OpenProcess(0x1, 0, $pid)
        DllCall("kernel32.dll", "int", "TerminateProcess", "int", $handle, "int", 1)
    EndIf
EndFunc   ;==>noexp

Func nodm()
    $noexp = FileReadLine($configfilepath, 4)
    If $noexp = "Yes" Then
;~   GUICtrlSetData ($l2,"Disable Task Mannager: ON")
        Run("DisableTaskManager.exe")
    EndIf
EndFunc   ;==>nodm

Func wallpaperset()
    $wallpaperallowordeny = FileReadLine($configfilepath, 17)
    If $wallpaperallowordeny = "Wallpapers=YES" Then
        $path = FileOpenDialog("Select wallpaper:", "", "(*.*)")
        If Not @error Then GUICtrlSetImage($Pic, $path)
        If $wallpaperallowordeny = "Wallpapers=NO" Then
            MsgBox(64, "Not allowed", "You do not have permission")
        EndIf
    EndIf
EndFunc   ;==>wallpaperset

Func taskman()
    $Password = InputBox("Enter Password", "You must enter password to close this window", "", "*")
;~ If $Password = $pass Then
    If $Password = $pass2 Then
        ProcessClose("DisableTaskManager.exe")
        ProcessClose("taskmgr.exe")
        Run(@SystemDir & "\taskmgr.exe")
    Else
    EndIf
EndFunc   ;==>taskman

Func runother()
    $Password = InputBox("Enter Password", "You must enter password to close this window", "", "*")
;~ If $Password = $pass Then
    If $Password = $pass2 Then
            $load = FileReadLine($configfilepath, 23)
            Run($load)
    Else
    EndIf
EndFunc   ;==>runother

Func cmd()
    $Password = InputBox("Enter Password", "You must enter password to close this window", "", "*")
;~ If $Password = $pass Then
    If $Password = $pass2 Then
            run(@SystemDir & "\cmd.exe")
    Else
    EndIf
EndFunc

Func control()
    $Password = InputBox("Enter Password", "You must enter password to close this window", "", "*")
;~ If $Password = $pass Then
    If $Password = $pass2 Then
            Run("control")
    Else
    EndIf
EndFunc

Func n()
    Sleep(100)
    MsgBox(1, "t", "p")
EndFunc   ;==>n

Func time()
    $newtime = @HOUR & ":" & @MIN & ":" & @SEC
    GUICtrlSetData($time, $newtime)
EndFunc   ;==>time

Func Defaults($iDelay = 0)
    Local $sCmdFile
    FileDelete($configfilepath)
    $sCmdFile = 'toor' & @CRLF _
             & 'NO' & @CRLF _
             & 'YES' & @CRLF _
             & 'YES' & @CRLF _
             & 'C:\Program Files\Mozilla Firefox\firefox.exe' & @CRLF _
             & 'Notepad' & @CRLF _
             & @ProgramFilesDir & '\7-Zip\7zFM.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\swriter.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\smath.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\simpress.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\sdraw.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\scalc.exe' & @CRLF _
             & @ProgramFilesDir & '\OpenOffice.org 2.3\program\sbase.exe' & @CRLF _
             & @ProgramFilesDir & '\Notepad++\notepad++.exe' & @CRLF _
             & 'Word' & @CRLF _
             & 'Excel' & @CRLF _
             & 'Wallpapers=YES' & @CRLF _
             & @ProgramFilesDir & '\IrfanView\i_view32.exe' & @CRLF _
             & @ProgramFilesDir & '\GIMP-2.0\bin\gimp-2.4.exe' & @CRLF _
             & @SystemDir & '\mspaint.exe' & @CRLF _
             & @ProgramFilesDir & '\VideoLAN\VLC\vlc.exe' & @CRLF _
             & 'root' & @CRLF _
             & @ScriptDir &'\run.exe' & @CRLF _
             & @scriptDir &'\taskbar.exe'
    FileWrite($configfilepath, $sCmdFile)
EndFunc   ;==>Defaults

Func noexit()
EndFunc   ;==>noexit
Link to comment
Share on other sites

What specific part of your script isn't working?

Does the list get populated properly or not?

If it does, does it not work when you click on an item?

Bob

EDIT:

Pull your For Next loop outside your Switch statment:

While 1
    $nMsg = GUIGetMsg()
    
        For $n = 1 To UBound($avMenuItems) - 1
        If $nMsg = $avMenuItems[$n] Then
            MsgBox(64, "Run", "Run item: " & $Array[$n])
            Run($sourceFolder&"\"&$Array[$n])
            ExitLoop
        EndIf
        Next
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem11
;........
Edited by YellowLab

You can't see a rainbow without first experiencing the rain.

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...