Leaderboard
Popular Content
Showing content with the highest reputation on 12/29/2015 in all areas
-
Few noob question about using AUTOIT
feelie75 and one other reacted to InunoTaishou for a topic
Welcome to the forums! 1a. Instead of copying over files using your mouse click you can use FileCopy or FileMove. 1b. Use _FileLIstToArray to get the files in the Backup folder, before using FileCopy you check to see if the file exists in the Backup Folder. If it exists the use FileMove to rename the old file. 1c. There's a few ways to do this: Have the script run indefinitely and start the backup process using a hotkey, or create a GUI and have it set to a button (If you use a GUI you could have the script output what it's doing. I.e., copying file Filename.txt.... copying complete, renaming old backup file *Filename.txt* to *Filename (old).txt*)You could still have the script run indefinitely and restart itself each time the last USB drive is removed and a new one is inserted. (Function: DriveGetDrive("ALL") will give you all the drive letters.)1d. Create a global variable (There's a few examples on the forums where they used $Paused) and set the hotkey to change the variable to true/false for paused/unpaused. Here's an example, I didn't implement it all, you'll have to change some things to make it work how you want, but it should give you a starting point #include <GUIConstants.au3> #include <AutoItConstants.au3> #include <File.au3> #include <Array.au3> Global $frmMain = GUICreate("Main Window", 400, 400) Global $btnStartBackup = GUICtrlCreateButton("Start Backup", 10, 10, 75, 25) Global $lblStatus = GUICtrlCreateLabel("Paused", 95, 10, 75, 25) Global $edtOutput = GUICtrlCreateEdit("", 10, 45, 380, 350) Global $aFilesToBackup[] = ["Test.txt", "My File.txt", "Old Script.au3"] Global $sFilePath = @ScriptDir & '\' GUICtrlSetFont($lblStatus, 10, 400, "", "Segoe UI") GUICtrlSetFont($edtOutput, 10, 400, "", "Segoe UI") GUISetState(@SW_SHOW, $frmMain) While (True) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnStartBackup GUICtrlSetData($lblStatus, "Running") BackupUSB() GUICtrlSetData($lblStatus, "Paused") EndSwitch WEnd Func BackupUSB() Local $drives = DriveGetDrive("ALL") Local $iBackupDrive = -1 Local $aOldFiles ; If getting the drive letters failed, send an error message and return If (@Error) Then DebugOutput("Failed to get Drive Letters" & @CRLF) Return EndIf ; Go through each drive letter and find the one that's USB. May have to change this if you have multiple USB's plugged int For $i = 1 to $drives[0] If (DriveGetType($drives[$i], $DT_BUSTYPE) = "USB") Then $iBackupDrive = $i ExitLoop EndIf Next ; If the $iBackupDrive is still -1, the for loop failed, send an error message and return If ($iBackupDrive = -1) Then DebugOutput("No USB Drive detected" & @CRLF) Return ; Else the $iBackupDrive is not -1 and the for loop succeeded, send a message that the backup process is starting Else DebugOutput("USB Drive detected. Backing up Drive " & $drives[$iBackupDrive] & @CRLF) EndIf ; Get all the files in the backup folder on the USB drive $aOldFiles = _FileListToArray($drives[$iBackupDrive] & "\Backup Folder\", $FLTA_FILES) ; Go through each file that we're going to backup from the computer For $i = 0 to UBound($aFilesToBackup) - 1 ; If the file already exists then rename it If (FileExists($drives[$iBackupDrive] & "\Backup Folder\" & $aFilesToBackup[$i])) Then Local $sFileExtension = StringTrimLeft($aFilesToBackup[$i], StringInStr($aFilesToBackup[$i], '.') - 1) Local $sFileName = StringTrimRight($aFilesToBackup[$i], StringLen($sFileExtension)) & ' ' & @MON & '-' & @MDAY & '-' & @YEAR DebugOutput("File " & $aFilesToBackup[$i] & " already exists. Renaming to " & $sFileName & $sFileExtension & @CRLF) If (FileMove($drives[$iBackupDrive] & "\Backup Folder\" & $aFilesToBackup[$i], $drives[$iBackupDrive] & "\Backup Folder\" & $sFileName & $sFileExtension)) Then DebugOutput(@TAB & "File renamed successfully" & @CRLF) Else DebugOutput(@TAB & "Failed to rename file" & @CRLF) EndIf EndIf If (FileCopy($sFilePath & $aFilesToBackup[$i], $drives[$iBackupDrive] & "\Backup Folder\" & $aFilesToBackup[$i])) Then DebugOutput("Successfully copied file " & $aFilesToBackup[$i] & @CRLF) Else DebugOutput("Failed to copy file " & $aFilesToBackup[$i] & @CRLF) EndIf Next DebugOutput("Backup process complete" & @CRLF) EndFunc Func DebugOutput(Const ByRef $sMsg) GUICtrlSetData($edtOutput, GUICtrlRead($edtOutput) & $sMsg) EndFunc2 points -
Incremental search in owner and custom drawn ListViews
pixelsearch reacted to LarsJ for a topic
Incremental search is usually implemented by drawing the background of the substrings that matches the search string with a specific color eg. yellow. Incremental in this context means that the search is performed dynamically after each character while the search string is typed. In a listview this can be implemented by owner drawing through the LVS_OWNERDRAWFIXED flag and WM_DRAWITEM messages. (A custom drawn listview supports coloring of fields. However, the coloring works best for whole fields. This doesn't make it applicable to incremental search.) Inspiration for the example is found in these two questions: Search box for names and Search In ListView (Redraw with matching string). Examples The zip file below contains three examples. Listview items are strings of random characters with different lengths. In all examples a global $iItems = 1000 in top of script specifies the number of rows. There are no performance issues up till 10,000 rows. Note that the search is performed in an array and not directly in the listview. A regular expression can be entered in the search box. Search strings like "m........." with a varying number of dots will result in a varying number of matches. To keep it simple only one occurrence of the search string in each item is tested. As soon as one occurrence is found the search loop moves on to next item. 1) Incremental text search.au3 The first example is a simple demonstration of basic functionality: F3 and Shift+F3 can be used instead of Next and Prev buttons. 2) Show matching rows only.au3 An owner drawn listview can easily be combined with a virtual listview to extend the functionality of the incremental search. A virtual listview is especially interesting if you want to dynamically update the listview to only display the rows that matches the search string. Such an update is very fast in a virtual listview. This example is useful if the listview contains a set of file names and you are searching for a specific file eg. to open the file. In this situation you are probably not interested in the files that doesn't match. Because the listview only contains matching rows "Next match" and "Prev match" buttons are disabled. Clear the search field to display all items. 3) Standard search dialog.au3 The last example is a demonstration of a standard search dialog as the search box in Notepad. FindText function in comdlg32.dll creates the standard search box. The function is implemented as _WinAPI_FindTextDlg in WinAPIDlg.au3. In the Microsoft documentation you can read: Note that the FINDREPLACE structure and the buffer for the search string should be a global or static variable so it does not go out of scope before the dialog box closes. Because the FINDREPLACE structure is created as a local variable in _WinAPI_FindTextDlg it goes out of scope as soon as the function returns. This implementation of FindText is used in the example: ;Func _WinAPI_FindTextDlg($hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) Func _WinAPI_FindTextDlgEx(ByRef $tFR, $hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) $__g_pFRBuffer = __HeapReAlloc($__g_pFRBuffer, 2 * $__g_iFRBufferSize) If @error Then Return SetError(@error + 20, @extended, 0) DllStructSetData(DllStructCreate('wchar[' & $__g_iFRBufferSize & ']', $__g_pFRBuffer), 1, StringLeft($sFindWhat, $__g_iFRBufferSize - 1)) ;Local $tFR = DllStructCreate($tagFINDREPLACE) $tFR = DllStructCreate($tagFINDREPLACE) DllStructSetData($tFR, 'Size', DllStructGetSize($tFR)) DllStructSetData($tFR, 'hOwner', $hOwner) DllStructSetData($tFR, 'hInstance', 0) DllStructSetData($tFR, 'Flags', $iFlags) DllStructSetData($tFR, 'FindWhat', $__g_pFRBuffer) DllStructSetData($tFR, 'ReplaceWith', 0) DllStructSetData($tFR, 'FindWhatLen', $__g_iFRBufferSize * 2) DllStructSetData($tFR, 'ReplaceWithLen', 0) DllStructSetData($tFR, 'lParam', $lParam) DllStructSetData($tFR, 'Hook', $pFindProc) DllStructSetData($tFR, 'TemplateName', 0) Local $Ret = DllCall('comdlg32.dll', 'hwnd', 'FindTextW', 'struct*', $tFR) If @error Or Not $Ret[0] Then Local $Error = @error + 30 __HeapFree($__g_pFRBuffer) If IsArray($Ret) Then Return SetError(10, _WinAPI_CommDlgExtendedErrorEx(), 0) Else Return SetError($Error, @extended, 0) EndIf EndIf Return $Ret[0] EndFunc Then it's ensured that the local variable that is used for $tFR in the script, does not go out of scope, while the search box is open. ListviewIncrSearch.7z 1) Incremental text search.au3 2) Show matching rows only.au3 3) Standard Find text dialog.au3 DrawItem.au3 GuiListViewEx.au3 WinAPIDlgEx.au3 You need AutoIt 3.3.14 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) ListviewIncrSearch.7z1 point -
Hello everyone, I started working on this calendar control for my company. It's still a work in progress, and there are some bugs and some features missing, but I still wanted to share it with you guys, to get some comments and ideas for future development. My question would be: "Would you have done it this way?", meaning, would you have built it with labels as I did, or would it be better using GDI+ or other methods? Screenshot: Here is an example (Try double-clicking on a date): #include <GUIConstantsEx.au3> #include "_CalendarUDF.au3" Opt("GUIOnEventMode", 1) Global $GUI, $fStartMonday = False, $iGridSize = 1, $sTheme = "Blue" _Main() Func _Main() Local $GUI = GUICreate("Calendar example", 800, 600, -1, -1, BitOR($WS_SYSMENU, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() GUICtrlCreateButton("Toggle grid", 20, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_ToggleGrid") GUICtrlCreateButton("Toggle Start Mon/Sun", 170, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_ToggleMondaySunday") GUICtrlCreateButton("Go to Date", 320, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_GoToDate") GUICtrlCreateButton("Add Event", 470, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_AddEvent") GUICtrlCreateButton("Switch theme", 620, 10, 150, 20) GUICtrlSetOnEvent(-1, "Btn_SwitchTheme") ;Create the calendar control: _GuiCtrlCal_Create("My Calendar", 20, 40, 760, 520, @MON, @YEAR, 30, $fStartMonday, $iGridSize) ;Register my function, called when I double click a date: _GuiCtrlCal_OnDateDblClickRegister("_MyFunction") ;Add some Events: _GuiCtrlCal_EventAdd("2012/12/01", "World AIDS Day") _GuiCtrlCal_EventAdd("2012/12/25", "Christmas") _GuiCtrlCal_EventAdd("2012/12/21", "Winter Solstice") _GuiCtrlCal_EventAdd("2012/12/10", "Human Rights day") _GuiCtrlCal_EventAdd("2012/12/31", "Happy new year") _GuiCtrlCal_EventAdd("2013/01/11", "Human Trafficking Awareness") _GuiCtrlCal_EventAdd("2013/01/26", "Australia Day") ;Loop: While 1 Sleep(50) WEnd EndFunc ;This function will now be called when I doubleclick on a date. ;This function has to have one parameter that will contain ;the selected date: Func _MyFunction($sDate) ;The selected date is $sDate ConsoleWrite("Selected date is: " & $sDate & @CRLF) ;Create a small gui to input a text for the event: Local $mousePos = MouseGetPos() Local $GUIAddEvent = GUICreate("Add Event", 250, 50, $mousePos[0] - 125, $mousePos[1] - 15, $WS_POPUP, $WS_EX_TOPMOST, $GUI) GUISetState(@SW_SHOW, $GUIAddEvent) Local $Info = GUICtrlCreateLabel("Enter a text and press enter to add the event", 0, 0, 250, 15) Local $GUIAddEvent_Input = GUICtrlCreateInput("", 0, 15, 250, 35) GUICtrlSetState($GUIAddEvent_Input, $GUI_FOCUS) ;Wait for the user to press enter: While 1 If _IsPressed("0D") Then Do Sleep(10) Until Not _IsPressed("0D") ExitLoop EndIf Sleep(50) WEnd ;Read the text: Local $sText = GUICtrlRead($GUIAddEvent_Input) If $sText = "" Then Return GUIDelete($GUIAddEvent) ;Add the event: _GuiCtrlCal_EventAdd($sDate, $sText) EndFunc Func _Exit() _GuiCtrlCal_Destroy() Exit EndFunc Func Btn_ToggleGrid() If $iGridSize = 0 Then $iGridSize = 1 Else $iGridSize = 0 EndIf _GuiCtrlCal_SetGridSize($iGridSize) _GuiCtrlCal_Refresh() EndFunc Func Btn_ToggleMondaySunday() $fStartMonday = Not $fStartMonday _GuiCtrlCal_SetStartMonday($fStartMonday) _GuiCtrlCal_Refresh() EndFunc Func Btn_GoToDate() Local $sDate = InputBox("Go to Date", "Input the year, month and day : YYYY/MM/DD", @YEAR & "/" & @MON & "/" & @MDAY) If $sDate <> "" Then Local $aDate = StringSplit($sDate, "/") If Not @error Then _GuiCtrlCal_GoToMonth($aDate[1], $aDate[2]) _GuiCtrlCal_SetSelectedDate($sDate) EndIf EndIf EndFunc Func Btn_AddEvent() Local $sDateEvent = InputBox("Event Date", "Input the year, month and day (YYYY/MM/DD) for your event", @YEAR & "/" & @MON & "/" & @MDAY) If $sDateEvent = "" Then Return Local $sText = InputBox("Event Text", "Input the Text for your event", "My Event") If $sText = "" Then Return _GuiCtrlCal_EventAdd($sDateEvent, $sText) EndFunc Func Btn_SwitchTheme() Switch $sTheme Case "Blue" $sTheme = "Dark" _GuiCtrlCal_SetThemeDark() Case "Dark" $sTheme = "Blue" _GuiCtrlCal_SetThemeBlue() EndSwitch EndFunc And here is the UDF: _CalendarUDF.au31 point
-
dBase udf and dll
argumentum reacted to mLipok for a topic
QUESTIONS: Who is the license owner for attached DLL ? What type of license is for this DLL ? btw. Pretty good UDF One remark: for the functions header use the standard headers you can add this using SciTE4AutoIt by pressing CTRL+ALT+H1 point -
Python total noob
JohnOne reacted to JLogan3o13 for a topic
I don't do a lot of Python, but I use Jetbrains PyCharm: https://www.jetbrains.com/pycharm/whatsnew/1 point -
You have an error because $W1 is not an array (no window found), isn't it ? This code works for me : $W1 = WinGetPos("Microsoft Outlook", "") IniWriteSection(@ScriptDir & "\settings.ini","MO", "X=" & $W1[0] & @LF & "Y=" & $W1[1] & @LF & "W=" & $W1[2] & @LF & "H=" & $W1[3]) Also, with a 2D array : $W1 = WinGetPos("Microsoft Outlook", "") Local $aArr[5][2] = [[], ["X", $W1[0]], ["Y", $W1[1]], ["W", $W1[2]], ["H", $W1[3]] ] IniWriteSection(@ScriptDir & "\settings.ini","MO", $aArr)1 point
-
WinExist can be used but the check must be more precise (window title or text) Func test() Local $w = WinList("[CLASS:#32770]") For $i = 1 to $w[0][0] If StringInStr(WinGetText($w[$i][1]), "some text") Then WinClose($w[$i][1]) Next EndFunc1 point
-
2DArray --> Neo4j
argumentum reacted to iamtheky for a topic
*update to give the visual a little more substance, and to make sure it was handling single entries ok (it was!)1 point -
Hey, it was only matter of a code which works or not, even if the combo is awful indeed1 point
-
My way. #include <String.au3> Global $sMainString = "ASDLFJHASLDJHFKJAWEJQzCMXNZMDBlkhjaskdjfasIOJAOSDFJIOjalsdfiashdfiouhqwpoJAOWPIJASDLFJASDNlnasdfkjansdkjfnasdkKLJASDKLJFHASDKJFHASDlsajpofdsjhfaowsdefaoidsnLAZZSSzzSDFZKSJALKSDJFHALSDFHJK" ConsoleWrite("!Normal String" & @CRLF) ConsoleWrite($sMainString & @CRLF) ConsoleWrite("!Sorted String" & @CRLF) ConsoleWrite(_SortChars($sMainString) & @CRLF) Func _SortChars($sString) Local Const $sChars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" Local $sOutString = "" Local $sChar = "" For $i = 1 To StringLen($sChars) $sChar = StringMid($sChars, $i, 1) StringReplace($sString, $sChar, "", 0, 1) If @extended Then $sOutString &= _StringRepeat($sChar, @extended) EndIf Next Return $sOutString EndFunc ;==>_SortCharsSaludos1 point
-
You can have a @guinness, but you cant have the wet farts? I would expect that from 'Zee Hard Ass' (at least thats how i pronounce @czardas), but not from a naked dude 'Mel Bare'.1 point