Leaderboard
Popular Content
Showing content with the highest reputation on 05/21/2021 in all areas
-
You're right, it doesn't. I assumed _NowCalc was a system call which would take care of the possible issues, I didn't look at its source. _Date_Time_GetLocalTime looks like it may offer the solution which I hoped I was pointing you to. Thanks to @argumentum for digging a little deeper. Once again I failed to follow my own advice which is "never assume".2 points
-
You could use an external flag for example registry or file, the child keeps watching for this flag and and once changed deletes or modifies the flag back to the default. Hope that makes sense1 point
-
Copy all files of a folder without overwriting existing ones
Musashi reacted to Earthshine for a topic
I would use a call to Robocopy. read this link https://stackoverflow.com/questions/5152835/having-xcopy-copy-a-file-and-not-overwrite-the-previous-one-if-it-exists-withou use the following syntax when calling it from AutoIt robocopy x:\sourcefolder Y:\destfolder /s /e /r:0 /z that should solve your issue1 point -
[Solved] Regular expression to capture multiple groups with prefix
FrancescoDiMuro reacted to mikell for a topic
Yes they are - a little, I confess Jan Goyvaerts says this : "The functionality offered by VBScript’s RegExp object is pretty much bare bones" This looked quite frustrating so I went away, sorry1 point -
Copy all files of a folder without overwriting existing ones
Musashi reacted to Earthshine for a topic
nice job @Musashi1 point -
Copy all files of a folder without overwriting existing ones
Earthshine reacted to Musashi for a topic
One way to copy files, but not overwrite existing files in the destination folder : Local $hSearch, $sSourceDir, $sDestinationDir, $sFileName $sSourceDir = @ScriptDir & "\Source\" $sDestinationDir = @ScriptDir & "\Destination\" $hSearch = FileFindFirstFile($sSourceDir & "*.*") ; Check, if Destination folder exists. If not, then create it : If Not StringInStr(FileGetAttrib($sDestinationDir), "D") Then DirCreate($sDestinationDir) While True $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If (Not FileExists($sDestinationDir & $sFileName)) And (Not StringInStr(FileGetAttrib($sSourceDir & $sFileName), "D")) Then FileCopy($sSourceDir & $sFileName, $sDestinationDir) EndIf WEnd FileClose($hSearch)1 point -
Copy all files of a folder without overwriting existing ones
Professor_Bernd reacted to Musashi for a topic
This is true (at least for my older AutoIt version 3.3.14.0). The following post by Melba23 explains the problem : https://www.autoitscript.com/forum/topic/176952-filecopy-works-only-with-overwrite-solved/?do=findComment&comment=1270166 Excerpt :1 point -
Jos, I did a quick check on mij home computer (W7-x64, with also the same error), and used the beta version Autoit3Wrapper.au3 No errors, it worked perfect! Next week (Tuesday) i'm going to check the beta version on my pc at work, where i did the testing today. I let you know! Thnx a lot !!1 point
-
Changing zorder of GUICtrlCreateGraphic possible?
Aaron3569 reacted to pixelsearch for a topic
Maybe this way ? #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> $hParentWindow = GUICreate("Main", 500, 500) GUISetState() GUISwitch($hParentWindow) ;Created bevor Child GUI GUICtrlCreateGraphic(110, 100, 100, 100) GUICtrlSetBkColor(-1, 0xFF0000) ; red $hChildWIndow = GUICreate("Child", 150, 150, 150, 150, $WS_CHILD, -1, $hParentWindow) GUISetBkColor(0x000000) GUISetState() GUISwitch($hParentWindow) ;Created after Child GUI GUICtrlCreateGraphic(230, 100, 100, 100) GUICtrlSetBkColor(-1, 0x00FF00) ; green _WinAPI_SetWindowPos($hChildWIndow, $HWND_BOTTOM , 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE)) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd1 point -
[Solved] Regular expression to capture multiple groups with prefix
FrancescoDiMuro reacted to JockoDundee for a topic
Cats are finicky...1 point -
Date.au3 and @macro usage
JockoDundee reacted to argumentum for a topic
in the post Date macros safe to use?, I started to dig into the possibilities. And within the UDF, yes, there is a possibility of 1 in a zillion, or just plain overwhelmed CPU that a time calculation be ugly wrong. So I propose to change all macro ( or most of 'em ), to "kernel32.dll, GetLocalTime". And since I thought of it, might as well get it done. Please find attached the new beta for evaluation. Thank you very much. I'll now go get a beer. oops: I now realized that I did not account for the leading zero on single digit numbers ( after the beer ) Fixed. Opps again: Forgot error checking. Done ok, this one can be downloaded Date.au3(3.3.15.4_proposal_v3).zip1 point -
Date.au3 and @macro usage
argumentum reacted to jpm for a topic
Thanks I integrate it in the next beta1 point -
How to Mute only AutoIT scripts that are using Text to Speech
FrancescoDiMuro reacted to Jos for a topic
Doesn't SAPI.SpVoice have an option for that? Something like "$oSP.volume = 0 ; mute" ?1 point -
The problem is that the execution of a statement generally takes time. During this process, seconds, minutes, etc. can skip to the next unit. This takes longer with scripting languages than with compiled languages. The question for all languages is therefore not how to prevent this problem, but what frequency of "incorrect" results you can accept. AutoIt is certainly unsuitable for real-time processing.1 point
-
Date.au3 and @macro usage
argumentum reacted to JockoDundee for a topic
For me, it was much less, around 1 in 13.6 million. Good idea, arg, definitely needed to be fixed! For anyone else who wants to test how long before the current production UDF glitches: #include <Date.au3> Local $sNow, $sThen, $iCalls=0, $htimer=TimerInit() Do $sThen=$sNow $sNow=_NowCalc() $iCalls+=1 Until $sNow<$sThen ConsoleWrite("Time jumped from "& $sNow &" to "& $sThen &@CRLF) ConsoleWrite("Run Time: "& Round(TimerDiff($htimer)/1000,3) &@CRLF) ConsoleWrite("Calls Made: "& $iCalls &@CRLF) *using the production UDF Time jumped from 2021/05/20 21:01:00 to 2021/05/20 21:01:59 Run Time: 50.323 Calls Made: 136029621 point -
Date macros safe to use?
EskoFIN reacted to argumentum for a topic
What @Nine may have meant is something like this: #include <Date.au3> Exit NowTestThis() Func NowTestThis() Local $tLocalTime = _Date_Time_GetLocalTime() ; ...so you can get the date/time right out of the struct ConsoleWrite( _ $tLocalTime.Year & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.Month & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.Day & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.Hour & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.Minute & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.Second & @TAB & @SEC & ':' & @MSEC & @CRLF & _ $tLocalTime.MSeconds & @TAB & @SEC & ':' & @MSEC & @CRLF) EndFunc Edit #5 ? :..going down the rabbit hole: So yes, it can happen that a time difference occur, as in deeper testing in a slow PC, it showed to change 1 ms. while processing, therefore, that could be the ms. of ... end of the hour?/day?/year?, so the assurance to get a timestamp is important. So either use a function to make sure that that second is the same from first macro call to the last macro call or something like the above function, that gets the "GetLocalTime" from kernel32.dll as a Struct. PS: .. just learned something today, I never looked deep into1 point -
_GUIScrollBars_ and Scrollsteps
Aaron3569 reacted to pixelsearch for a topic
Based on your script in another post, here is a smooth scroll of 1 pixel (adjustable in variable $iPixels) in 4 directions, using 4 direction keys. No scrollbars. It may help you to achieve your goal : #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{RIGHT}", "ScrollRight") HotKeySet("{LEFT}", "ScrollLeft") HotKeySet("{UP}", "ScrollUp") HotKeySet("{DOWN}", "ScrollDown") Global $iPixels = 1 $hParent = GUICreate("Parent", 1000, 700) GUICtrlCreateButton("Button", 50, 50, 50, 50) GUISetState() $hChild = GUICreate("Child", 200, 200, -1,-1, $WS_CHILD , -1, $hParent) GUISetBkColor(0x000000) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func ScrollRight() _ScrollWindow($hParent, $iPixels, 0) EndFunc Func ScrollLeft() _ScrollWindow($hParent, - $iPixels, 0) EndFunc Func ScrollUp() _ScrollWindow($hParent, 0, - $iPixels) EndFunc Func ScrollDown() _ScrollWindow($hParent, 0, $iPixels) EndFunc Func _ScrollWindow($hWnd, $iXAmount, $iYAmount) Return DllCall("user32.dll", "bool", "ScrollWindow", "hwnd", $hWnd, "int", $iXAmount, "int", $iYAmount, "ptr", 0, "ptr", 0)[0] EndFunc ;==>_ScrollWindow1 point -
Changing zorder of GUICtrlCreateGraphic possible?
Aaron3569 reacted to JockoDundee for a topic
Minimal code snippet required.1 point -
[Solved] Regular expression to capture multiple groups with prefix
FrancescoDiMuro reacted to Deye for a topic
without too much of examining how, this somehow moves everything to the top "(User|Login-name|NTSecurity|Member):\s(.*)|(.+)\r\n?(?:\r?\n)"1 point -
Incremental search in owner and custom drawn ListViews
Lion66 reacted to pixelsearch for a topic
Hi Lion66 * Concerning _GUICtrlListView_GetItemText (LVM_GETITEMTEXT message) it doesn't work in a Virtual Listview (LVS_OWNERDATA style) as stipulated in this MS link (just search LVM_GETITEMTEXT in the web page, it will lead you to 4 chapters concerning Virtual Listview, all interesting to read) Edit #1 : _GUICtrlListView_GetItemText seems to work fine if LVN_GETDISPINFO is used (just tested on "2h") * Concerning _GUICtrlListView_JustifyColumn (LVM_SETCOLUMN message) I think you're right. It works fine when the Virtual ListView is populated via LVN_GETDISPINFO, but when it's populated via WM_DRAWITEM (when LV got the LVS_OWNERDRAWFIXED style) then it doesn't work because coords applied by user's code in WM_DRAWITEM are all related to a left string justification. Here is a silly test to show what could work. In version "2i", you can add 1 line to center headers : For $i = 0 To $g_iCols - 1 _GUICtrlListView_AddColumn($g_idListView, $g_aCols[$i], $g_aWidths[$i]) _GUICtrlListView_JustifyColumn($g_idListView, $i, 2) ; <======= added line Next Then you can center all items (starting from col 1 in the example below, by modifying 1 line : ; DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tRect, "uint", 0) ; _WinAPI_DrawText changed to : DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sItemText, "int", StringLen( $sItemText ), "struct*", $tRect, "uint", $i > 0 ? $DT_CENTER : 0) ; _WinAPI_DrawText Unfortunately it's not enough : what looks great in the precedent pic (all cols centered starting from col 1+) will display bad coords when search (a "." in search field) is applied to other columns, for example : Maybe if we knew how to change the matched rectangle coords, then center justification could be done when using WM_DRAWITEM ? Edit #2 : @Lion66 To retrieve the text of any subitem in a virtual listview having LVS_OWNERDRAWFIXED style, you need to retrieve it from the array that populated the listview. As you can't use _GUICtrlListView_GetItemText, then try this code in "2i", it will give you an idea on how to retrieve subitem texts in your script. This code is just an example and has to be added inside the While... Wend Loop . Then right click on an item, it will be selected and retrieve the text of column 0 (because of column [0] in code) no matter the columns are sorted or not. Case $GUI_EVENT_SECONDARYDOWN Local $iSelected = GUICtrlSendMsg($g_idListView, $LVM_GETNEXTITEM, -1, $LVNI_SELECTED) If $iSelected > - 1 Then If $g_iSortDir = 0x0400 Then ; 0x0400 = $HDF_SORTUP Local $sGetText = $g_aSubArray[$g_tIndex.arr($iSelected + 1)][0] Else Local $sGetText = $g_aSubArray[$g_tIndex.arr($g_iSearch - $iSelected)][0] EndIf MsgBox($MB_TOPMOST, "Item = " & $iSelected, "Text col 0 = " & $sGetText) EndIf It's easy to create a function for this, so it's reusable anywhere in the script : Case $GUI_EVENT_SECONDARYDOWN Local $iSelected = GUICtrlSendMsg($g_idListView, $LVM_GETNEXTITEM, -1, $LVNI_SELECTED) If $iSelected > - 1 Then ; an item is selected Local $sGetText = _GetText($iSelected, 0) MsgBox($MB_TOPMost, "Item = " & $iSelected, "Text col 0 = " & $sGetText) EndIf ... ;======================================================================== Func _GetText($iItem, $iSubItem) Local $sGetText If $g_iSortDir = 0x0400 Then ; 0x0400 = $HDF_SORTUP $sGetText = $g_aSubArray[$g_tIndex.arr($iItem + 1)][$iSubItem] Else $sGetText = $g_aSubArray[$g_tIndex.arr($g_iSearch - $iItem)][$iSubItem] EndIf Return $sGetText EndFunc ;==>_GetText It's great that global variables all start with $g_ in the script, so it's quicker to prepare a function (we don't spend time on checking $g_ variables to add them as parameters)1 point -
This is my first thread in Example, so please easy with me I found a function by Rogue5099 to check if a file is in used or not, but it only working great when checking a file in local drive. I make a little change so it can also report a correct "file in used" status for files that on network. I hope this script can benefit for every of us $fFile = "c:\myscript.exe" If _FileInUse($fFile) = 0 then Msgbox(64, "Info", $fFile & " is NOT in used") Else Msgbox(64, "Info", $fFile & " is in used") EndIf ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Parameter(s): $sFilename = File name ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use or file not exists ; Create by: Rogue5099 ; Modified by: michaelslamet ; ;=============================================================================== Func _FileInUse($sFilename) ;note: dword", 0x40000000, _ ---> jalan bagus jika $sFilename ada di hdd local, tapi jika $sFilename ada di network drive, gunakan dword", 0x80000000, _ Local $aRet, $hFile If StringUpper(DriveGetType($sFilename)) = "NETWORK" Then $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ "dword", 0x00000004, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL Else $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x40000000, _ ;dwDesiredAccess = GENERIC_WRITE "dword", 0x00000004, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL EndIf If NOT FileExists($sFilename) Then Return 0 Else $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") SetError($aRet[0]) Return 1 Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return 0 EndIf EndIf EndFunc1 point
-
cyanidemonkey Try this: Global Const $GENERIC_READ = 0x80000000 Global Const $GENERIC_WRITE = 0x40000000 Global Const $OPEN_EXISTING = 3 Global Const $FILE_ATTRIBUTE_NORMAL = 0x80 $file = "d:\Base\work.dat" If Not FileExists($file) Then Exit $hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", $file, _ "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _ "int", 0, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) If $hFile[0] = -1 Then MsgBox(48, "Warning", "File is open") Else DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0]) EndIf1 point
-
Forum is full of examples and UDFs of how to use DllCall, using Windows API too. Anyway, here you go... $file = "FileInUseTestfile.txt" $h = FileOpen($file, 1) $x = _FileInUse($file) MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") FileClose($h) $x = _FileInUse($file) MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") FileDelete($file) ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Parameter(s): $sFilename = File name ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; ;=============================================================================== Func _FileInUse($sFilename) Local $aRet, $hFile $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ "dword", 0, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") SetError($aRet[0]) Return 1 Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return 0 EndIf EndFunc1 point