Leaderboard
Popular Content
Showing content with the highest reputation on 06/13/2017 in all areas
-
I've recently been uncovering the useful commandline tools that can be found natively in Windows, one of which was findstr (there is also a GUI interface available in SciTE4AutoIt3.) After coming across this little gem and implementing in >SciTE Jump, it felt only right that I should share this on the forums as a standalone UDF. Thanks Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FindInFile ; Description ...: Search for a string within files located in a specific directory. ; Syntax ........: _FindInFile($sSearch, $sFilePath[, $sMask = '*'[, $fRecursive = True[, $fLiteral = Default[, ; $fCaseSensitive = Default[, $fDetail = Default]]]]]) ; Parameters ....: $sSearch - The keyword to search for. ; $sFilePath - The folder location of where to search. ; $sMask - [optional] A list of filetype extensions separated with ';' e.g. '*.au3;*.txt'. Default is all files. ; $fRecursive - [optional] Search within subfolders. Default is True. ; $fLiteral - [optional] Use the string as a literal search string. Default is False. ; $fCaseSensitive - [optional] Use Search is case-sensitive searching. Default is False. ; $fDetail - [optional] Show filenames only. Default is False. ; Return values .: Success - Returns a one-dimensional and is made up as follows: ; $aArray[0] = Number of rows ; $aArray[1] = 1st file ; $aArray[n] = nth file ; Failure - Returns an empty array and sets @error to non-zero ; Author ........: guinness ; Remarks .......: For more details: http://ss64.com/nt/findstr.html ; Example .......: Yes ; =============================================================================================================================== Func _FindInFile($sSearch, $sFilePath, $sMask = '*', $fRecursive = True, $fLiteral = Default, $fCaseSensitive = Default, $fDetail = Default) Local $sCaseSensitive = $fCaseSensitive ? '' : '/i', $sDetail = $fDetail ? '/n' : '/m', $sRecursive = ($fRecursive Or $fRecursive = Default) ? '/s' : '' If $fLiteral Then $sSearch = ' /c:' & $sSearch EndIf If $sMask = Default Then $sMask = '*' EndIf $sFilePath = StringRegExpReplace($sFilePath, '[\\/]+$', '') & '\' Local Const $aMask = StringSplit($sMask, ';') Local $iPID = 0, $sOutput = '' For $i = 1 To $aMask[0] $iPID = Run(@ComSpec & ' /c ' & 'findstr ' & $sCaseSensitive & ' ' & $sDetail & ' ' & $sRecursive & ' "' & $sSearch & '" "' & $sFilePath & $aMask[$i] & '"', @SystemDir, @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput &= StdoutRead($iPID) Next Return StringSplit(StringStripWS(StringStripCR($sOutput), BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)), @LF) EndFunc ;==>_FindInFileExample use of Function: #include <Array.au3> #include <Constants.au3> Example() Func Example() Local $hTimer = TimerInit() Local $aArray = _FindInFile('findinfile', @ScriptDir, '*.au3;*.txt') ; Search for 'findinfile' within the @ScripDir and only in .au3 & .txt files. ConsoleWrite(Ceiling(TimerDiff($hTimer) / 1000) & ' second(s)' & @CRLF) _ArrayDisplay($aArray) $hTimer = TimerInit() $aArray = _FindInFile('autoit', @ScriptDir, '*.au3') ; Search for 'autoit' within the @ScripDir and only in .au3 files. ConsoleWrite(Ceiling(TimerDiff($hTimer) / 1000) & ' second(s)' & @CRLF) _ArrayDisplay($aArray) EndFunc ;==>Example1 point
-
You can use _GDIPlus_GraphicsDrawImageRectRect or _GDIPlus_BitmapCloneArea for example.1 point
-
Cannot check SysTreeView32 item
fw85 reacted to anthonyjr2 for a topic
I've found a solution, although it requires an external UDF. For some reason the built in TreeView doesn't work correct on a lot of SysTreeView32 controls, but this other one I found does. I think it is a problem with 32/64 bit architectures. You can get the other UDF from here and then use it in your script like so: #RequireAdmin #AutoIt3Wrapper_UseX64=N #include "r_SysTreeView.au3" Run("winamp5666_full_all.exe"); WinWait("Installer Language", "Please select a language."); WinActivate("Installer Language", "Please select a language."); ControlClick("Installer Language", "Please select a language.", 1); WinWait("Winamp Installer", "Welcome to the Winamp installer"); WinActivate("Winamp Installer", "Welcome to the Winamp installer"); ControlClick("Winamp Installer", "Welcome to the Winamp installer", 1); WinWait("Winamp Installer", "License Agreement"); WinActivate("Winamp Installer", "License Agreement"); ControlClick("Winamp Installer", "License Agreement", 1); WinWait("Winamp Installer", "Choose Install Location"); WinActivate("Winamp Installer", "Choose Install Location"); ControlClick("Winamp Installer", "Choose Install Location", 1); WinWait("Winamp Installer", "Choose Components"); WinActivate("Winamp Installer", "Choose Components"); ControlCommand("Winamp Installer", "Choose Components", 1017, "SelectString", "Full"); ControlTreeView("Winamp Installer", "Choose Components", 1032, "Expand", "#2"); ControlTreeView("Winamp Installer", "Choose Components", 1032, "Expand", "#2|#1"); ControlSysTreeView("Winamp Installer", "Choose Components", "[CLASS:SysTreeView32; ID:1032]", "Uncheck", "#2|#1|#1") I know this is an odd workaround, but hey it works for me. Also make sure you are compiling non 64-bit (I added the option at the top of my code).1 point -
Will post an example as soon as I return to my office.1 point
-
[Solved]Converting PDF file to word document. Possible for AutoIt?
mLipok reacted to ViciousXUSMC for a topic
I would guess it depends if its a flat pdf that is basically an image, or if it has metadata so you can extract the text out of it. Also maybe 2013 and 2016 have a feature: https://support.office.com/en-us/article/Edit-PDF-content-in-Word-b2d1d729-6b79-499a-bcdb-233379c2f63a1 point -
corgano, This caught me out a few years ago - apparently a fix to the code to get the $WS_EX_RTL style to work correctly meant that from 3.3.13.19 onwards, you need to use GUISetState before any WinMove commands or the autoresizing will not work. I was told at the time that the Help file would be modified to reflect this but I cannot find anything so I will look to add something myself. M231 point
-
Skysnake, From the Help file for GUICtrlCreateGraphic: So you cannot change the size of the control when resizing the GUI, only the position of the control within the resized GUI. M231 point
-
Recent Files Logic
argumentum reacted to czardas for a topic
The following code is intended to illustrate a method of adding recent files to the File menu, once files have been opened or saved. This is not a UDF, nor a universal solution which fits all requirements. It is just the solution I made for myself and I thought it worth sharing. I haven't noticed much about this subject. The example only emulates opening and saving files: nothing is actually written to disk. I have not included any code for opening or saving files - only the File menu and Title bar are updated. The code is intended to illustrate the logic I used. Perhaps you can improve on it or get some ideas from this example. #include <GUIConstants.au3> #include <MsgBoxConstants.au3> Example() #Region ; core functions Func UpdateRecentFiles(ByRef $aRecentFiles, $ahMenu, $sNewPath, $iMenuInsertPos) Local $iMaxFiles = UBound($aRecentFiles) -1 For $i = 1 To $aRecentFiles[0][0] ; check to see if the path was accessed recently If $aRecentFiles[$i][0] = $sNewPath Then ; file is already in the list For $j = $i To 2 Step -1 $aRecentFiles[$j][0] = $aRecentFiles[$j -1][0] ; push items down the list Next $aRecentFiles[1][0] = $sNewPath For $j = 1 To $aRecentFiles[0][0] ; update all recent file menu items GUICtrlSetData($aRecentFiles[$j][1], $aRecentFiles[$j][0]) ; overwrite existing control data Next Return ; the list has simply been reordered EndIf Next ; if we are here, then the file was not found in the recent files list For $i = $iMaxFiles To 2 Step -1 $aRecentFiles[$i][0] = $aRecentFiles[$i -1][0] ; push all existing items down the list Next If $aRecentFiles[0][0] < $iMaxFiles Then $aRecentFiles[0][0] += 1 ; increment the number of recent files in the list $aRecentFiles[$aRecentFiles[0][0]][1] = GUICtrlCreateMenuItem($sNewPath, $ahMenu[0], $aRecentFiles[0][0] + $iMenuInsertPos) ; create a new control ; add a second spacer to the menu after the first recent item appears (one time action) If $aRecentFiles[0][0] = 1 Then $aRecentFiles[0][1] = GUICtrlCreateMenuItem('', $ahMenu[0], $aRecentFiles[0][0] + $iMenuInsertPos +1) ; add divider after adding the first recent item EndIf $aRecentFiles[1][0] = $sNewPath ; add the new path to the files list For $i = 1 To $aRecentFiles[0][0] ; update all recent file menu items GUICtrlSetData($aRecentFiles[$i][1], $aRecentFiles[$i][0]) ; overwrite existing control data Next EndFunc ;==> UpdateRecentFiles Func ClearRecentFiles(ByRef $aRecentFiles, $idDummyInactive) For $i = 0 To $aRecentFiles[0][0] GUICtrlDelete($aRecentFiles[$i][1]) ; delete menu items $aRecentFiles[$i][1] = $idDummyInactive ; render all control IDs inactivate Next $aRecentFiles[0][0] = 0 ; there are now zero files in the list EndFunc ;==> ClearRecentFiles Func DeleteRecentItem(ByRef $aRecentFiles, $iItem, $idDummyInactive) For $i = $iItem To $aRecentFiles[0][0] -1 $aRecentFiles[$i][0] = $aRecentFiles[$i +1][0] GUICtrlSetData($aRecentFiles[$i][1], $aRecentFiles[$i][0]) Next GUICtrlDelete($aRecentFiles[$aRecentFiles[0][0]][1]) $aRecentFiles[$aRecentFiles[0][0]][1] = $idDummyInactive $aRecentFiles[0][0] -= 1 If $aRecentFiles[0][0] = 0 Then GUICtrlDelete($aRecentFiles[0][1]) $aRecentFiles[0][1] = $idDummyInactive EndIf EndFunc ;==> DeleteRecentItem #EndRegion ;==> core functions #Region ; example code Func Example() Local $sGUITitle = "New Project", $hGUI = GUICreate($sGUITitle, 500, 200) ; create GUI Local _ ; declare menu arrays $ahMenu[2] = [" File "," Options"], _ ; 1D array assigned to menus $ahMenuItem = GetMenuItems() ; 2D array assigned to menu item controls For $i = 0 To UBound($ahMenu) -1 $ahMenu[$i] = GUICtrlCreateMenu($ahMenu[$i]) ; create menu For $j = 1 To $ahMenuItem[0][$i] ; add menu item controls $ahMenuItem[$j][$i] = GUICtrlCreateMenuItem($ahMenuItem[$j][$i], $ahMenu[$i]) Next Next Local $iMenuInsertPos = 4 ; this is the menuentry position for the most recent file GUICtrlCreateMenuItem('', $ahMenu[0], $iMenuInsertPos) ; create dividor Local $aRecentFiles[9][2] = [[0]], _ ; zero previously stored items - assuming that the recent files list is empty at startup $idDummyInactive = GUICtrlCreateDummy() ; never send messages to $idDummyInactive For $i = 0 To 8 ; [IMPORTANT] Windows assigned a unique control ID to $idDummyInactive $aRecentFiles[$i][1] = $idDummyInactive ; temporarily set all (recent files list) controls to never receive messages Next GUISetState(@SW_SHOW) Local $msg, $sFilePath While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $ahMenuItem[5][0] ExitLoop Case $ahMenuItem[1][0] ; File ==> New New() WinSetTitle($hGUI , WinGetTitle($hGUI), $sGUITitle) Case $ahMenuItem[2][0] ; File ==> Open $sFilePath = Open() If Not @error Then WinSetTitle($hGUI , WinGetTitle($hGUI), $sFilePath) UpdateRecentFiles($aRecentFiles, $ahMenu, $sFilePath, $iMenuInsertPos) EndIf Case $ahMenuItem[3][0] ; File ==> Save $sFilePath = Save(WinGetTitle($hGUI)) If @error Then MsgBox($MB_OK, "Action Failed", "Unable to save file") ContinueLoop ; [use your own code logic] Else WinSetTitle($hGUI , WinGetTitle($hGUI), $sFilePath) UpdateRecentFiles($aRecentFiles, $ahMenu, $sFilePath, $iMenuInsertPos) ; update recent files here EndIf Case $ahMenuItem[4][0] ; File ==> Save As $sFilePath = SaveAs() If @error Then MsgBox($MB_OK, "Action Failed", "Unable to save file") ContinueLoop ; [use your own code logic] Else WinSetTitle($hGUI , WinGetTitle($hGUI), $sFilePath) UpdateRecentFiles($aRecentFiles, $ahMenu, $sFilePath, $iMenuInsertPos) ; update recent files here EndIf Case $ahMenuItem[1][1] ; Options ==> Clear Recent Files ClearRecentFiles($aRecentFiles, $idDummyInactive) Case $aRecentFiles[1][1], $aRecentFiles[2][1], $aRecentFiles[3][1], $aRecentFiles[4][1], $aRecentFiles[5][1], $aRecentFiles[6][1], $aRecentFiles[7][1], $aRecentFiles[8][1] For $i = 1 To $aRecentFiles[0][0] If $msg = $aRecentFiles[$i][1] Then $sFilePath = OpenRecent($aRecentFiles[$i][0]) If Not @error Then WinSetTitle($hGUI , WinGetTitle($hGUI), $sFilePath) UpdateRecentFiles($aRecentFiles, $ahMenu, $sFilePath, $iMenuInsertPos) ; update recent files here ElseIf @error = 1 Then If MsgBox(BitOR($MB_YESNO, $MB_DEFBUTTON2, $MB_TASKMODAL), "Action Failed", "Unable to locate " & $aRecentFiles[$i][0] & @CRLF & _ "Do you want to remove this item from the menu?") = 6 Then DeleteRecentItem($aRecentFiles, $i, $idDummyInactive) EndIf ExitLoop ; return to the While loop EndIf Next EndSwitch WEnd EndFunc ;==> Example Func New() ; start a new project [your code here] EndFunc ;==> New Func Open() Local $sFilePath = FileOpenDialog("Open", @DocumentsCommonDir, "All (*.*)") If @error Then Return SetError(1) ; read file [your code here] Return $sFilePath EndFunc ;== Open Func OpenRecent($sFilePath) If Not FileExists($sFilePath) Then Return SetError(1) ; unable to open recent file ; read file [your code here] Return $sFilePath EndFunc ;== OpenRecent Func Save($sFilePath) If Not FileExists($sFilePath) Then Local $sNewPath = SaveAs() If @error Then Return SetError(1) ; unable to save file Return $sNewPath EndIf ; save file [your code here] Return $sFilePath EndFunc ;==> Save Func SaveAs() Local $sFilePath = FileSaveDialog( "Save As", @DocumentsCommonDir, "All (*.*)") If @error Then Return SetError(1) ; unable to save file ; save new or existing file [your code here] Return $sFilePath EndFunc ;==> SaveAs Func GetMenuItems() Local $aMenuItem[6][2] $aMenuItem[0][0] = 5 ; number of items on the File Menu $aMenuItem[0][1] = 1 ; number of items on the Options Menu ; File Menu $aMenuItem[1][0] = "New" $aMenuItem[2][0] = "Open" $aMenuItem[3][0] = "Save" $aMenuItem[4][0] = "Save As" $aMenuItem[5][0] = "Exit" ; Options Menu $aMenuItem[1][1] = "Clear Recent Files" Return $aMenuItem EndFunc ;==> GetMenuItems #Region ; example code Run the example, open some files and check for new menu items that are added. Then try a few other menu options and check the various changes occurring in the File menu.1 point -
tezhihi, Sorry. It was for a better readability indeed If you keep this pattern then of course all whitespaces can be removed - and the (?x) too I personally rarely use significant whitespaces in patterns, I better use \h etc which fit in most cases1 point
-
Outlook manipulation, open mails and open attachments
rapt3r reacted to JLogan3o13 for a topic
@rapt3r welcome to the forum. Yes this is possible, and in fact quite common. Please check the OutlookEX thread in our Examples forum, download the library and try out the examples. If you have any questions, please post them here along with your code and we will do our best to assist1 point -
remember this one (I assume on new machines you cannot assume all .NET versions are there) https://blogs.msdn.microsoft.com/dsvc/2013/03/04/usage-of-net-collections-types-in-vbscript-is-not-supported-after-net-4-5/1 point
-
Code for clicking a button by text not working in IE
Hanukka reacted to anthonyjr2 for a topic
This isn't a limitation of the UDF or the website, it's a limitation of all browsers in general. They purposely deny XSS for security reasons.1 point -
The forum is currently being upgraded - this post details the status. Content may look badly formatted at the moment. This is normal until the background rebuild tasks have finished. There is no need to re-edit your old posts or signatures to fix them, this should happen automatically. Please resist the urge to do so The post rebuild is estimated at 9 hours - it's not a quick task. Current Status: Forum upgraded - 100%AutoIt code boxes rebuilt - 100%Double-spaced paragraphs fixed up (as best I can) - 100%Forum to Wiki Access - 100%Signatures rebuilt - 100%Posts rebuilt (emoticons, bbcode, attachments, images, quotes) - 100%Legacy BBCode fixed in signatures​color - 100%color=rgb() - 100%url - 100%img - 100%size - 100%Search engine online - 100%1 point
-
PhilHibbs, I would do it this way: #include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hEdit_1 = GUICtrlCreateEdit("", 10, 10, 400, 140) $hEdit_1_Handle = GUICtrlGetHandle(-1) $hButton_1 = GUICtrlCreateButton("Edit 1", 10, 160, 80, 30) $hEdit_2 = GUICtrlCreateEdit("", 10, 210, 400, 140) $hEdit_2_Handle = GUICtrlGetHandle(-1) $hButton_2 = GUICtrlCreateButton("Edit 1", 10, 360, 80, 30) GUISetState() _WinAPI_SetFocus($hEdit_1_Handle) GUICtrlSetState($hButton_2, $GUI_DISABLE) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch Switch _WinAPI_GetFocus() Case $hEdit_1_Handle If BitAnd(GUICtrlGetState($hButton_1), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($hButton_1, $GUI_ENABLE) If BitAnd(GUICtrlGetState($hButton_2), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($hButton_2, $GUI_DISABLE) Case $hEdit_2_Handle If BitAnd(GUICtrlGetState($hButton_2), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($hButton_2, $GUI_ENABLE) If BitAnd(GUICtrlGetState($hButton_1), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($hButton_1, $GUI_DISABLE) EndSwitch WEnd M231 point