Leaderboard
Popular Content
Showing content with the highest reputation on 03/28/2018 in all areas
-
[NEW VERSION] - 2 Aug 18 Added: When specifying the icon to use, if the $vIcon parameter is set to the name of an ico or exe file, the main icon within will be displayed, but if a trailing "|" followed by the icon index is added to the name, that icon from within the file is used New UDF and example in the zip below. Details of previous versions: Changelog.txt A forum query about the small pop-ups that some apps produce from the systray led me to create my version of how this can be done. By the way, I call these small GUIs "Toasts" for obvious reasons! A zip containing the UDF, an example script and my StringSize UDF (which is also required): Toast.zip As always, kind comments and constructive criticisms welcome - particularly the former! M231 point
-
In the last versions of Windows, it has been difficult to automate Windows Explorer. But there are many examples of code like this to extract the selected items: ; Windows Explorer on XP, Vista, 7, 8 $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then Exit ; Shell object $oShell = ObjCreate( "Shell.Application" ) ; Find window For $oWindow In $oShell.Windows() If $oWindow.HWND() = $hExplorer Then ExitLoop Next ; Selected items For $oItem In $oWindow.Document.SelectedItems() ConsoleWrite( $oItem.Path() & @CRLF ) Next It's possible to create these objects with ObjCreateInterface. More precisely, create an IShellBrowser interface for the top level browser of an open Windows Explorer. Plan and code This is the plan: Create an IShellWindows interface to get a list of shell windows Get an IWebBrowserApp object for each window. This is done in two steps: Get an IDispatch object for the window Get the IWebBrowserApp interface Identify the proper shell window with get_HWND of IWebBrowserApp Get an IServiceProvider interface with QueryInterface of IWebBrowserApp Get the IShellBrowser interface with QueryService of IServiceProvider This is the code: Func GetIShellBrowser( $hExplorer ) ; IShellWindows interface Local $pIShellWindows, $oIShellWindows CoCreateInstance( $tCLSID_ShellWindows, $NULL, $CLSCTX_ALL, $tRIID_IShellWindows, $pIShellWindows ) $oIShellWindows = ObjCreateInterface( $pIShellWindows, $sIID_IShellWindows, $dtag_IShellWindows ) ; Number of shell windows Local $iWindows $oIShellWindows.get_Count( $iWindows ) ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows - 1 $oIShellWindows.Item( $i, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next ; IServiceProvider interface Local $pIServiceProvider, $oIServiceProvider $oIWebBrowserApp.QueryInterface( $tRIID_IServiceProvider, $pIServiceProvider ) $oIServiceProvider = ObjCreateInterface( $pIServiceProvider, $sIID_IServiceProvider, $dtag_IServiceProvider ) ; IShellBrowser interface Local $pIShellBrowser $oIServiceProvider.QueryService( $tRIID_STopLevelBrowser, $tRIID_IShellBrowser, $pIShellBrowser ) $oIShellBrowser = ObjCreateInterface( $pIShellBrowser, $sIID_IShellBrowser, $dtag_IShellBrowser ) EndFunc Now it's easy to create the shell interfaces. The main interfaces are: Func GetShellInterfaces() Local $pIFolderView, $pIFolderView2, $pIPersistFolder2, $pIShellFolder, $pPidlFolder, $pPidlRel, $i = 0 ; IShellView interface $oIShellBrowser.QueryActiveShellView( $pIShellView ) $oIShellView = ObjCreateInterface( $pIShellView, $sIID_IShellView, $dtag_IShellView ) ; IFolderView interface $oIShellView.QueryInterface( $tRIID_IFolderView, $pIFolderView ) $oIFolderView = ObjCreateInterface( $pIFolderView, $sIID_IFolderView, $dtag_IFolderView ) If @OSVersion <> "WIN_XP" Then ; IFolderView2 interface (Vista and later) $oIShellView.QueryInterface( $tRIID_IFolderView2, $pIFolderView2 ) $oIFolderView2 = ObjCreateInterface( $pIFolderView2, $sIID_IFolderView2, $dtag_IFolderView2 ) EndIf ; IPersistFolder2 interface $oIFolderView.GetFolder( $tRIID_IPersistFolder2, $pIPersistFolder2 ) $oIPersistFolder2 = ObjCreateInterface( $pIPersistFolder2, $sIID_IPersistFolder2, $dtag_IPersistFolder2 ) $oIPersistFolder2.GetCurFolder( $pPidlFolder ) ; IShellFolder interface If ILIsEqual( $pPidlFolder, $pPidlAbsDesktop ) Then SHGetDesktopFolder( $pIShellFolder ) Else Local $pIParentFolder, $oIParentFolder, $pPidlRel SHBindToParent( $pPidlFolder, DllStructGetPtr( $tRIID_IShellFolder ), $pIParentFolder, $pPidlRel ) $oIParentFolder = ObjCreateInterface( $pIParentFolder, $sIID_IShellFolder, $dtag_IShellFolder ) $oIParentFolder.BindToObject( $pPidlRel, $NULL, $tRIID_IShellFolder, $pIShellFolder ) EndIf $oIShellFolder = ObjCreateInterface( $pIShellFolder, $sIID_IShellFolder, $dtag_IShellFolder ) ; Free memory used by $pPidlFolder _WinAPI_CoTaskMemFree( $pPidlFolder ) ; Wait for Explorer to refresh $pPidlRel = GetFocusedItem() While Not $pPidlRel And $i < 10 Sleep( 25 ) $pPidlRel = GetFocusedItem() $i += 1 WEnd ; Free memory used by $pPidlRel If $pPidlRel Then _ _WinAPI_CoTaskMemFree( $pPidlRel ) EndFunc Features The methods of the interfaces supports the following features: You can handle items in Windows Explorer: Get current folder, get all items, get/set selected items and get/set focused item. A selected file is opened by executing the InvokeCommand for the default item in the context menu. You can browse to a specific folder or a parent/child folder. You can set icon view mode. Functions AutomatingWindowsExplorer.au3 contains the two functions above. And it contains a number of functions to implement the features: GetCurrentFolder SetCurrentFolder CountItems GetItems GetFiles GetFolders GetPidls GetFocusedItem SetFocusedItem SetSelectedItem GetIconView SetIconView When the interfaces are created, the functions can be implemented with a few lines of code. This is the code for GetCurrentFolder and SetCurrentFolder: Func GetCurrentFolder() Local $pPidlAbs $oIPersistFolder2.GetCurFolder( $pPidlAbs ) Return $pPidlAbs EndFunc ; After this command $oIShellBrowser is the only valid interface object. To ; be able to use the other interfaces you must execute GetShellInterfaces(). Func SetCurrentFolder( $pPidl, $fFlag ) $oIShellBrowser.BrowseObject( $pPidl, BitOR( $SBSP_DEFBROWSER, $fFlag ) ) EndFunc For examples search the functions in Example.au3 and Example*.au3. Depending on parameters most functions can return PIDLs. Some functions return only PIDLs. In these cases you must free memory (_WinAPI_CoTaskMemFree) used by the PIDLs, when you have finished using the PIDLs. There are many more methods that are not implemented in these functions, and there are available interfaces that have not been created. Example Example.au3 demonstrates the features. Example folder contains scripts with functions used in the example. It's important that there is consistency between the interfaces, and the current folder in Windows Explorer. If the GUI loses and gets focus, it's checked if the current folder is changed. In that case the interfaces are updated to match the new folder. This is a picture of the GUI: Items and selected items are shown with _ArrayDisplay. The number of rows in the listview to the right is limited to 100. The listview can only be used for the buttons in the lower right group. The buttons in the lower left group are disabled, if there are more than 100 items in the folder. There is also a listview on the second tab item. It's limited to 100 rows, and can only be used for the Child folder button. You can also double click a child folder in the listview, to browse to this folder. Control Panel The example does not work for the Control Panel. The reason is that the child windows which are created for the Control Panel, are different from the child windows which are created for other folders. You can verify that with the UI Automation framework. Zipfile Example - include files used in example Includes - include files used for Automating Windows Explorer Example.au3 - Example For AutoIt 3.3.10 and later. Testet on Windows XP 32 bit and Windows 7 32/64 bit. Automating Windows Explorer.7z Examples in posts below Post 7 is a collection of small examples. Post 15 shows how to automate a search with UI Automation code. Post 31 shows how to execute a function on a double-click in empty space of the right pane window (the listview). The code contains UI Automation code. Post 38 is UI Automation code to make a selected item visible by scrolling the listview up or down.1 point
-
Just a little program I whipped up a couple of days ago, to fill a need. It has a few nice features. Basically it gives batch list ability, to any program that supports an input path on the command-line (%1 etc). It only supports drag & drop, and uses RunWait .... but feel free to adapt to your needs. Batch Create & Run v1.8.zip BUGFIX OLDER DOWNLOADS Older Screenshot NOTE - My usage was with a BAT file, so even though I coded for EXE files as well, that element remains untested, but should work. EDIT - Of course, if you use a DOS (console) EXE, you might want to add a checkbox to specify that the @Comspec method should be used. Perhaps I will add that ... one day. DONE1 point
-
The easiest way is $s = "abcde12345abcde12345" $s = StringRegExpReplace($s, '([c3])', "*$1*") Msgbox(0,"", $s) For this, you can just add an alternation in the 2nd pattern from jchd Local $sClean = StringRegExpReplace($s, "(?x) (\x1B \[ (?:\s*\d*\s*;?)* [[:alpha:]]) | [\x1E\x0A]", "") MsgBox(0, "Pure text", $sClean)1 point
-
Auto Write Notes From Clipboard
Draygoes reacted to JLogan3o13 for a topic
As an FYI we do have a snippets section dedicated to "small, reusable bits of code"1 point -
Need help for a game script!
mLipok reacted to JLogan3o13 for a topic
Maybe if we make the forum rules link bright and blinking people will actually read them...1 point -
Here a modified examples from here #include <Color.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIConstants.au3> #include <WinAPISysWin.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Global $iH = 150, $iW = $iH ; Initialize GDI+ _GDIPlus_Startup() Global $hGUI = GUICreate("GDI+ Countdown Circle", 0, 0, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hHBitmap, $hOld Global $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; Using antialiasing _GDIPlus_GraphicsSetSmoothingMode($hGfx, 2) ; Create a Pen object Global $pen_size = Floor($iH / 6) Global $hPen = _GDIPlus_PenCreate(0, $pen_size) ; Create String objects Global $fsize = Floor($iH / 10) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("Arial") Global $hFont = _GDIPlus_FontCreate($hFamily, $fsize) Global $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4) Global $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION) $tSize.X = $iW $tSize.Y = $iH $tBlend.Alpha = 255 $tBlend.Format = 1 Global Const $hScrDC = _WinAPI_GetDC($hGUI), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ; Setup font parameters Global $angle = 360 Global $countdown_t = 20 ;seconds Global $countdown = $countdown_t Global $t_calc = Round(1000 * ($countdown_t + 1) / 360, 0) Global $timer = TimerInit() Global $flash_color[3], $fx $flash_color[1] = 0x00 $flash_color[2] = 0x00 Global $z = 1 While 1 _GDIPlus_GraphicsClear($hGfx, 0x00000000) _GDIPlus_PenSetColor($hPen, 0xFFE0FFE0) _GDIPlus_GraphicsDrawEllipse($hGfx, $pen_size / 2, $pen_size / 2, $iW - $pen_size, $iH - $pen_size, $hPen) If $countdown > 5 Then _GDIPlus_PenSetColor($hPen, 0xFF00FF00) Else $flash_color[0] = Max(0xB0, Abs(0xFF * Sin($z / (0xC0 * $countdown)))) _GDIPlus_PenSetColor($hPen, "0xFF" & Hex(_ColorSetRGB($flash_color), 6)) EndIf _GDIPlus_GraphicsDrawArc($hGfx, $pen_size / 2, $pen_size / 2, $iW - $pen_size, $iH - $pen_size, -90, $angle, $hPen) $fx = StringLen(StringFormat("%.2f", $countdown)) * $fsize / 2.5 $tLayout.x = $iW / 2 - $fx $tLayout.y = $iH / 2 - $fsize * 0.75 _GDIPlus_GraphicsDrawStringEx($hGfx, StringFormat("%.2f", $countdown), $hFont, $tLayout, $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hHBitmap) If TimerDiff($timer) > $t_calc Then $countdown -= $t_calc / 1000 $timer = TimerInit() $angle = 360 * $countdown / $countdown_t If $countdown <= 0 Then $countdown = $countdown_t $angle = 360 $timer = TimerInit() EndIf EndIf $z += 2 Sleep(10) WEnd Func Max($a, $b) Return ($a > $b ? $a : $b) EndFunc Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $hGui) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func _Exit() ; Clean up _GDIPlus_BrushDispose($hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PenDispose($hPen) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGfx) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_DeleteDC($hMemDC) ; Shutdown GDI+ _GDIPlus_Shutdown() Exit EndFunc1 point
-
NP, if you want to test your "State" spreadsheet, just use the following: __Excel_FilterRange(@ScriptDir & "\Test\Excel2.xls", "*State*", 1) @ScriptDir & "\Test\Excel2.xls = Name of Spreadsheet you want to save the results to "*State*" = Filter where Cell "contains" the word State 1 = The Column where you want to apply the filter1 point
-
@DigDeep Sorry for the delay, sorry I didn't see your CopyandPaste function which is required for copying formatting etc... So here is a different method, just using Excel filtering and Copy and Paste to new Workbooks, again the files Excel2 - Excel5 do not have to exist, if they do the data will be appended to the end of sheet. #include <Array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open(False) Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test\Excel1.xls", True) __Excel_FilterRange(@ScriptDir & "\Test\Excel2.xls", "Grade A", 4) __Excel_FilterRange(@ScriptDir & "\Test\Excel3.xls", "Grade B", 4) __Excel_FilterRange(@ScriptDir & "\Test\Excel4.xls", "Grade C", 4) __Excel_FilterRange(@ScriptDir & "\Test\Excel5.xls", "Grade D", 4) _Excel_BookClose($oWorkbook) Func __Excel_FilterRange($_sWorkbook, $_vFilterCriteria, $_iFilterColumn) Local $bWorkbookNew = False _Excel_FilterSet($oWorkbook, Default, Default, $_iFilterColumn, $_vFilterCriteria) If FileExists($_sWorkbook) Then $oXLWorkbook = _Excel_BookOpen($oExcel, $_sWorkbook, False) Else $oXLWorkbook = _Excel_BookNew($oExcel) EndIf ;~ Get the number of rows in the current Excel document Local $iWorkbookRows = $oXLWorkbook.ActiveSheet.UsedRange.Rows.Count If $iWorkbookRows = 1 Then $bWorkbookNew = True ;~ Check if this is a New Workbook or Existing Workbook If $bWorkbookNew Then ;~ Add the Excel Header to the Array _Excel_RangeCopyPaste($oWorkbook.ActiveSheet, $oWorkbook.ActiveSheet.Usedrange.SpecialCells($xlCellTypeVisible), $oXLWorkbook.ActiveSheet.Range("A1")) _Excel_BookSaveAs($oXLWorkbook, $_sWorkbook) Else _Excel_RangeCopyPaste($oWorkbook.ActiveSheet, $oWorkbook.ActiveSheet.Usedrange.OffSet(1).SpecialCells($xlCellTypeVisible), $oXLWorkbook.ActiveSheet.Range("A" & $iWorkbookRows + 1)) EndIf _Excel_BookClose($oXLWorkbook, True) EndFunc1 point
-
Instead of walking into hazardous wild ways I would personally use a 2nd step as a workaround (BTW much easier to manage, probably) #Include <Array.au3> Local $s = "Hello, " & Chr(27) & "[ 40;31mThis is red on black " & chr(13) & _ Chr(27) & "[ 47;32m And this is green on white" & chr(10) & _ Chr(27) & "[ 47 ; 32 m And this is also green on white (more spaces)" & _ Chr(27) & "[1234567890123456798Kvftio this matches the definition, albeit probably invalid ANSI escape" & _ Chr(27) & "[ 47;32 !!!! this is not an ANSI sequence" & _ Chr(27) & "[ z but this one is OK and final." Local $aRes = StringRegExp($s, "(?x)" & _ "(?(DEFINE) (?<ANSI_Escape> \[ (?:\s*\d*\s*;?)* [[:alpha:]]) )" & _ "(?| \x1B (?&ANSI_Escape) | (?:[^\x1B] (?!(?&ANSI_Escape)))+ )", 3) ;_ArrayDisplay($aRes, "Mixed results") $s2 = _ArrayToString($aRes, "*") $s2 = StringRegExpReplace($s2, '(?=[\r\n])', "*") $aRes2 = StringSplit($s2, '*', 2) _ArrayDisplay($aRes2, "Mixed results2") ;check ;Msgbox(0,"", "chr(" & asc($aRes2[3]) & ")" &@cr& "chr(" & asc($aRes2[6]) & ")" )1 point
-
AutoIt v3.3.14.5 has been released. Just a small bug fix to the updater script. Download it here. Complete list of changes: History1 point
-
FileReadLine - can you read second last line?
PoojaKrishna reacted to Melba23 for a topic
Danyfirex, It is very inefficient - because you are reading every line in the file. Take a look at these other ways of doing it: #include <File.au3> $sFile = "M:ProgramAutoIt3IncludeWinAPI.au3" ; Adjust to your include path Local $hFile = FileOpen($sFile, 0) If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf MsgBox(0, "", LSL($hFile)) FileClose($hFile) MsgBox(0, "", _Read_Pen_Line()) MsgBox(0, "", _Read_To_Array()) Func LSL($hFilehandle) $iBegin = TimerInit() Local $i = 0 While 1 Local $line = FileReadLine($hFilehandle) If @error = -1 Then ExitLoop $i += 1 WEnd $lastSline = FileReadLine($hFilehandle, $i - 1) ConsoleWrite(TimerDiff($iBegin) & @CRLF) Return $lastSline EndFunc ;==>LSL Func _Read_Pen_Line() ; Count the lines and just read the one we want $iBegin = TimerInit() $iCount = _FileCountLines($sFile) $lastSline = FileReadLine($sFile, $iCount - 1) ConsoleWrite(TimerDiff($iBegin) & @CRLF) Return $lastSline EndFunc Func _Read_To_Array() ; Read into an aray and then just extrat the line we want $iBegin = TimerInit() Local $aLines _FileReadToArray($sFile, $aLines) ConsoleWrite(TimerDiff($iBegin) & @CRLF) Return $aLines[$aLines[0] - 1] EndFunc When I run this I find that the first function takes well over twice as long as the last - and nearly twice as long as the second. I would go for the array version each time. M231 point -
I have made such a script. Very useful. Here's a simple function to do so. Requires admin rights (locally and remotely of course).- _GetLocalAdmins() Func _GetLocalAdmins($host = @ComputerName) Dim $filter[1] = ["group"] $colGroups = ObjGet("WinNT://" & $host & "") If Not IsObj($colGroups) Then Return 0 $colGroups.Filter = $filter For $objGroup In $colGroups If $objGroup.name = "Administrators" Then ConsoleWrite($host & @CRLF) For $objUser In $objGroup.Members ConsoleWrite("--" & $objUser.name & @CRLF) Next ConsoleWrite(@CRLF & @CRLF) EndIf Next EndFunc1 point