Sign in to follow this  
Followers 0
D4rk^S0ul

Help with clickable list

11 posts in this topic

What i have so far is:

#include <GuiConstants.au3>

GuiCreate("ShortCuts", 121, 179,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$List = GuiCtrlCreateList("", 10, 30, 100, 110)
$Label_2 = GuiCtrlCreateLabel("Shortcuts:", 10, 10, 80, 20)
$Button_Add = GuiCtrlCreateButton("Add", 10, 150, 40, 20)
$Button_Delete = GuiCtrlCreateButton("Clear", 70, 150, 40, 20)

GuiSetState()

$Add = GuiCreate("Add:", 376, 91,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_Name = GuiCtrlCreateInput("", 10, 30, 110, 20)
$Label_2 = GuiCtrlCreateLabel("Shortcut Name:", 10, 10, 80, 20)
$Input_Location = GuiCtrlCreateInput("", 140, 30, 160, 20)
$Label_4 = GuiCtrlCreateLabel("Location:", 140, 10, 70, 20)
$Button_Browse = GuiCtrlCreateButton("Browse", 310, 30, 50, 20)
$Button_OK = GuiCtrlCreateButton("OK", 10, 60, 40, 20)
$Button_Cancel = GuiCtrlCreateButton("Cancel", 70, 60, 60, 20)

GuiSetState(@SW_HIDE)


While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_Add
        GUISetState(@SW_SHOW, $Add)
    Case $msg = $Button_Cancel
        GUISetState(@SW_HIDE, $Add)
    Case $msg = $Button_Browse
        $Browse = FileOpenDialog("Browse", @MyDocumentsDir, "All(*.*)", 1)
        GUICtrlSetData($Input_Location, $Browse)
    Case $msg = $Button_OK
        If GUICtrlRead($Input_Name) = "" Then
            MsgBox(0, "Enter a Name!", "Please enter a name!")
        Else
            $Name = GUICtrlRead($Input_Name)
            GUICtrlSetData($List, $Name)
            GUISetState(@SW_HIDE, $Add)
        EndIf
    Case $msg = $Button_Delete
        GUICtrlSetData($List, "")
    EndSelect
WEnd
Exit

Is there any way to make it so if u click the list it will exicute the shortcut?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Case $msg = $List

$info = GUICtrlRead($List)

Run($Info)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Only 1 prob the list doesnt hold the location only the name of the shortcut is there anyway to put the location in without it being visible and be able to run it when the name is ran, or would i have to add a array of name and compare the name to the locations name?

Share this post


Link to post
Share on other sites

Only 1 prob the list doesnt hold the location only the name of the shortcut is there anyway to put the location in without it being visible and be able to run it when the name is ran, or would i have to add a array of name and compare the name to the locations name?

I'd probably go with the method of running a Select Case on Valuater's $info variable.

Cheers,

Def

Share this post


Link to post
Share on other sites

Yes but like i said the list on holds the name of the shortcut not the location.

Share this post


Link to post
Share on other sites

Try

Case $msg = $List
$info = GUICtrlRead($List)
$prog = FileGetShortcut($info)
Run($prog)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Try

Case $msg = $List
$info = GUICtrlRead($List)
$prog = FileGetShortcut($info)
Run($prog)

thats the right idea...

but if the the message is from the list

read the variable that has the shortcut in it

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try

Case $msg = $List
$info = GUICtrlRead($List)
$prog = FileGetShortcut($info)
Run($prog)
If he has the shortcut already... wouldn't it be something like:

Case $msg = $List
    $info = FileGetLongName(GUICtrlRead($List))
    Run($info)
?

Edit:

Actually, I just read it quickly, I still have no idea what the creator of the script is trying to accomplish?

Edit2:

Ok, after running the GUI I get the idea... are you planning on using an .ini or a .dat file to store the variables?

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Exactly - Once you have returned the shortcut name via $info = GUICtrlRead($List), then run value through a Select Case.

Case $info = xxxx Run(xxxx)

Case $info = yyyy Run(yyyy)

Share this post


Link to post
Share on other sites

Is this what you had in mind?

#include <GuiConstants.au3>
#include <FILE.AU3>

Global Const $WM_COMMAND = 0x0111
Global Const $LBN_SELCHANGE = 1
Global Const $LBN_DBLCLK = 2
Global $ShortCutSection = 'ShortCutName', $IniLocation = @ScriptDir & '\ShortCutStore.ini'
If Not FileExists($IniLocation) Then
    _FileCreate($IniLocation)
    FileWriteLine($IniLocation, '[ShortCutName]')
EndIf
Local $SecValue = _SectionValue()

$MAINGUI = GuiCreate("ShortCuts", 121, 179,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$List = GuiCtrlCreateList("", 10, 30, 100, 110)
$Label_2 = GuiCtrlCreateLabel("Shortcuts:", 10, 10, 80, 20)
$Button_Add = GuiCtrlCreateButton("Add", 10, 150, 40, 20)
$Button_Delete = GuiCtrlCreateButton("Clear", 70, 150, 40, 20)

If $SecValue <> '' Then GUICtrlSetData($List, $SecValue)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_Add
            GUISetState(@SW_DISABLE, $MAINGUI)
            _Add_To_GUI()
            GUISetState(@SW_ENABLE, $MAINGUI)
            If Not WinActive($MAINGUI) Then WinActivate($MAINGUI)
        Case $msg = $Button_Delete
                $RemoveShortCutInfo = IniReadSection($IniLocation, $ShortCutSection)
                For $x = 1 To $RemoveShortCutInfo[0][0]
                    If $RemoveShortCutInfo[$x][1] = GUICtrlRead($List) Then
                        Remove_Shortcut($RemoveShortCutInfo[$x][0] & '=' & $RemoveShortCutInfo[$x][1])
                        ExitLoop
                    EndIf
                Next
                $SecValue = _SectionValue()
                MsgBox(0, '', $SecValue)
                If $SecValue <> '' Then
                    GUICtrlSetData($List, '')
                    GUICtrlSetData($List, $SecValue)
                Else
                    GUICtrlSetData($List, '')
                EndIf
        Case _IsPressed('0D') And ControlGetFocus($MAINGUI) = 'ListBox1'
            TakeAction()
            Sleep(200)
    EndSelect
WEnd

Func _Add_To_GUI()
    $Add_GUI = GuiCreate("Add:", 376, 91,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    $Input_Name = GuiCtrlCreateInput("", 10, 30, 110, 20)
    $Label_2 = GuiCtrlCreateLabel("Shortcut Name:", 10, 10, 80, 20)
    $Input_Location = GuiCtrlCreateInput("", 140, 30, 160, 20)
    $Label_4 = GuiCtrlCreateLabel("Location:", 140, 10, 70, 20)
    $Button_Browse = GuiCtrlCreateButton("Browse", 310, 30, 50, 20)
    $Button_OK = GuiCtrlCreateButton("OK", 10, 60, 40, 20)
    $Button_Cancel = GuiCtrlCreateButton("Cancel", 70, 60, 60, 20)

    GuiSetState()
    While 1
        $ADD_MSG = GUIGetMsg()
        Select
            Case $ADD_MSG = $GUI_EVENT_CLOSE Or $ADD_MSG = $Button_Cancel
                ExitLoop
            Case $ADD_MSG = $Button_Browse
                $Browse = FileOpenDialog("Browse", @HomeDrive, "All(*.*)", 1)
                GUICtrlSetData($Input_Location, FileGetShortName($Browse))
            Case $ADD_MSG = $Button_OK
                If GUICtrlRead($Input_Name) = "" Or GUICtrlRead($Input_Location) = '' Then
                    MsgBox(64, "Error", "Please enter a name of the shortcut or the location of the file you wish to make a shortcut of!")
                Else
                    IniWrite($IniLocation, $ShortCutSection, GUICtrlRead($Input_Location), GUICtrlRead($Input_Name))
                    GUICtrlSetData($List, GUICtrlRead($Input_Name))
                    ExitLoop
                EndIf
        EndSelect
    WEnd
    GUIDelete($ADD_GUI)
EndFunc

Func Remove_Shortcut($RemoveShortCut)
    Local $nArray = ''
    Local $TempPath = @TempDir & '\TempShortCutInfo.txt'
    _FileReadToArray($IniLocation, $nArray)
    For $i = 1 To UBound($nArray) - 1
        If Not StringInStr($nArray[$i], $RemoveShortCut) And $nArray[$i] <> '' Then FileWriteLine($TempPath, $nArray[$i])
    Next
    Do
        FileDelete($IniLocation)
    Until Not FileExists($IniLocation)
    FileMove($TempPath, $IniLocation, 1)
    Do
        Sleep(10)
    Until FileExists($IniLocation)
    Do
        FileDelete($TempPath)
    Until Not FileExists($TempPath)
EndFunc
            
Func _SectionKey()
    Local $sArray = IniReadSection($IniLocation, $ShortCutSection)
    If Not @error Then 
        Local $ReturnArray = ''
        For $i = 1 To $sArray[0][0]
            If $sArray[$i][0] <> '' Then $ReturnArray = $ReturnArray & $sArray[$i][0] & '|'
        Next
        Return StringTrimRight($ReturnArray, 1)
    EndIf
EndFunc

Func _SectionValue()
    Local $sArray = IniReadSection($IniLocation, $ShortCutSection)
    If Not @error Then 
        Local $ReturnArray = ''
        For $i = 1 To $sArray[0][0]
            If $sArray[$i][0] <> '' Then $ReturnArray = $ReturnArray & $sArray[$i][1] & '|'
        Next
        Return StringTrimRight($ReturnArray, 1)
    EndIf
EndFunc

Func TakeAction()
    Local $IniReadSection = IniReadSection($IniLocation, $ShortCutSection)
    If Not @error Then
        For $i = 1 To $IniReadSection[0][0]
            If GUICtrlRead($List) = $IniReadSection[$i][1] Then 
                Run($IniReadSection[$i][0])
                ExitLoop
            EndIf
        Next
    EndIf
EndFunc

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    $hCtrl        = $lParam
    If $nID = $List Then
        Switch $nNotifyCode                 
        Case $LBN_DBLCLK
            TakeAction()
            Return 0
        EndSwitch
    EndIf
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc
NOTE***Needs Beta!!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

nice job smoke

8)


NEWHeader1.png

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