Moin,
ich habe ein Schleifenproblem...
Und zwar erstelle ich zur Zeit ein Programm, das nur im SystemTray zu bedienen sein soll (und per Hotkey !).
Wenn ich jetzt die MainFunction starte, dann zeigen die Klicks auf die Traymenü Items keinerlei Wirkung !
D.h. die Schleife in der MainFunction unterbricht die Traymenü-Schleife und scheint diese Lahm zu legen...
Wie kann ich diesen Makel ausmerzen ???
Ich könnte einfach die Traymenü Geschichte noch einmal in die MainFunction Schleife nehmen, aber diese Schleife enthält einen Sleep, was die Trayfunktionalität dann doch auch beinträchtigt..., hmmm.
Gibt es keine Möglichkeit die Funktionsschleife auszuführen, ohne die Trayschleife zu unterbrechen ?
Spoiler anzeigen
#cs =====================================================================================================================
Screenshot & Upload to ftp
by Greenhorn
inspired by Mex
#ce ======================================================================================================================
#Region AutoIt3Wrapper directives section
#AutoIt3Wrapper_icon=E:\AutoIt Projekte\ScreenshotToFTP\snap.ico
#AutoIt3Wrapper_Res_Icon_Add=E:\AutoIt Projekte\ScreenshotToFTP\FallenAngel.ico
#AutoIt3Wrapper_allow_decompile=N
#AutoIt3Wrapper_PassPhrase=*****
#EndRegion
#NoTrayIcon
#Include <Constants.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
Global $i = 1
Global $Picform = 85
Global $FileExt = ".jpg"
Global $server, $username, $pass, $serverdir, $Seconds, $PicDir, $h_DllCaptDLL
HotKeySet("{PrintScreen}", "_Capture")
HotKeySet("{Insert}", "_Upload")
$Data = IniReadSection(@ScriptDir & "\config.ini", "Ftp")
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
_IniDialog()
Else
$server = IniRead("config.ini", "Ftp", "Server", "")
$username = IniRead("config.ini", "Ftp", "User", "")
$pass = IniRead("config.ini", "Ftp", "Pass", "")
$serverdir = IniRead("config.ini", "Ftp", "Serverpath", "")
$Seconds = IniRead("config.ini", "Capture", "Reapeat", 5)
$Picform = IniRead("config.ini", "Capture", "Picformat", 85)
$PicDir = IniRead("config.ini", "Capture", "Picdir", @ScriptDir)
EndIf
Opt("TrayMenuMode", 0)
Opt("TrayAutoPause", 0)
$TrConfig = TrayCreateItem("Einstellungen")
TrayCreateItem("")
$TrUpload = TrayCreateItem("Upload")
TrayCreateItem("")
$TrStart = TrayCreateItem("Start")
TrayCreateItem("")
$TrStop = TrayCreateItem("Stop")
TrayItemSetText($TRAY_ITEM_PAUSE, "Pause")
TrayItemSetText($TRAY_ITEM_EXIT, "Beenden")
TraySetState()
[/autoit] [autoit][/autoit] [autoit]While 1
$msg = TrayGetMsg()
Switch $msg
Case $TrConfig
_IniDialog()
Case $TrUpload
_Upload()
Case $TrStart
_Capture() ; MainFunction -> Das Problemkind...
Case $TrStop
OnAutoItExit()
Case $TRAY_ITEM_EXIT
Terminate()
EndSwitch
WEnd
Func _Capture() ; Ab hier ist Schluss mit Funktionalität des Traymenüs, Hotkeys funzen aber...
FileInstall("Captdll.dll", "Captdll.dll", 0)
Dim $h_DllCaptDLL = DllOpen("captdll.dll");Open it only once at the beginning and close it once at the end. Not every time the while loops.
HotKeySet("{End}", "OnAutoItExit")
HotKeySet("{Pause}", "_Pause")
While 1
DllCall($h_DllCaptDLL, "int:cdecl", "CaptureScreen", "str", $PicDir & "\" & "Screenshot_" & $i & $FileExt, "int", $Picform)
If @error = 1 Then ExitLoop
Sleep($Seconds * 1000)
$i += 1
WEnd
EndFunc ;==>_Capture
Func _Upload()
FileInstall("ScrUploader.exe", @TempDir & "\ScrUploader.exe", 0)
IniWrite(@TempDir & "\Upload.ini", "Ftp", "Server", $server)
IniWrite(@TempDir & "\Upload.ini", "Ftp", "User", $username)
IniWrite(@TempDir & "\Upload.ini", "Ftp", "Pass", $pass)
IniWrite(@TempDir & "\Upload.ini", "Ftp", "Serverpath", $serverdir)
IniWrite(@TempDir & "\Upload.ini", "Capture", "Picdir", $PicDir)
Sleep(500)
Run(@TempDir & "\ScrUploader.exe")
EndFunc ;==>_Upload
Func _Pause()
TraySetState(4)
Do
Sleep(100)
Until _IsPressed("13") ; Pause-Taste
TraySetState(8)
EndFunc ;==>_Pause
Func _IniDialog()
$Capt2ftp = GUICreate("Capture 2 ftp", 409, 447, 193, 115)
$Tab = GUICtrlCreateTab(16, 24, 377, 345)
$TFtp = GUICtrlCreateTabItem("FTP")
GUICtrlSetState(-1, $GUI_SHOW)
$server = GUICtrlCreateInput("", 40, 78, 250, 21)
$username = GUICtrlCreateInput("", 40, 138, 250, 21)
$pass = GUICtrlCreateInput("", 40, 198, 250, 21)
$serverdir = GUICtrlCreateInput("", 40, 268, 250, 21)
$Lserver = GUICtrlCreateLabel("Servername", 40, 58, 61, 20)
$Lusername = GUICtrlCreateLabel("Benutzername", 40, 118, 72, 20)
$Lpass = GUICtrlCreateLabel("Kennwort", 40, 178, 49, 20)
$Lserverdir = GUICtrlCreateLabel("Serververzeichnis", 40, 248, 88, 17)
$TCaptures = GUICtrlCreateTabItem("Captures")
$LPic1 = GUICtrlCreateLabel("Bildformat wählen", 40, 72, 87, 17)
$RadioBmp = GUICtrlCreateRadio("Bitmap", 40, 98, 70, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RadioJpg = GUICtrlCreateRadio("JPEG", 40, 138, 70, 17)
$LPic2 = GUICtrlCreateLabel("Bildqualität (1 bis 100)", 145, 138, 120, 20)
$JpgQlty = GUICtrlCreateInput($Picform, 264, 138, 50, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$Updown1 = GUICtrlCreateUpdown($JpgQlty)
GUICtrlSetLimit(-1, 100, 1)
$LPic3 = GUICtrlCreateLabel("Screenshot vom Bildschirm alle ", 88, 216, 175, 17)
$Seconds = GUICtrlCreateInput("5", 264, 213, 50, 21)
$Updown2 = GUICtrlCreateUpdown($Seconds)
GUICtrlSetLimit(-1, 100, 1)
$LPic4 = GUICtrlCreateLabel("Sekunden", 320, 216, 53, 17)
$LPic5 = GUICtrlCreateLabel("Screenshotverzeichnis ", 40, 253, 175, 17)
$PicDir = GUICtrlCreateInput(@ScriptDir, 40, 273, 250, 21)
$BtnDir = GUICtrlCreateButton("...", 305, 272, 60, 25, 0)
GUICtrlCreateTabItem("")
$BtnOK = GUICtrlCreateButton("Start", 304, 392, 89, 25, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $RadioBmp
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetState($JpgQlty, $GUI_DISABLE)
GUICtrlSetState($Seconds, $GUI_DISABLE)
$Picform = -1
$FileExt = ".bmp"
Case $RadioJpg
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetState($JpgQlty, $GUI_ENABLE)
GUICtrlSetState($Seconds, $GUI_ENABLE)
$FileExt = ".jpg"
Case $Updown1
$Picform = GUICtrlRead($JpgQlty)
Case $Updown2
$Seconds = GUICtrlRead($Seconds)
Case $BtnDir
$PicDir = FileSelectFolder("Screenshotverzeichnis wählen...", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 7, @ScriptDir)
Case $BtnOK
_IniWrite()
ExitLoop
EndSwitch
WEnd
EndFunc ;==>_IniDialog
Func _IniWrite()
IniWrite("config.ini", "Ftp", "Server", $server)
IniWrite("config.ini", "Ftp", "User", $username)
IniWrite("config.ini", "Ftp", "Pass", $pass)
IniWrite("config.ini", "Ftp", "Serverpath", $serverdir)
IniWrite("config.ini", "Capture", "Reapeat", $Seconds)
IniWrite("config.ini", "Capture", "Picformat", $Picform)
IniWrite("config.ini", "Capture", "Picdir", $PicDir)
EndFunc ;==>_IniWrite
;Exit helper functions
Func Terminate()
Exit
EndFunc ;==>Terminate
Func OnAutoItExit()
DllClose($h_DllCaptDLL);closing the dll now that the script is exiting.
EndFunc ;==>OnAutoItExit
#cs ===> FTP - ScrUploader.exe
$PicUp = IniRead("Upload.ini", "ScreenshotDir", "Dir", "Not Found")
$Open = _FTPOpen ("MyFTP_Control")
$Conn = _FTPConnect ($Open, $server, $username, $pass)
While 1
$Ftpp = _FtpPutFile ($Conn, $PicUp, $serverdir)
Sleep(100)
;programmcode
WEnd
$Ftpc = _FTPClose($Open)
#ce ===> FTP
Gruß
Greenhorn