Jump to content

User to Attach a file to a button in GUI


AJJ
 Share

Recommended Posts

yeah thats cool then, my script is in that place!

ok wicked, well thats definitly all working and good, the thing i was saying before with having more than one is that, during the drama each scene will have different noisees to it and some of them might be used more than once, others wont so i was going to create about 9 different play, stop, attach modules to put together in a gui so that depending on what is happening you can play different sound effects, quickly and repeatedly if nessecary. i was wondering what i had to copy to make another one, and another and so on. it will be more than just making new buttons in the gui right?

Link to comment
Share on other sites

  • Moderators

AJJ,

Here is a 3 module script. You need to declare the additional variables, create additional buttons/combos in the GUI, add additional Cases to the GUIGetMsg loop to catch them, and add additional cases to the GUIRegisterMsg function to autocomplete them. But now you have this model, you should be able to add the others easily.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <Sound.au3>
#include <File.au3>
#include <RecFileListToArray.au3>

Global $sToPlay1 = "", $sToPlay2 = "", $sToPlay3 = ""  ;<<<<<<<<<<< Declare additional variables

$sFolder = @ScriptDir & "\" ; You said your script is in the same folder as your sound files

$asSounds = _RecFileListToArray($sFolder, "*.mp3;*.wma;*.wav", 1, 1)
$sSound_Data = ""
For $i = 1 To $asSounds[0]
    $sSound_Data &= $asSounds[$i] & "|"
Next

; Create GUI
$hGUI = GUICreate("Test", 700, 500)

$hPlay1 = GUICtrlCreateButton("Play 1", 10, 10, 80, 30)
$hStop1 = GUICtrlCreateButton("Stop 1", 10, 50, 80, 30)
$hChoose1 = GUICtrlCreateCombo("", 10, 110, 200, 20)
GUICtrlSetData(-1, $sSound_Data)

$hPlay2 = GUICtrlCreateButton("Play 2", 250, 10, 80, 30) ;<<<<<<<<<<<  Add Additional buttons/combos
$hStop2 = GUICtrlCreateButton("Stop 2", 250, 50, 80, 30)
$hChoose2 = GUICtrlCreateCombo("", 250, 110, 200, 20)
GUICtrlSetData(-1, $sSound_Data)

$hPlay3 = GUICtrlCreateButton("Play 3", 490, 10, 80, 30)
$hStop3 = GUICtrlCreateButton("Stop 3", 490, 50, 80, 30)
$hChoose3 = GUICtrlCreateCombo("", 490, 110, 200, 20)
GUICtrlSetData(-1, $sSound_Data)                         ;<<<<<<<<<<< 

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hPlay1
            If GUICtrlRead($hChoose1) <> "" Then
                $sToPlay1 = $sFolder & GUICtrlRead($hChoose1)
                SoundPlay($sToPlay1)
            EndIf
        Case $hStop1
            If $sToPlay1 <> "" Then SoundPlay("")

        Case $hPlay2                                     ;<<<<<<<<<<< Add additional Cases to catch the buttons 
            If GUICtrlRead($hChoose2) <> "" Then
                $sToPlay2 = $sFolder & GUICtrlRead($hChoose2)
                SoundPlay($sToPlay2)
            EndIf
        Case $hStop2
            If $sToPlay2 <> "" Then SoundPlay("")

        Case $hPlay3
            If GUICtrlRead($hChoose3) <> "" Then
                $sToPlay3 = $sFolder & GUICtrlRead($hChoose3)
                SoundPlay($sToPlay3)
            EndIf
        Case $hStop3
            If $sToPlay3 <> "" Then SoundPlay("")        ;<<<<<<<<<<< 
    EndSwitch

WEnd

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0x0000FFFF)
    Local $iCode = BitShift($wParam, 16)

    Switch $iIDFrom
        Case $hChoose1
            Switch $iCode
                Case $CBN_EDITCHANGE
                    _GUICtrlComboBox_AutoComplete($hChoose1)
            EndSwitch
        Case $hChoose2                                   ;<<<<<<<<<<< Add additional Cases for the Combo autocomplete
            Switch $iCode
                Case $CBN_EDITCHANGE
                    _GUICtrlComboBox_AutoComplete($hChoose2)
            EndSwitch
        Case $hChoose3
            Switch $iCode
                Case $CBN_EDITCHANGE
                    _GUICtrlComboBox_AutoComplete($hChoose3)
            EndSwitch                                    ;<<<<<<<<<<< 
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Glad we could get you up and running. Do ask again if you run into any problems with the additional modules.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

awesome, this is just what i need i think, we are nearly there, so is this just a matter of copying and pasting the case and changing places where it says 3 to 4 and so on, (also copying the buttons)

Link to comment
Share on other sites

  • Moderators

AJJ,

Copy and paste with number changing works well - that is exactly how I did it for the example! Just remember to adjust the positions of the new controls in the GUI - otherwise you will just overwrite the previous controls.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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