Jump to content

Buttons - GUICtrlSetOnEvent x20


 Share

Recommended Posts

Hi, got this code that gets called when the correspondent button is clicked.

Wondering if there's a way to shorten this up, as right now i have 20 of these,

GUICtrlCreateButton("...", $FS1X, $FS1Y, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile1")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
GUICtrlCreateButton("...", $FS1X, $FS1Y + 30, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile2")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
GUICtrlCreateButton("...", $FS1X, $FS1Y + 60, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile3")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)


Func SelectFile1()
    $FileDlgApp = FileOpenDialog('Select File', @DesktopDir, "All (*.*)")
    If Not @error Then
        IniWrite($Ini, "abc", "AppStr1", $FileDlgApp)
        GUICtrlSetData($UserAppStr[1], $FileDlgApp)
    EndIf
EndFunc   ;==>SelectFile1
;=============================================================================
Func SelectFile2()
    $FileDlgApp = FileOpenDialog('Select File', @DesktopDir, "All (*.*)")
    If Not @error Then
        IniWrite($Ini, "abc", "AppStr2", $FileDlgApp)
        GUICtrlSetData($UserAppStr[2], $FileDlgApp)
    EndIf
EndFunc   ;==>SelectFile2
;=============================================================================
Func SelectFile3()
    $FileDlgApp = FileOpenDialog('Select File', @DesktopDir, "All (*.*)")
    If Not @error Then
        IniWrite($Ini, "abc", "AppStr3", $FileDlgApp)
        GUICtrlSetData($UserAppStr[3], $FileDlgApp)
    EndIf
EndFunc   ;==>SelectFile3

Thanks

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

I would do something like this (tailor as necessary)

$idBtnSelect1 = GUICtrlCreateButton("...", $FS1X, $FS1Y, 20, 22)
GUICtrlSetOnEvent(-1, "SelectButtonEvent")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
$idBtnSelect2 = GUICtrlCreateButton("...", $FS1X, $FS1Y + 30, 20, 22)
GUICtrlSetOnEvent(-1, "SelectButtonEvent")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
$idBtnSelect3 = GUICtrlCreateButton("...", $FS1X, $FS1Y + 60, 20, 22)
GUICtrlSetOnEvent(-1, "SelectButtonEvent")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)


Func SelectButtonEvent()
    Switch @GUI_CtrlId
        Case $idBtnSelect1
            SelectFile(1)
        Case $idBtnSelect2
            SelectFile(2)
        Case $idBtnSelect3
            SelectFile(3)
    EndSwitch
EndFunc

Func SelectFile($iKey)
    $FileDlgApp = FileOpenDialog('Select File', @DesktopDir, "All (*.*)")
    If Not @error Then
        IniWrite($Ini, "abc", "AppStr" & $iKey, $FileDlgApp)
        GUICtrlSetData($UserAppStr[$iKey], $FileDlgApp)
    EndIf
EndFunc

 

Link to comment
Share on other sites

Looks like a good idea.

thank you.

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

End result for 20 buttons if anyone cares.

Did some changes but i used the base principle. thanks.

$SelBut[1] = GUICtrlCreateButton("...", $FS1X, $FS1Y, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
$SelBut[2] = GUICtrlCreateButton("...", $FS1X, $FS1Y + 30, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)
$SelBut[3] = GUICtrlCreateButton("...", $FS1X, $FS1Y + 60, 20, 22)
GUICtrlSetOnEvent(-1, "SelectFile")
GUICtrlSetTip(-1, $Tip3, "FileSelect", 1)

Func SelectFile()
    Local $f = 1
    For $f = 1 To 20
        If @GUI_CtrlId = $SelBut[$f] Then
            $FileDlgApp = FileOpenDialog('Select File', @DesktopDir, "All (*.*)")
            If Not @error Then
                IniWrite($Ini, "Triggers", "AppStr" & $f, $FileDlgApp)
                GUICtrlSetData($UserAppStr[$f], $FileDlgApp)
            EndIf
        EndIf
    Next
EndFunc   ;==>SelectFile

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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