Sturmi Posted June 3, 2016 Share Posted June 3, 2016 hi , I need to select any item in List Item at startup everytime. Is there a style, exstyle to set it or do i need to click a random one ? because I get my items from a ini and don't want to allow no selection thanks Link to comment Share on other sites More sharing options...
AutoBert Posted June 4, 2016 Share Posted June 4, 2016 Use the default parameter of GuiCtrlSetData. Here a small old example (just inserted 3 lines 54,55,65): expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <WindowsConstants.au3> ; *** End added by AutoIt3Wrapper *** #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: AutoBert: http://www.autoit.de/index.php?page=Thread&postID=164341#post164341 Skriptbeispiel für den Umgang mit INI-Files und ListBox #ce ---------------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <StaticConstants.au3> ;#include <Array.au3> Const $sElect = "bitte einen Download auswählen" Global $sUrl ;ausgewählte DownloadUrl Global $sIni = @AppDataDir & "\Download.INI" ;Pfad zur Inidatei Global $sLocalFolder ;letztes Verzeichnis in das gespeichert wurde Global $aData[3] ;Download-Infos Global $iFileSize ;Grösse des DL-Files Global $tStart ;Download gestartet Global $nKBPerSec ;KB pro Sekunde Global $iPercent ;aktuell heruntergeladenen Prozentanteil der Datei ;If Not FileExists($sIni) Then $sData = "AutoIt 3.3.12.0=https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe" & @LF $sData &= "AutoIt Beta=https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.13.20-beta-setup.exe" & @LF $sData &= "Scite=http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe" & @LF IniWriteSection($sIni, "URLs", $sData) ;EndIf $hGui = GUICreate("mini-Downloader", 300, 105, 302, 218) $idlstProg = GUICtrlCreateList("", 8, 8, 200, 25) $idbtnAdd = GUICtrlCreateButton("&Hinzufügen", 213, 8, 80) $idbtnDel = GUICtrlCreateButton("&Löschen", 213, 35, 80) $idprgInfo = GUICtrlCreateProgress(8, 70, 285, 30) $idbtnDL = GUICtrlCreateButton("&Downloaden", 8, 35, 200) $hGUI_c = GUICreate("", 269, 30, 8, 70, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI) GUISetBkColor(0x989898, $hGUI_c) $idlblInfo = GUICtrlCreateLabel("0", 0, 8, 285, 25, $ES_CENTER) GUICtrlSetFont(-1, 12, 1000) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) _WinAPI_SetLayeredWindowAttributes($hGUI_c, 0x989898) GUICtrlSetState($idlblInfo, $GUI_HIDE) GUICtrlSetState($idprgInfo, $GUI_HIDE) read_INI() $sSelected=IniRead($sIni,'Selected','selected','') If $sSelected<>'' Then GUICtrlSetData($idlstProg,$sSelected,$sSelected) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOWNA, $hGUI_c) HttpSetUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.16") ;sonst streiken manche Freehoster wenn der AutoItUseragent gesetzt ist While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE IniWrite($sIni, "Path", "Local", $sLocalFolder) IniWrite($sIni, "Selected", "selected", GUICtrlRead($idlstProg)) Exit Case $idbtnAdd $write1 = InputBox("Downloadadresse", "Bitte eine gültige Download-Adresse eingeben") If $write1 <> "" Then $write2 = InputBox("Download verwalten unter", "Bitte Kurzbegriff eingeben") If $write2 <> "" Then IniWrite($sIni, "URLs", $write2, $write1) GUICtrlSetData($idlstProg, $write2, $write2) EndIf get_Selection() Case $idbtnDel $sDel = GUICtrlRead($idlstProg) IniDelete($sIni, "URLs", $sDel) GUICtrlSetData($idlstProg, "") read_INI() Case $idlstProg get_Selection() Case $idbtnDL ;get_Selection() $bCanceld = False GUICtrlSetData($idbtnDL, "Download &abbrechen") $aDatei = StringSplit($sUrl, "/") $sDatei = $aDatei[$aDatei[0]] $sLocal = FileSaveDialog($sDatei & "Speichern unter", $sLocalFolder, "Alle (*.*)", 18, $sDatei, $hGui) If Not @error Then GUICtrlSetState($idprgInfo, $GUI_SHOW) GUICtrlSetState($idlblInfo, $GUI_SHOW) GUICtrlSetData($idlblInfo, "Download startet") $aTmp = StringSplit($sLocal, "\") $sLocalFolder = $aTmp[$aTmp[1]] $iFileSize = InetGetSize($sUrl) $hDL = InetGet($sUrl, $sLocal, 1, 1) $tStart = TimerInit() $aData[0] = 0 Do $bCanceld = _MySleep(500) If $bCanceld Then ExitLoop $aData = InetGetInfo($hDL, -1) If $aData[0] > 0 Then $tDiff = TimerDiff($tStart) $nKBPerSec = Round($aData[0] / $tDiff * 1000 / 1024, 2) $iPercent = Round($aData[0] / $iFileSize * 100, 2) If GUICtrlRead($idlblInfo) <> $iPercent Then GUICtrlSetData($idprgInfo, $iPercent) GUICtrlSetData($idlblInfo, $iPercent & " % " & $nKBPerSec & " KB/sec") WinSetTitle($hGui, "", "DL: " & $sDatei & " " & $iPercent & "%") EndIf EndIf Until $aData[2] InetClose($hDL) ;_ArrayDisplay($aData) If $aData[0] < $aData[1] Then $aData[3] = False ;dummerweise werden nur DL-Fehler auf meiner Seite erkannt es kommt aber vo das der DL aus anderen Gründen nicht erfolgreich war If $aData[0] < $iFileSize Then $aData[3] = False ;dummerweise werden nur DL-Fehler auf meiner Seite erkannt es kommt aber vo das der DL aus anderen Gründen nicht erfolgreich war If Not $aData[3] Then If $bCanceld Then $sMsg = "Download wurde durch Benutzer abgebrochen" Else $sMsg = "Download hat abgebrochen," & @CRLF & "überprüfen sie Ihre Internetverbindung." & @CRLF & @CRLF & "Probieren Sie danach noch einmal!" EndIf MsgBox(48, "Fehler:", $sMsg) FileDelete($sLocal) Else GUICtrlSetState($idbtnDL, $GUI_DISABLE) GUICtrlSetData($idlstProg,$sElect,$sElect) MsgBox(64, $sLocal, "erfolgreich heruntergeladen") EndIf Else MsgBox(48, "Fehler:", "keinen Namen zum Speichern ausgeählt") EndIf GUICtrlSetData($idprgInfo, 0) GUICtrlSetData($idlblInfo, 0) GUICtrlSetState($idlblInfo, $GUI_HIDE) GUICtrlSetState($idprgInfo, $GUI_HIDE) GUICtrlSetData($idbtnDL, "&Downloaden") WinSetTitle($hGui, "", "mini-Downloader") EndSwitch WEnd Func _MySleep($iMSec) Local $nMsg, $dt = TimerInit() Do $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idbtnDL Return 1; DL Abbrechen wurde gedrückt EndSwitch Sleep(10) Until TimerDiff($dt) > $iMSec EndFunc ;==>_MySleep Func read_INI() $list1 = IniReadSection($sIni, "URLs") ;ConsoleWrite($list1 & @CRLF) If IsArray($list1) Then For $i = 1 To $list1[0][0] GUICtrlSetData($idlstProg, $list1[$i][0]) Next EndIf _GUICtrlListBox_InsertString($idlstProg, $sElect, 0) _GUICtrlListBox_SetCurSel($idlstProg, 0) $sLocalFolder = IniRead($sIni, "Path", "Local", @ScriptDir) EndFunc ;==>read_INI Func get_Selection() If GUICtrlRead($idlstProg) = $sElect Then GUICtrlSetState($idbtnDL, $GUI_DISABLE) GUICtrlSetData($idlblInfo, "") Else GUICtrlSetState($idbtnDL, $GUI_ENABLE) $Prog = GUICtrlRead($idlstProg) ;ConsoleWrite("ausgewählt: " & $Prog & @CRLF) $sUrl = IniRead($sIni, "URLs", $Prog, "") EndIf EndFunc ;==>get_Selection no after starting the last choise is selected, without line 55 item 0 ("please select a Download") is selected. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now