supersonic Posted September 7, 2008 Share Posted September 7, 2008 Hello everybody, I wrote a little script to print directly to LPT1:. Theoretically it will work, but two problems prevent me from finishing this script: 1. I can't stop the program. 2. High CPU usage (maybe due GUICtrlSetOnEvent() or badly programmed While/WEnd). Can somebody help me out... expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> ; Preserve order of variables! Global $program = "DPRINT" Global $lCounter = 0 Global $pCounter = 0 Global $pScope = RegRead("HKCU\Software\" & $program, "pScope") Global $fScope = RegRead("HKCU\Software\" & $program, "fScope") Global $port = RegRead("HKCU\Software\" & $program, "Port") Global $timer = RegRead("HKCU\Software\" & $program, "Timer") ; <...> Global $mainGUI = GUICreate($program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">", 500, 376, -1, -1) ; Global $mainP = GUICtrlCreatePic(@ScriptDir & "\" & $program & ".bmp", 1, 1, 498, 50) Global $mainLV = GUICtrlCreateListView("Date/Time|Path/File", 1, 53, 498, 148, $LVS_SORTDESCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) Global $mainG1 = GUICtrlCreateGroup("pScope", 001, 200, 498, 158) Global $mainG2 = GUICtrlCreateGroup("fScope | Port | Timer", 001, 243, 498, 115) Global $mainG2 = GUICtrlCreateGroup("", 001, 286, 498, 072) Global $mainI = GUICtrlCreateInput($pScope, 13, 218, 450, 21) Global $mainC1 = GUICtrlCreateCombo($fScope, 013, 261, 156, 021) Global $mainC2 = GUICtrlCreateCombo($port, 172, 261, 156, 021) Global $mainC3 = GUICtrlCreateCombo($timer, 331, 261, 156, 021) Global $mainB1 = GUICtrlCreateButton(">", 466, 218, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB2 = GUICtrlCreateButton("START", 013, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB3 = GUICtrlCreateButton("STOP", 172, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB4 = GUICtrlCreateButton("CLOSE", 331, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainL = GUICtrlCreateLabel("Freeware.", 1, 360, 498, 15, $SS_CENTER) AutoItSetOption("GUIOnEventMode", 1) ; Opt ; AutoItSetOption("TrayIconHide", 1) ; Opt HotKeySet("^{F1}", "start") ; STRG + F1 HotKeySet("^{F2}", "dummy") ; STRG + F2 HotKeySet("^{F3}", "close") ; STRG + F3 GUICtrlSetBkColor($mainL, 0x484848) GUICtrlSetColor($mainL, 0xFFFFFF) GUICtrlSetFont($mainL, 8.5, 400) GUICtrlSetOnEvent($mainB1, "path") GUICtrlSetOnEvent($mainB2, "start") GUICtrlSetOnEvent($mainB3, "stop") GUICtrlSetOnEvent($mainB4, "close") GUICtrlSetState($mainI, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState(@SW_SHOW, $mainGUI) $fArray = StringSplit("*.csv;*.dat;*.doc;*.txt", ";", 0) For $i = 1 to $fArray[0] Step 1 If Not StringInStr($fArray[$i], $fScope, 0) Then GUICtrlSetData($mainC1, $fArray[$i], "") EndIf Next ; <...> $pArray = StringSplit("COM1:;COM2:;COM3:;COM4:;LPT1:;LPT2:;LPT3:;LPT4:", ";", 0) For $i = 1 to $pArray[0] Step 1 If Not StringInStr($pArray[$i], $port, 0) Then GUICtrlSetData($mainC2, $pArray[$i], "") EndIf Next ; <...> For $i = 1 to 30 Step 1 GUICtrlSetData($mainC3, $i, "") Next While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func path() $pDummy = FileSelectFolder("", "", 4, $pScope) If $pDummy <> "" And _ Not StringInStr($pDummy, ".", 0) And _ Not StringInStr($pDummy, "\\", 0) Then $pScope = $pDummy GUICtrlSetData($mainI, $pScope) EndIf EndFunc Func start() GUICtrlSetState($mainC1, $GUI_DISABLE) GUICtrlSetState($mainC2, $GUI_DISABLE) GUICtrlSetState($mainC3, $GUI_DISABLE) GUICtrlSetState($mainB1, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_DISABLE) GUICtrlSetState($mainB3, $GUI_FOCUS) ; <...> If StringIsASCII(GUICtrlRead($mainI)) = "" Or _ StringIsASCII(GUICtrlRead($mainC1)) = "" Or _ StringIsASCII(GUICtrlRead($mainC2)) = "" Or _ StringIsInt(GUICtrlRead($mainC3)) = "" Then ; <...> Else For $i = 0 to 1 Step 1 For $j = $timer to 1 Step -1 GUICtrlSetData($mainC3, $j, "") Sleep(1000) Next $sDummy = FileFindFirstFile($pScope & "\" & $fScope) If $sDummy = -1 Then $lCounter = $lCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & "No file(s) found.", $mainLV) lvAutosize() EndIf While 1 $fDummy = FileFindNextFile($sDummy) If @error Then ExitLoop Else $pCounter = $pCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & $pScope & "\" & $fDummy, $mainLV) lvAutosize() EndIf WEnd FileClose($sDummy) $i = 0 Next EndIf ; <...> GUICtrlSetState($mainC1, $GUI_ENABLE) GUICtrlSetState($mainC2, $GUI_ENABLE) GUICtrlSetState($mainC3, $GUI_ENABLE) GUICtrlSetState($mainB1, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) EndFunc Func stop() EndFunc Func close() If StringIsASCII(GUICtrlRead($mainI)) Then RegWrite("HKCU\Software\" & $program, "pScope", "REG_SZ", GUICtrlRead($mainI)) EndIf If StringIsASCII(GUICtrlRead($mainC1)) Then RegWrite("HKCU\Software\" & $program, "fScope", "REG_SZ", GUICtrlRead($mainC1)) EndIf If StringIsASCII(GUICtrlRead($mainC2)) Then RegWrite("HKCU\Software\" & $program, "Port", "REG_SZ", GUICtrlRead($mainC2)) EndIf If StringIsInt(GUICtrlRead($mainC3)) Then RegWrite("HKCU\Software\" & $program, "Timer", "REG_SZ", GUICtrlRead($mainC3)) EndIf ; <...> Exit EndFunc Func dummy() EndFunc Func lvAutosize() For $i = 0 to 1 _GUICtrlListView_SetColumnWidth($mainLV, $i, $LVSCW_AUTOSIZE) Next EndFunc Greets, -supersonic. Link to comment Share on other sites More sharing options...
Andreik Posted September 7, 2008 Share Posted September 7, 2008 (edited) Use sleep in some loops. For example: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Sleep(25) WEnd Edited September 7, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ludocus Posted September 7, 2008 Share Posted September 7, 2008 this is strange,... I cant fix it.. Link to comment Share on other sites More sharing options...
ChrisL Posted September 7, 2008 Share Posted September 7, 2008 Use sleep in some loops. For example: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Sleep(25) WEnd You don't use a sleep in a GuiGetMsg() loop because it automatically sleeps the CPU [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
supersonic Posted September 7, 2008 Author Share Posted September 7, 2008 (edited) It's strange... After START button is pressed I can't press CLOSE button... But the hotkeys are working... Any ideas? Edited September 7, 2008 by supersonic Link to comment Share on other sites More sharing options...
Andreik Posted September 7, 2008 Share Posted September 7, 2008 You don't use a sleep in a GuiGetMsg() loop because it automatically sleeps the CPUI didn't knew this. How much time? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ChrisL Posted September 7, 2008 Share Posted September 7, 2008 (edited) You don't need GuiGetMsg() its an onEvent GuiIt works fine for me like this (closing that is all I tried) no high CPUCODE#include <GUIConstants.au3>#include <GUIListView.au3>;#include <ButtonConstants.au3>;#include <WindowsConstants.au3>;#include <StaticConstants.au3> ; Preserve order of variables!Global $program = "DPRINT"Global $lCounter = 0Global $pCounter = 0Global $pScope = RegRead("HKCU\Software\" & $program, "pScope")Global $fScope = RegRead("HKCU\Software\" & $program, "fScope")Global $port = RegRead("HKCU\Software\" & $program, "Port")Global $timer = RegRead("HKCU\Software\" & $program, "Timer"); <...>Global $mainGUI = GUICreate($program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">", 500, 376, -1, -1); Global $mainP = GUICtrlCreatePic(@ScriptDir & "\" & $program & ".bmp", 1, 1, 498, 50)Global $mainLV = GUICtrlCreateListView("Date/Time|Path/File", 1, 53, 498, 148, $LVS_SORTDESCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))Global $mainG1 = GUICtrlCreateGroup("pScope", 001, 200, 498, 158)Global $mainG2 = GUICtrlCreateGroup("fScope | Port | Timer", 001, 243, 498, 115)Global $mainG2 = GUICtrlCreateGroup("", 001, 286, 498, 072)Global $mainI = GUICtrlCreateInput($pScope, 13, 218, 450, 21)Global $mainC1 = GUICtrlCreateCombo($fScope, 013, 261, 156, 021)Global $mainC2 = GUICtrlCreateCombo($port, 172, 261, 156, 021)Global $mainC3 = GUICtrlCreateCombo($timer, 331, 261, 156, 021)Global $mainB1 = GUICtrlCreateButton(">", 466, 218, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE)Global $mainB2 = GUICtrlCreateButton("START", 013, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)Global $mainB3 = GUICtrlCreateButton("STOP", 172, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)Global $mainB4 = GUICtrlCreateButton("CLOSE", 331, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)Global $mainL = GUICtrlCreateLabel("Freeware.", 1, 360, 498, 15, $SS_CENTER)AutoItSetOption("GUIOnEventMode", 1); Opt; AutoItSetOption("TrayIconHide", 1); OptHotKeySet("^{F1}", "start"); STRG + F1HotKeySet("^{F2}", "dummy"); STRG + F2HotKeySet("^{F3}", "close"); STRG + F3GUICtrlSetBkColor($mainL, 0x484848)GUICtrlSetColor($mainL, 0xFFFFFF)GUICtrlSetFont($mainL, 8.5, 400)GUICtrlSetOnEvent($mainB1, "path")GUICtrlSetOnEvent($mainB2, "start")GUICtrlSetOnEvent($mainB3, "stop")GUICtrlSetOnEvent($mainB4, "close")GUICtrlSetState($mainI, $GUI_DISABLE)GUICtrlSetState($mainB2, $GUI_FOCUS)GUISetOnEvent($GUI_EVENT_CLOSE, "close")GUISetState(@SW_SHOW, $mainGUI)$fArray = StringSplit("*.csv;*.dat;*.doc;*.txt", ";", 0)For $i = 1 to $fArray[0] Step 1 If Not StringInStr($fArray[$i], $fScope, 0) Then GUICtrlSetData($mainC1, $fArray[$i], "") EndIfNext; <...>$pArray = StringSplit("COM1:;COM2:;COM3:;COM4:;LPT1:;LPT2:;LPT3:;LPT4:", ";", 0)For $i = 1 to $pArray[0] Step 1 If Not StringInStr($pArray[$i], $port, 0) Then GUICtrlSetData($mainC2, $pArray[$i], "") EndIfNext; <...>For $i = 1 to 30 Step 1 GUICtrlSetData($mainC3, $i, "")NextWhile 1 Sleep(1000)WEndFunc path() $pDummy = FileSelectFolder("", "", 4, $pScope) If $pDummy <> "" And _ Not StringInStr($pDummy, ".", 0) And _ Not StringInStr($pDummy, "\\", 0) Then $pScope = $pDummy GUICtrlSetData($mainI, $pScope) EndIfEndFuncFunc start() GUICtrlSetState($mainC1, $GUI_DISABLE) GUICtrlSetState($mainC2, $GUI_DISABLE) GUICtrlSetState($mainC3, $GUI_DISABLE) GUICtrlSetState($mainB1, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_DISABLE) GUICtrlSetState($mainB3, $GUI_FOCUS) ; <...> If StringIsASCII(GUICtrlRead($mainI)) = "" Or _ StringIsASCII(GUICtrlRead($mainC1)) = "" Or _ StringIsASCII(GUICtrlRead($mainC2)) = "" Or _ StringIsInt(GUICtrlRead($mainC3)) = "" Then ; <...> Else For $i = 0 to 1 Step 1 For $j = $timer to 1 Step -1 GUICtrlSetData($mainC3, $j, "") Sleep(1000) Next $sDummy = FileFindFirstFile($pScope & "\" & $fScope) If $sDummy = -1 Then $lCounter = $lCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & "No file(s) found.", $mainLV) lvAutosize() EndIf While 1 $fDummy = FileFindNextFile($sDummy) If @error Then ExitLoop Else $pCounter = $pCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & $pScope & "\" & $fDummy, $mainLV) lvAutosize() EndIf WEnd FileClose($sDummy) $i = 0 Next EndIf ; <...> GUICtrlSetState($mainC1, $GUI_ENABLE) GUICtrlSetState($mainC2, $GUI_ENABLE) GUICtrlSetState($mainC3, $GUI_ENABLE) GUICtrlSetState($mainB1, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_FOCUS)EndFuncFunc stop()EndFuncFunc close() If StringIsASCII(GUICtrlRead($mainI)) Then RegWrite("HKCU\Software\" & $program, "pScope", "REG_SZ", GUICtrlRead($mainI)) EndIf If StringIsASCII(GUICtrlRead($mainC1)) Then RegWrite("HKCU\Software\" & $program, "fScope", "REG_SZ", GUICtrlRead($mainC1)) EndIf If StringIsASCII(GUICtrlRead($mainC2)) Then RegWrite("HKCU\Software\" & $program, "Port", "REG_SZ", GUICtrlRead($mainC2)) EndIf If StringIsInt(GUICtrlRead($mainC3)) Then RegWrite("HKCU\Software\" & $program, "Timer", "REG_SZ", GUICtrlRead($mainC3)) EndIf ; <...> ExitEndFuncFunc dummy()EndFuncFunc lvAutosize() For $i = 0 to 1 _GUICtrlListView_SetColumnWidth($mainLV, $i, $LVSCW_AUTOSIZE) NextEndFunc Edited September 7, 2008 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted September 7, 2008 Share Posted September 7, 2008 (edited) I see what you mean when it's running.. This allows you to use the stop button Edit: I changed it a bit I like this better! Edit2: the second exitloop is now Exitloop(1) otherwise it leaves file handles open expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ; Preserve order of variables! Global $program = "DPRINT" Global $lCounter = 0 Global $pCounter = 0 Global $pScope = RegRead("HKCU\Software\" & $program, "pScope") Global $fScope = RegRead("HKCU\Software\" & $program, "fScope") Global $port = RegRead("HKCU\Software\" & $program, "Port") Global $timer = RegRead("HKCU\Software\" & $program, "Timer") ; <...> Global $mainGUI = GUICreate($program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">", 500, 376, -1, -1) ; Global $mainP = GUICtrlCreatePic(@ScriptDir & "\" & $program & ".bmp", 1, 1, 498, 50) Global $mainLV = GUICtrlCreateListView("Date/Time|Path/File", 1, 53, 498, 148, $LVS_SORTDESCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) Global $mainG1 = GUICtrlCreateGroup("pScope", 001, 200, 498, 158) Global $mainG2 = GUICtrlCreateGroup("fScope | Port | Timer", 001, 243, 498, 115) Global $mainG2 = GUICtrlCreateGroup("", 001, 286, 498, 072) Global $mainI = GUICtrlCreateInput($pScope, 13, 218, 450, 21) Global $mainC1 = GUICtrlCreateCombo($fScope, 013, 261, 156, 021) Global $mainC2 = GUICtrlCreateCombo($port, 172, 261, 156, 021) Global $mainC3 = GUICtrlCreateCombo($timer, 331, 261, 156, 021) Global $mainB1 = GUICtrlCreateButton(">", 466, 218, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB2 = GUICtrlCreateButton("START", 013, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB3 = GUICtrlCreateButton("STOP", 172, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB4 = GUICtrlCreateButton("CLOSE", 331, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainL = GUICtrlCreateLabel("Freeware.", 1, 360, 498, 15, $SS_CENTER) Global $Start AutoItSetOption("GUIOnEventMode", 1); Opt ; AutoItSetOption("TrayIconHide", 1); Opt HotKeySet("^{F1}", "start"); STRG + F1 HotKeySet("^{F2}", "dummy"); STRG + F2 HotKeySet("^{F3}", "close"); STRG + F3 GUICtrlSetBkColor($mainL, 0x484848) GUICtrlSetColor($mainL, 0xFFFFFF) GUICtrlSetFont($mainL, 8.5, 400) GUICtrlSetOnEvent($mainB1, "path") GUICtrlSetOnEvent($mainB2, "start") GUICtrlSetOnEvent($mainB3, "stop") GUICtrlSetOnEvent($mainB4, "close") GUICtrlSetState($mainI, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState(@SW_SHOW, $mainGUI) $fArray = StringSplit("*.csv;*.dat;*.doc;*.txt", ";", 0) For $i = 1 to $fArray[0] Step 1 If Not StringInStr($fArray[$i], $fScope, 0) Then GUICtrlSetData($mainC1, $fArray[$i], "") EndIf Next ; <...> $pArray = StringSplit("COM1:;COM2:;COM3:;COM4:;LPT1:;LPT2:;LPT3:;LPT4:", ";", 0) For $i = 1 to $pArray[0] Step 1 If Not StringInStr($pArray[$i], $port, 0) Then GUICtrlSetData($mainC2, $pArray[$i], "") EndIf Next ; <...> For $i = 1 to 30 Step 1 GUICtrlSetData($mainC3, $i, "") Next While 1 Sleep(1000) If $Start = 1 then _process() WEnd Func _Process() GUICtrlSetState($mainC1, $GUI_DISABLE) GUICtrlSetState($mainC2, $GUI_DISABLE) GUICtrlSetState($mainC3, $GUI_DISABLE) GUICtrlSetState($mainB1, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_DISABLE) GUICtrlSetState($mainB3, $GUI_FOCUS) ; <...> If StringIsASCII(GUICtrlRead($mainI)) = "" Or _ StringIsASCII(GUICtrlRead($mainC1)) = "" Or _ StringIsASCII(GUICtrlRead($mainC2)) = "" Or _ StringIsInt(GUICtrlRead($mainC3)) = "" Then ; <...> Else For $i = 0 to 1 Step 1 For $j = $timer to 1 Step -1 If $Start = 0 then Exitloop(2) GUICtrlSetData($mainC3, $j, "") Sleep(1000) Next $sDummy = FileFindFirstFile($pScope & "\" & $fScope) If $sDummy = -1 Then $lCounter = $lCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & "No file(s) found.", $mainLV) lvAutosize() EndIf While 1 If $Start = 0 then Exitloop(1) $fDummy = FileFindNextFile($sDummy) If @error Then ExitLoop Else $pCounter = $pCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & $pScope & "\" & $fDummy, $mainLV) lvAutosize() EndIf WEnd FileClose($sDummy) $i = 0 Next EndIf ; <...> GUICtrlSetState($mainC1, $GUI_ENABLE) GUICtrlSetState($mainC2, $GUI_ENABLE) GUICtrlSetState($mainC3, $GUI_ENABLE) GUICtrlSetState($mainB1, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) EndFunc Func path() $pDummy = FileSelectFolder("", "", 4, $pScope) If $pDummy <> "" And _ Not StringInStr($pDummy, ".", 0) And _ Not StringInStr($pDummy, "\\", 0) Then $pScope = $pDummy GUICtrlSetData($mainI, $pScope) EndIf EndFunc Func start() $Start = 1 EndFunc Func stop() $Start = 0 EndFunc Func close() If StringIsASCII(GUICtrlRead($mainI)) Then RegWrite("HKCU\Software\" & $program, "pScope", "REG_SZ", GUICtrlRead($mainI)) EndIf If StringIsASCII(GUICtrlRead($mainC1)) Then RegWrite("HKCU\Software\" & $program, "fScope", "REG_SZ", GUICtrlRead($mainC1)) EndIf If StringIsASCII(GUICtrlRead($mainC2)) Then RegWrite("HKCU\Software\" & $program, "Port", "REG_SZ", GUICtrlRead($mainC2)) EndIf If StringIsInt(GUICtrlRead($mainC3)) Then RegWrite("HKCU\Software\" & $program, "Timer", "REG_SZ", GUICtrlRead($mainC3)) EndIf ; <...> Exit EndFunc Func dummy() EndFunc Func lvAutosize() For $i = 0 to 1 _GUICtrlListView_SetColumnWidth($mainLV, $i, $LVSCW_AUTOSIZE) Next EndFunc Edited September 7, 2008 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted September 7, 2008 Share Posted September 7, 2008 I didn't knew this. How much time?Dunno how much but it's in the help file under GuiGetMsg() [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
supersonic Posted September 7, 2008 Author Share Posted September 7, 2008 @ChrisL: Thanks very much for your help! I see what you mean when it's running.. This allows you to use the stop button Edit: I changed it a bit I like this better! Edit2: the second exitloop is now Exitloop(1) otherwise it leaves file handles open expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ; Preserve order of variables! Global $program = "DPRINT" Global $lCounter = 0 Global $pCounter = 0 Global $pScope = RegRead("HKCU\Software\" & $program, "pScope") Global $fScope = RegRead("HKCU\Software\" & $program, "fScope") Global $port = RegRead("HKCU\Software\" & $program, "Port") Global $timer = RegRead("HKCU\Software\" & $program, "Timer") ; <...> Global $mainGUI = GUICreate($program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">", 500, 376, -1, -1) ; Global $mainP = GUICtrlCreatePic(@ScriptDir & "\" & $program & ".bmp", 1, 1, 498, 50) Global $mainLV = GUICtrlCreateListView("Date/Time|Path/File", 1, 53, 498, 148, $LVS_SORTDESCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) Global $mainG1 = GUICtrlCreateGroup("pScope", 001, 200, 498, 158) Global $mainG2 = GUICtrlCreateGroup("fScope | Port | Timer", 001, 243, 498, 115) Global $mainG2 = GUICtrlCreateGroup("", 001, 286, 498, 072) Global $mainI = GUICtrlCreateInput($pScope, 13, 218, 450, 21) Global $mainC1 = GUICtrlCreateCombo($fScope, 013, 261, 156, 021) Global $mainC2 = GUICtrlCreateCombo($port, 172, 261, 156, 021) Global $mainC3 = GUICtrlCreateCombo($timer, 331, 261, 156, 021) Global $mainB1 = GUICtrlCreateButton(">", 466, 218, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB2 = GUICtrlCreateButton("START", 013, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB3 = GUICtrlCreateButton("STOP", 172, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainB4 = GUICtrlCreateButton("CLOSE", 331, 304, 156, 042, $BS_CENTER, $WS_EX_CLIENTEDGE) Global $mainL = GUICtrlCreateLabel("Freeware.", 1, 360, 498, 15, $SS_CENTER) Global $Start AutoItSetOption("GUIOnEventMode", 1); Opt ; AutoItSetOption("TrayIconHide", 1); Opt HotKeySet("^{F1}", "start"); STRG + F1 HotKeySet("^{F2}", "dummy"); STRG + F2 HotKeySet("^{F3}", "close"); STRG + F3 GUICtrlSetBkColor($mainL, 0x484848) GUICtrlSetColor($mainL, 0xFFFFFF) GUICtrlSetFont($mainL, 8.5, 400) GUICtrlSetOnEvent($mainB1, "path") GUICtrlSetOnEvent($mainB2, "start") GUICtrlSetOnEvent($mainB3, "stop") GUICtrlSetOnEvent($mainB4, "close") GUICtrlSetState($mainI, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetState(@SW_SHOW, $mainGUI) $fArray = StringSplit("*.csv;*.dat;*.doc;*.txt", ";", 0) For $i = 1 to $fArray[0] Step 1 If Not StringInStr($fArray[$i], $fScope, 0) Then GUICtrlSetData($mainC1, $fArray[$i], "") EndIf Next ; <...> $pArray = StringSplit("COM1:;COM2:;COM3:;COM4:;LPT1:;LPT2:;LPT3:;LPT4:", ";", 0) For $i = 1 to $pArray[0] Step 1 If Not StringInStr($pArray[$i], $port, 0) Then GUICtrlSetData($mainC2, $pArray[$i], "") EndIf Next ; <...> For $i = 1 to 30 Step 1 GUICtrlSetData($mainC3, $i, "") Next While 1 Sleep(1000) If $Start = 1 then _process() WEnd Func _Process() GUICtrlSetState($mainC1, $GUI_DISABLE) GUICtrlSetState($mainC2, $GUI_DISABLE) GUICtrlSetState($mainC3, $GUI_DISABLE) GUICtrlSetState($mainB1, $GUI_DISABLE) GUICtrlSetState($mainB2, $GUI_DISABLE) GUICtrlSetState($mainB3, $GUI_FOCUS) ; <...> If StringIsASCII(GUICtrlRead($mainI)) = "" Or _ StringIsASCII(GUICtrlRead($mainC1)) = "" Or _ StringIsASCII(GUICtrlRead($mainC2)) = "" Or _ StringIsInt(GUICtrlRead($mainC3)) = "" Then ; <...> Else For $i = 0 to 1 Step 1 For $j = $timer to 1 Step -1 If $Start = 0 then Exitloop(2) GUICtrlSetData($mainC3, $j, "") Sleep(1000) Next $sDummy = FileFindFirstFile($pScope & "\" & $fScope) If $sDummy = -1 Then $lCounter = $lCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & "No file(s) found.", $mainLV) lvAutosize() EndIf While 1 If $Start = 0 then Exitloop(1) $fDummy = FileFindNextFile($sDummy) If @error Then ExitLoop Else $pCounter = $pCounter + 1 WinSetTitle($program, "", $program & " <Loop(s): " & $lCounter & " | Print(s): " & $pCounter & ">") GUICtrlCreateListViewItem(StringRight(@YEAR, 2) & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "|" & $pScope & "\" & $fDummy, $mainLV) lvAutosize() EndIf WEnd FileClose($sDummy) $i = 0 Next EndIf ; <...> GUICtrlSetState($mainC1, $GUI_ENABLE) GUICtrlSetState($mainC2, $GUI_ENABLE) GUICtrlSetState($mainC3, $GUI_ENABLE) GUICtrlSetState($mainB1, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_ENABLE) GUICtrlSetState($mainB2, $GUI_FOCUS) EndFunc Func path() $pDummy = FileSelectFolder("", "", 4, $pScope) If $pDummy <> "" And _ Not StringInStr($pDummy, ".", 0) And _ Not StringInStr($pDummy, "\\", 0) Then $pScope = $pDummy GUICtrlSetData($mainI, $pScope) EndIf EndFunc Func start() $Start = 1 EndFunc Func stop() $Start = 0 EndFunc Func close() If StringIsASCII(GUICtrlRead($mainI)) Then RegWrite("HKCU\Software\" & $program, "pScope", "REG_SZ", GUICtrlRead($mainI)) EndIf If StringIsASCII(GUICtrlRead($mainC1)) Then RegWrite("HKCU\Software\" & $program, "fScope", "REG_SZ", GUICtrlRead($mainC1)) EndIf If StringIsASCII(GUICtrlRead($mainC2)) Then RegWrite("HKCU\Software\" & $program, "Port", "REG_SZ", GUICtrlRead($mainC2)) EndIf If StringIsInt(GUICtrlRead($mainC3)) Then RegWrite("HKCU\Software\" & $program, "Timer", "REG_SZ", GUICtrlRead($mainC3)) EndIf ; <...> Exit EndFunc Func dummy() EndFunc Func lvAutosize() For $i = 0 to 1 _GUICtrlListView_SetColumnWidth($mainLV, $i, $LVSCW_AUTOSIZE) Next EndFunc 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