Hintergrundbild von GUI ändern und bei Programmneustart wieder anzeigen.

  • Hi ich habe mal ein Programm geschrieben, in dem ich will das man während es läuft, das Hintergrundbild der GUI ändern kann und das es nach einem Programmneustart trotzdem wieder das ausgewählte erscheint. Das mit .Ini habe ich leider net selber geschafft. Hier der wichtige Teil des Scripts:

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=Icon.ico
    #AutoIt3Wrapper_outfile=..\Desktop\BlackEyes StreamPlayer\BlackEyes StreamPlayer.exe
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_UseX64=n
    #AutoIt3Wrapper_Res_Fileversion=1.3.1.12
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
    #AutoIt3Wrapper_Res_Language=1031
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <StructureConstants.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ProgressConstants.au3>
    #include <Security.au3>
    #include <Memory.au3>
    #include <UDFGlobalID.au3>
    #include <GuiStatusBar.au3>
    #include <GUIEdit.au3>
    #include-once
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <Constants.au3>
    #include <GUIEdit.au3>
    #include <GuiToolbar.au3>
    #include <inet.au3>
    #include <array.au3>
    #include <ie.au3>

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister("CheckMouse")

    [/autoit] [autoit][/autoit] [autoit]

    $oWMP = ObjCreate("WMPLayer.ocx")
    $GUI = GUICreate("BlackEyes Stream Player", 498, 357, 238, 172)
    $Pic1 = GUICtrlCreatePic(@ScriptDir & "\Styles\BlackEyes.jpg", 0, 0, 497, 353, BitOR($WS_GROUP,$WS_CLIPSIBLINGS))
    $HauptMenu = GUICtrlCreateMenu("Datei")
    $HMenuE = GUICtrlCreateMenuItem("Beenden",$HauptMenu)
    $SMenu = GUICtrlCreateMenu("Stream URLs")
    $SMenu1 = GUICtrlCreateMenuItem("TechnoBase.FM",$SMenu)
    $SMenu2 = GUICtrlCreateMenuItem("Top100Station",$SMenu)
    $SMenu3 = GUICtrlCreateMenuItem("Planet Radio",$SMenu)
    $SMenu4 = GUICtrlCreateMenuItem("YouFM",$SMenu)
    $SMenu5 = GUICtrlCreateMenuItem("BigFM",$SMenu)
    $SMenu6 = GUICtrlCreateMenuItem("Rautemusik.fm Main",$SMenu)
    $SMenu7 = GUICtrlCreateMenuItem("1Live",$SMenu)
    $StyleM = GUICtrlCreateMenu("Styles")
    $Style1 = GUICtrlCreateMenuItem("BlackEyes",$StyleM)
    $Style2 = GUICtrlCreateMenuItem("Standard",$StyleM)
    $Menu = GUICtrlCreateMenu("Hilfe")
    $MenuE = GUICtrlCreateMenuItem("About",$Menu)
    $Combo1 = GUICtrlCreateCombo("Bitte auswählen", 144, 112, 209, 25)
    GUICtrlSetData(-1,"TechnoBase.FM|Top100Station|Planet Radio|YouFM|BigFM|Rautemusik.fm Main|1Live","Bitte auswählen")
    $Label1 = GUICtrlCreateLabel("Radio Streams", 144, 88, 94, 20)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    $Button1 = GUICtrlCreateButton("Play", 24, 304, 193, 33, $WS_GROUP)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Button2 = GUICtrlCreateButton("Stop", 280, 304, 193, 33, $WS_GROUP)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetState($Button2, $GUI_DISABLE)
    $Progress1 = GUICtrlCreateProgress(8, 30, 33, 265, $PBS_VERTICAL)
    GUICtrlSetBkColor($Progress1,0x1000)
    $Volume = GUICtrlCreateSlider(448, 30, 33, 265, BitOR($TBS_AUTOTICKS,$TBS_VERT))
    GUICtrlSetBkColor($Volume,000000)
    GUICtrlSetData(-1, $oWMP.settings.volume())
    GUICtrlSetState($Volume, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $oWMP.settings.volume = 100 - GUICtrlRead($Volume)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $HMenuE
    Exit
    Case $SMenu1
    MsgBox(0,"TechnoBase.FM","http://listen.technobase.fm/tunein-dsl-asx")
    Case $SMenu2
    MsgBox(0,"Top100Station","http://www.top100station.de/switch/r3472.asx")
    Case $SMenu3
    MsgBox(0,"Planet Radio","http://lsd.newmedia.nacamar.net/bb/redirect.lsc?stream=planetradio$livestream.mp3&content=live&media=mp3")
    Case $SMenu4
    MsgBox(0,"YouFM","http://metafiles.gl-systemhaus.de/hr/youfm_1.asx")
    Case $SMenu5
    MsgBox(0,"BigFM","http://217.151.152.245/bigfm-mp3-96")
    Case $SMenu6
    MsgBox(0,"Rautemusik.fm Main","http://main-high.rautemusik.fm/listen.asx")
    Case $SMenu7
    MsgBox(0,"1Live","http://www.wdr.de/wdrlive/media/einslive.asx")
    Case $MenuE
    MsgBox(0,"About BlackEyes StreamPlayer","BlackEyes StreamPlayer Version 1.3.1.12")
    Case $Button1
    $readcombo1 = GUICtrlRead($Combo1)
    $oWMP.controls.play()
    GUICtrlSetState($Volume, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_ENABLE)
    Switch $Button1
    Case $readcombo1 = "TechnoBase.FM"
    $oWMP.URL = 'http://listen.technobase.fm/tunein-dsl-asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Top100Station"
    $oWMP.URL = 'http://www.top100station.de/switch/r3472.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Planet Radio"
    $oWMP.URL = 'http://lsd.newmedia.nacamar.net/bb/redirect.lsc?stream=planetradio$livestream.mp3&content=live&media=mp3'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "YouFM"
    $oWMP.URL = 'http://metafiles.gl-systemhaus.de/hr/youfm_1.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "BigFM"
    $oWMP.URL = 'http://217.151.152.245/bigfm-mp3-96'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Rautemusik.fm Main"
    $oWMP.URL = 'http://main-high.rautemusik.fm/listen.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "1Live"
    $oWMP.URL = 'http://www.wdr.de/wdrlive/media/einslive.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Bitte auswählen"
    MsgBox(0,"ERROR","Kein Sender ausgewählt!")
    EndSwitch
    Case $Button2
    $oWMP.controls.stop()
    GUICtrlSetState($Volume, $GUI_DISABLE)
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_DISABLE)
    GUICtrlSetState($Combo1, $GUI_ENABLE)
    GUICtrlSetData($Progress1, 0)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func CheckMouse()
    Local Static $mouseout=0
    $aMpos = MouseGetPos()
    $aWpos = WinGetPos("BlackEyes Stream Player")
    If $aMpos[0] > $aWpos[0] And $aMpos[0] < $aWpos[0] + $aWpos[2] And $aMpos[1] > $aWpos[1] And $aMpos[1] < $aWpos[1] + $aWpos[3] Then
    If $mouseout = 1 Then
    For $i=30 to 255 Step 30
    WinSetTrans("BlackEyes Stream Player", "", $i)
    sleep(50)
    Next
    WinSetTrans("BlackEyes Stream Player", "", 255)
    $mouseout=0
    EndIf
    Else
    If $mouseout=0 Then
    For $i=255 to 30 Step -30
    WinSetTrans("BlackEyes Stream Player", "", $i)
    sleep(50)
    Next
    $mouseout=1
    EndIf
    EndIf
    EndFunc

    [/autoit]

    Am besten soll es sich ändern wenn man im Menü Styles auf den jeweiligen Style drückt.

    2 Mal editiert, zuletzt von Molaynox (6. Oktober 2010 um 15:42)

  • Hi,
    hab jetzt nicht dein Script durchgelesen aber hier mal mein Vorschlag wie man es mit ner INI-Datei lösen kann:

    [autoit][/autoit][autoit][/autoit][autoit]

    $BildName = IniRead( @ScriptDir & "\Ini-Datei.ini","Bilder","Hintergrundbild","Beispielbild.jpg")
    ;in der variable ist nun der Name des Bildes gespeichert

    [/autoit][autoit][/autoit][autoit]

    IniWrite(@ScriptDir & "\Ini-Datei.ini","Bilder","Hintergrundbild",$BildName)
    ;der Bildname aus der Variablen $Bildname wird in die INI-Datei gepeichert

    [/autoit]

    Ini-Datei.ini

    Code
    [Bilder]
    Hintergrundbild=MeinBildName.jpg

    Also ich würde jetzt den User nen Bild aus wählen lassen, und dann den Namen/Pfad vom Bild in der Ini speichern. Die Ini datei würde dann halt immer beim Programmstart ausgelesen und das jeweilige Bild würde benutzt werden.

    Hoffe du verstehst es wenn net dann frag!

    Jakolo

  • Noch ein Problem mit dem IniWrite. Wenn ich meinen kompilierten script mit dem Programm EasySetup oder Inno Setup in ein Setup mache dann funktioniert nach der Installation die IniWrite funktion anscheinend nicht mehr. Jedensfalls wird dann keine .ini erstellt. Ohne das Setup schon.
    Edit: IniWrite funktioniert nur einmal. Danach nicht mehr. auch nicht wenn man die .ini per hand löscht.
    Hier ist der Script:

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=Icon.ico
    #AutoIt3Wrapper_outfile=..\Desktop\BlackEyes StreamPlayer\BlackEyes StreamPlayer.exe
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_UseX64=n
    #AutoIt3Wrapper_Res_Fileversion=1.4.0.3
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
    #AutoIt3Wrapper_Res_Language=1031
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <StructureConstants.au3>
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ProgressConstants.au3>
    #include <GuiStatusBar.au3>
    #include <GUIEdit.au3>
    #include <File.au3>
    #include-once
    #include <Constants.au3>
    #include <GUIEdit.au3>
    #include <GuiToolbar.au3>
    #include <inet.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $INIstyle = @ScriptDir & "\Style.ini"
    Global $BlackEyes = @ScriptDir & "\Styles\BlackEyes.jpg"
    AdlibRegister("CheckMouse")

    [/autoit] [autoit][/autoit] [autoit]

    $Pic1 = IniRead($INIstyle,"Style","Background","")
    $oWMP = ObjCreate("WMPLayer.ocx")
    $GUI = GUICreate("BlackEyes Stream Player", 498, 357, 238, 172)
    GUICtrlCreatePic($Pic1, 0, 0, 497, 353, BitOR($WS_GROUP,$WS_CLIPSIBLINGS))
    $HauptMenu = GUICtrlCreateMenu("Datei")
    $KonifgDel = GUICtrlCreateMenuItem("Konfiguration löschen",$HauptMenu)
    $HMenuE = GUICtrlCreateMenuItem("Beenden",$HauptMenu)
    $SMenu = GUICtrlCreateMenu("Stream URLs")
    $SMenu1 = GUICtrlCreateMenuItem("TechnoBase.FM",$SMenu)
    $SMenu2 = GUICtrlCreateMenuItem("Top100Station",$SMenu)
    $SMenu3 = GUICtrlCreateMenuItem("Planet Radio",$SMenu)
    $SMenu4 = GUICtrlCreateMenuItem("YouFM",$SMenu)
    $SMenu5 = GUICtrlCreateMenuItem("BigFM",$SMenu)
    $SMenu6 = GUICtrlCreateMenuItem("Rautemusik.fm Main",$SMenu)
    $SMenu7 = GUICtrlCreateMenuItem("1Live",$SMenu)
    $StyleM = GUICtrlCreateMenu("Styles")
    $Style1 = GUICtrlCreateMenuItem("BlackEyes",$StyleM)
    $Style2 = GUICtrlCreateMenuItem("Standard",$StyleM)
    $StyleE = GUICtrlCreateMenuItem("Eigenes Bild",$StyleM)
    $Menu = GUICtrlCreateMenu("Hilfe")
    $MenuE = GUICtrlCreateMenuItem("About",$Menu)
    $Combo1 = GUICtrlCreateCombo("Bitte auswählen", 144, 112, 209, 25)
    GUICtrlSetData(-1,"TechnoBase.FM|Top100Station|Planet Radio|YouFM|BigFM|Rautemusik.fm Main|1Live","Bitte auswählen")
    $Label1 = GUICtrlCreateLabel("Radio Streams", 144, 88, 94, 20)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xff0000)
    $Button1 = GUICtrlCreateButton("Play", 24, 304, 193, 33, $WS_GROUP)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Button2 = GUICtrlCreateButton("Stop", 280, 304, 193, 33, $WS_GROUP)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetState($Button2, $GUI_DISABLE)
    $Progress1 = GUICtrlCreateProgress(8, 30, 33, 265, $PBS_VERTICAL)
    GUICtrlSetBkColor($Progress1,0x1000)
    $Volume = GUICtrlCreateSlider(448, 30, 33, 265, BitOR($TBS_AUTOTICKS,$TBS_VERT))
    $Slider = IniRead($INIstyle,"Slider","Slider","-2")
    GUICtrlSetBkColor($Volume, $Slider)
    GUICtrlSetData(-1, $oWMP.settings.volume())
    GUICtrlSetState($Volume, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $oWMP.settings.volume = 100 - GUICtrlRead($Volume)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $KonifgDel
    FileDelete(@ScriptDir & "\Style.ini")
    MsgBox(0,"Information","Änderung wirkt sich erst nach Programmneustart aus.")
    Case $Style1
    IniDelete($INIstyle,"Style","")
    IniWrite($INIstyle,"Style","Background",$BlackEyes)
    IniDelete($INIstyle,"Slider","")
    IniWrite($INIstyle,"Slider","Slider","000000")
    MsgBox(0,"Information","Änderung wirkt sich erst nach Programmneustart aus.")
    Case $Style2
    IniDelete($INIstyle,"Style","")
    IniDelete($INIstyle,"Slider","")
    IniWrite($INIstyle,"Slider","Slider","-2")
    MsgBox(0,"Information","Änderung wirkt sich erst nach Programmneustart aus.")
    Case $StyleE
    $open = FileOpenDialog("Bild",@DesktopDir,"Bilder (*.jpg)",1+4)
    IniDelete($INIstyle,"Style","")
    IniDelete($INIstyle,"Slider","")
    IniWrite($INIstyle,"Style","Background",$open)
    MsgBox(0,"Information","Änderung wirkt sich erst nach Programmneustart aus.")
    Case $HMenuE
    Exit
    Case $SMenu1
    MsgBox(0,"TechnoBase.FM","http://listen.technobase.fm/tunein-dsl-asx")
    Case $SMenu2
    MsgBox(0,"Top100Station","http://www.top100station.de/switch/r3472.asx")
    Case $SMenu3
    MsgBox(0,"Planet Radio","http://lsd.newmedia.nacamar.net/bb/redirect.lsc?stream=planetradio$livestream.mp3&content=live&media=mp3")
    Case $SMenu4
    MsgBox(0,"YouFM","http://metafiles.gl-systemhaus.de/hr/youfm_1.asx")
    Case $SMenu5
    MsgBox(0,"BigFM","http://217.151.152.245/bigfm-mp3-96")
    Case $SMenu6
    MsgBox(0,"Rautemusik.fm Main","http://main-high.rautemusik.fm/listen.asx")
    Case $SMenu7
    MsgBox(0,"1Live","http://www.wdr.de/wdrlive/media/einslive.asx")
    Case $MenuE
    MsgBox(0,"About BlackEyes StreamPlayer","BlackEyes StreamPlayer Version 1.4.0.3")
    Case $Button1
    $readcombo1 = GUICtrlRead($Combo1)
    $oWMP.controls.play()
    GUICtrlSetState($Volume, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_ENABLE)
    Switch $Button1
    Case $readcombo1 = "TechnoBase.FM"
    $oWMP.URL = 'http://listen.technobase.fm/tunein-dsl-asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Top100Station"
    $oWMP.URL = 'http://www.top100station.de/switch/r3472.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Planet Radio"
    $oWMP.URL = 'http://lsd.newmedia.nacamar.net/bb/redirect.lsc?stream=planetradio$livestream.mp3&content=live&media=mp3'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "YouFM"
    $oWMP.URL = 'http://metafiles.gl-systemhaus.de/hr/youfm_1.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "BigFM"
    $oWMP.URL = 'http://217.151.152.245/bigfm-mp3-96'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Rautemusik.fm Main"
    $oWMP.URL = 'http://main-high.rautemusik.fm/listen.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "1Live"
    $oWMP.URL = 'http://www.wdr.de/wdrlive/media/einslive.asx'
    GUICtrlSetData($Progress1, 100)
    Sleep(2000)
    GUICtrlSetData($Progress1, 0)
    Case $readcombo1 = "Bitte auswählen"
    MsgBox(0,"ERROR","Kein Sender ausgewählt!")
    EndSwitch
    Case $Button2
    $oWMP.controls.stop()
    GUICtrlSetState($Volume, $GUI_DISABLE)
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_DISABLE)
    GUICtrlSetState($Combo1, $GUI_ENABLE)
    GUICtrlSetData($Progress1, 0)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func CheckMouse()
    Local Static $mouseout=0
    $aMpos = MouseGetPos()
    $aWpos = WinGetPos("BlackEyes Stream Player")
    If $aMpos[0] > $aWpos[0] And $aMpos[0] < $aWpos[0] + $aWpos[2] And $aMpos[1] > $aWpos[1] And $aMpos[1] < $aWpos[1] + $aWpos[3] Then
    If $mouseout = 1 Then
    For $i=30 to 255 Step 30
    WinSetTrans("BlackEyes Stream Player", "", $i)
    sleep(50)
    Next
    WinSetTrans("BlackEyes Stream Player", "", 255)
    $mouseout=0
    EndIf
    Else
    If $mouseout=0 Then
    For $i=255 to 30 Step -30
    WinSetTrans("BlackEyes Stream Player", "", $i)
    sleep(50)
    Next
    $mouseout=1
    EndIf
    EndIf
    EndFunc

    [/autoit]

    Und setup hat leider nicht in den Anhang gepasst.

    Einmal editiert, zuletzt von Molaynox (5. Oktober 2010 um 15:33)