Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/16/2017 in all areas

  1. It does, however so does the code Matt posted from Big Daddy, although the code was strange to me, basically it opens two Word docs, but only uses one of the docs to post the data from the gui, it then uses Word spell checker and returns the spell checker information to a second AutoIt Gui (which is hidden). Unfortunately I couldn't get the code working correctly, so thought I'd just write a simpler version utilizing the Word spell checker and dictionary.
    2 points
  2. 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
  3. Try this: Func decode($n) Static $table = ["cat", "dog"] Return $table[$n] EndFunc Local $string = "Hello this is a &0; and this is a &1;" Local $decoded = Execute("'" & StringRegExpReplace($string, "&(\d+);", "' & decode(\1) & '") & "'") MsgBox(0, "Result", $decoded) If your context needs a condom in case of unsure input, prefer that: Func decode($n) Static $table = ["cat", "dog"] Return ($n < 0 Or $n >= UBound($table)) ? '(null)' : $table[$n] EndFunc
    1 point
  4. Here you are: SSCtrlHover.7z And the example: #AutoIt3Wrapper_UseX64=y #include "SSCtrlHover_v3.au3" GUICreate(@AutoItVersion) $idLbl1 = GUICtrlCreateLabel("Label 1", 5, 5) SSCtrlHover_Register($idLbl1, "FnNormal", 0, "FnHover", 0, "FnActive", 0, "FnClick", 0) $idLbl2 =GUICtrlCreateLabel("Label 2", 5, 35) SSCtrlHover_Register($idLbl2, "FnNormal", 0, "FnHover", 0, "FnActive", 0, "FnClick", 5) GUISetState() While GUIGetMsg() <> -3 Sleep(10) WEnd Func FnNormal($idCtrl, $hWnd, $vData) ConsoleWrite(@CRLF & "Normal/Leave " & $idCtrl) EndFunc Func FnHover($idCtrl, $hWnd, $vData) ConsoleWrite(@CRLF & "Hover " & $idCtrl) EndFunc Func FnActive($idCtrl, $hWnd, $vData) ConsoleWrite(@CRLF & "Active " & $idCtrl) EndFunc Func FnClick($idCtrl, $hWnd, $vData) ConsoleWrite(@CRLF & "CLICK! " & $idCtrl & " - " & $hWnd & " - " & $vData) EndFunc
    1 point
  5. Yep, I can understand . P.S Congratulations on the 200th post
    1 point
  6. I admit I didn't have performance in mind when I was looking for a solution....usually when I am throwing a project together I use the first working answer I come across P.S. This is my 200th post
    1 point
  7. Right now I'm sitting in front of my Windows PC and try to find out what causes the problem. I tested: Section break (next page) - works as expected (finds all occurrences) Section break (continuous) - works as expected (finds all occurrences) Column break - works as expected (finds all occurrences) To be continued
    1 point
  8. TheDcoder

    AutoIt Snippets

    Here is something that I created while _IELoadWait wasn't working with the job in hand. Some explanation first, I was working on a website automation project, I decided to use the IE UDF naturally. The website that I am trying to automate uses Javascript to log me in (no page refresh, no submitting form to new page etc.) so _IELoadWait do any good for me . Thanks to @TheSaint's excellent idea of checking for a piece of text that only appears after logging in (usually the username or the logout text). I present you _IEWaitForTagText! ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IEWaitForTagText ; Description ...: Waits for a HTML tag to appear with the specified text ; Syntax ........: _IEWaitForTagText($oObject, $sTagName, $sTagText[, $iTimeout = 0[, $bNoError = True]]) ; Parameters ....: $oObject - Object related to IE (Any Window, Frame, IFrame or any DOM object). ; $sTagName - Name of the HTML tag (p, img, tr, etc). ; $sTagText - The (inner) text of the tag to wait for. ; $iTimeout - [optional] Timeout for the wait in milliseconds. Default is 0 (No timeout). ; $bNoError - [optional] Temporarily disable IE errors messages in the console. Default is True. ; Return values .: Success: The DOM element's object ; Failure: False and @error is set to 1 ; Author ........: Damon Harris (TheDcoder) ; Remarks .......: 1. Failure is impossible if $iTimeout is set to 0 ; 2. This is how $bNoError works: ; * If $bNoError is True, then _IEErrorNotify(False) is called and _IEErrorNotify(True) is called after the wait. ; * If $bNoError is True and _IEErrorNotify() is False, nothing will be changed. ; * If $bNoError is False, nothing will be changed. ; Related .......: _IELoadWait ; Link ..........: https://git.io/vHxOT ; Example .......: _IEWaitForTagText($oIE, "p", "logout") ; =============================================================================================================================== Func _IEWaitForTagText($oObject, $sTagName, $sTagText, $iTimeout = 0, $bNoError = True) Local $oTags, $hTimer, $sText, $bTurnOnNotify = False If Not $iTimeout = 0 Then $hTimer = TimerInit() If $bNoError And _IEErrorNotify() Then _IEErrorNotify(False) $bTurnOnNotify = True EndIf Do $oTags = _IETagNameGetCollection($oObject, $sTagName) For $oTag In $oTags $sText = _IEPropertyGet($oTag, "innertext") If @error Then ContinueLoop If ($sText = $sTagText) Then If $bTurnOnNotify Then _IEErrorNotify(True) Return $oTag EndIf Sleep(10) Next Until ($iTimeout = 0) ? False : (TimerDiff($hTimer) >= $iTimeout) If $bTurnOnNotify Then _IEErrorNotify(True) Return SetError(1, 0, False) EndFunc I only did some basic testing, I would appreciate if someone could code a simple HTML page with Javascript which can create a new element after 3 secs and test this function in that page to see if it works. That would make a great example! Enjoy, TD
    1 point
  9. Here is my spell check function: #include <GuiEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Word.au3> Local $hGui = GUICreate("Spell Checker", 461, 212) Local $idString = GUICtrlCreateEdit('“To be, or not to be…that is the question” This wellknown utterance has been the source of both mystery and wonderment for students around the world since the turn of the 16th century—arguably the zenith of Shakespeare’s creative output. However, the mere ubiquity of this phrase fails to answer some basic questions about it’s rather context. Where did it come from what does it mean? The first of these questions (where does it come from?) can be answered fairly easily: from Shakespeare’s famous play Hamlet.', 7, 23, 330, 81, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL)) Local $idSpellCheck = GUICtrlCreateButton("Check Spelling", 346, 23, 107, 22) Local $idUpdate = GUICtrlCreateEdit('', 7, 123, 330, 81, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL)) Local $idCloseGui = GUICtrlCreateButton("Close", 346, 183, 107, 22) ControlFocus($hGui, "", $idSpellCheck) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGui Exit Case $idSpellCheck GUICtrlSetData($idUpdate, _SpellCheck(GUICtrlRead($idString))) EndSwitch WEnd Func _SpellCheck($sStringCheck) Local Const $wdDialogToolsSpellingAndGrammar = 828 ;~ Word Spelling and Grammar Dialog Window Local $oWord, $oDoc, $sSpellCheck = $sStringCheck $oWord = _Word_Create(False) With $oWord ;.Visible = False $oDoc = .Documents.Add .Selection.Text = $sSpellCheck .Dialogs($wdDialogToolsSpellingAndGrammar).Show $sSpellCheck = .Selection.Text $oDoc.Close($wdDonotSaveChanges) .Quit($wdDonotSaveChanges) EndWith Return $sSpellCheck = "" ? $sStringCheck : $sSpellCheck EndFunc
    1 point
  10. You have your Return statement in the GET_LANG function in the wrong place, returning the wrong thing. You don't need a Return in that function anyway, because you're not reading what you're returning.
    1 point
  11. Use .SelectNodes on the locale, and then loop through what's returned...you can continually add into the same variable by $sLocale &= $oBlah.text
    1 point
  12. Fulano

    Increment a Letter

    You have to cast it to an ascii value and then increment, then switch it back to a character. Keep in mind this will not wrap around from Z to a or z to A, so be sure to do some checks on your data so you don't end up trying to access drive [:\ Chr (Asc ("A") + 1) Edit: Woot! props to Mavis Beacon
    1 point
×
×
  • Create New...