Leaderboard
Popular Content
Showing content with the highest reputation on 05/27/2019 in all areas
-
Basic example, look at the help file for more information: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Local $aWndPos Local $hWnd = GUICreate("Form2", 900, 420, -1, -1, Default + $WS_MAXIMIZE) GUISetBkColor(0x333333) Local $idFilemenu = GUICtrlCreateMenu("&File") Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu) Local $idInput = GUICtrlCreateInput("", 210, 10, 660, 360) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) Local $idButton = GUICtrlCreateButton("Button1", 10, 10, 190, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT)) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MAXIMIZE ;~ Uncomment lines below if you wish to have the inputbox take up the entire window ;~ $aWndPos = WinGetPos($hWnd) ;~ GUICtrlSetPos($idInput, 11, 11, $aWndPos[2] - 54, $aWndPos[3] - 99) Case $idExititem Exit EndSwitch WEnd1 point
-
WebDriver UDF - Help & Support
Letraindusoir reacted to Gianni for a topic
You could try this visual tool to get "selectors" of DOM objects: https://www.autoitscript.com/forum/topic/195777-ie-dom-elements-visual-selector-tool/ The selectors obtained by this tool can be used in this WebDriver UDF. Example: suppose you store in the variable $sMyCssSelector the string of the CSS selector retrieved with the above visual tool, you can then use that variable in the _WD_FindElement function() in this way: $RefElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, $sMyCssSelector)1 point -
such kind of images (strips) can also be handled by the _GUIImageList* functions. Have a look to this link for an example of use https://www.autoitscript.com/forum/topic/165083-question-on-_guiimagelist-usage/. In your case posted here, since you want to use it with the TraySetIcon() function, and since that function accepts a filename as parameter, you should convert the frames of the strip at least in single icons, and save them to disk, or, by the workaround from this post (https://www.autoitscript.com/forum/topic/97902-trayseticon-with-handle/) you can manage it by the image handle. here a quick and dirty example: #include <GuiImageList.au3> #include <WinAPI.au3> #include <GDIPlus.au3> ; ---------------------- ; https://www.autoitscript.com/forum/topic/97902-trayseticon-with-handle/ Global Const $tagNOTIFYICONDATAW = _ 'dword cbSize;' & _ 'hwnd hWnd;' & _ 'uint uID;' & _ 'uint uFlags;' & _ 'uint uCallbackMessage;' & _ 'hwnd hIcon;' & _ 'wchar szTip[128];' & _ 'dword dwState;' & _ 'dword dwStateMask;' & _ 'wchar szInfo[256];' & _ 'uint uVersion;' & _ 'wchar szInfoTitle[64];' & _ 'dword dwInfoFlags;' ; & $tagGUID Global $tNID = DllStructCreate($tagNOTIFYICONDATAW), $pNID = DllStructGetPtr($tNID) Global $hWnd = WinGetHandle(AutoItWinGetTitle()), $hIcon ; ---------------------- Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "Quit") Example() Func Example() _GDIPlus_Startup() ; Load Image Local $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & ".\Bitmap351.bmp") Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ; convert GDIPlus bitmap to GDI format which is usable for _GUIImageList* functions ; there are 31 images (frames) in strip Local $iFramesInStrip = 31 Local $iFrameWidth = _GDIPlus_ImageGetWidth($hBitmap) / $iFramesInStrip Local $iFrameHeight = _GDIPlus_ImageGetHeight($hBitmap) _GDIPlus_BitmapDispose($hBitmap) ; release GDIPlus bitmap because not needed anymore $hImages = _GUIImageList_Create($iFrameWidth, $iFrameHeight, 5) ; create image list in 32-bit which supports transparency _GUIImageList_Add($hImages, $hGDIBitmap) ; add the whole strip to the ImageList ; Create a little GUI $hGUI = GUICreate("Demo", 150, 80) GUICtrlCreateLabel("see the tray icon...", 10, 10, 140) GUICtrlSetFont(-1, 12) GUICtrlCreateButton("Quit", 40, 40, 80) GUICtrlSetOnEvent(-1, "Quit") GUISetState(@SW_SHOW) Do For $i = 0 To $iFramesInStrip - 1 ; loop all frames $hIcon = _GUIImageList_GetIcon($hImages, $i) DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID)) DllStructSetData($tNID, 'hWnd', $hWnd) ;HWnd($hGUI)) ; DllStructSetData($tNID, 'uID', 1) DllStructSetData($tNID, 'uFlags', 2) DllStructSetData($tNID, 'hIcon', $hIcon) _Shell_NotifyIcon(1, $pNID) ; TraySetIcon() Sleep(250) Next Until False EndFunc ;==>Example Func Quit() ; free memory _GDIPlus_Shutdown() _WinAPI_DestroyIcon($hIcon) GUIDelete() Exit EndFunc ;==>Quit Func _Shell_NotifyIcon($iMessage, $pdata) Local $aRet $aRet = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', $pdata) If @error Then Return SetError(1, 0, 0) Return $aRet[0] EndFunc ;==>_Shell_NotifyIcon1 point
-
@Letraindusoir I don't have any plans to create such a tool. Besides, you should really get accustomed to using the browser's built-in dev tools. 😛1 point
-
Capturing Array into XML tagging
KickStarter15 reacted to mikell for a topic
It's correct. But if you want the whole thing to work in both cases, this must be mentioned in the expression by putting 2 alternations #Include <Array.au3> Local $astr[1] = ["Wagner W., Raudsepp M., Holtz P., Sen R., (2017) Essence politics Identity work and stereotyping in inter-group relations. Haward C., Matt C., The social psychology of everyday politics. London. Routledge. 121-150."] ; Local $astr[1] = ["Wagner, W., Raudsepp, M., Holtz, P., Sen, R., (2017) Essence politics Identity work and stereotyping in inter-group relations. Haward, C., Matt, C., The social psychology of everyday politics. London. Routledge. 121-150."] $n = 0 For $str In $astr $res = StringRegExp($str, '(*UCP)(?x) (?| ' & _ ' ([A-Za-z]+)\h([A-Z][^,]+),\h? ' & _ ; names, Eds , case #1 ' | ([A-Za-z][^.]+),\h([A-Z][^,]+),\h? ' & _ ; names, Eds , case #2 ' | ([[a-z\h.]+),\h? ' & _ ; et al ' | \((\d+)\)\.?\h? ' & _ ; year ' | ([A-Z][^.]+\.\h) ' & _ ; ChapterTitle, PubLoc, Name ' | (\d+[\(\);.-]) ' & _ ; vol, issue, pages ' | (?:https?://)?(\w+\S+)$) ' , 3) ; url $n += 1 _ArrayDisplay($res, $n) Local $i = 0, $s = '<File xml:id="1110">' & @crlf & _ '<citation type="journal" xml:id="00001">' & @crlf While $i < UBound($res) AND StringRegExp($res[$i], '^[A-Z]') $s &= '<Person>' & '<familyName>' & $res[$i] & '</familyName>, ' & _ '<givenNames>' & $res[$i+1] & '</givenNames>' & '</Person>, ' & @crlf $i += 2 Wend If $i < UBound($res) AND StringRegExp($res[$i], '^[a-z\h.]+$') Then $s &= $res[$i] & @crlf $i += 1 EndIf If $i < UBound($res) AND StringIsDigit($res[$i]) Then $s &= '(<pubYear year="' & $res[$i] & '">' & $res[$i] & '</pubYear>);' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringIsUpper(StringLeft($res[$i], 1)) Then $s &= '<chapterTitle>' & $res[$i] & '</chapterTitle>. ' & @crlf $i += 1 EndIf While $i < UBound($res) AND StringRegExp($res[$i], '^[A-Z]\S*$') $s &= '<editor>' & '<givenNames>' & $res[$i] & '</givenNames>, ' & _ '<familyName>' & $res[$i+1] & '</familyName>' & '</editor>, ' & @crlf $i += 2 Wend If $i < UBound($res) AND StringIsUpper(StringLeft($res[$i], 1)) Then $s &= '<OtherTitle>' & $res[$i] & '</OtherTitle>. ' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringIsUpper(StringLeft($res[$i], 1)) Then $s &= '<Location>' & $res[$i] & '</Location>. ' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringIsUpper(StringLeft($res[$i], 1)) Then $s &= '<LocationName>' & $res[$i] & '</LocationName>. ' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringRegExp($res[$i], '^\d+-$') Then $s &= '<pageFirst>' & StringTrimRight($res[$i], 1) & '</pageFirst>' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringRegExp($res[$i], '^\d+\.$') Then $s &= '?<pageLast>' & StringTrimRight($res[$i], 1) & '</pageLast>.' & @crlf $i += 1 EndIf If $i < UBound($res) AND StringInStr($res[$i], "doi") > 0 Then $s &= '<url href="' & $res[$i] & '">' & $res[$i] & '</url>' & @crlf $i += 1 ElseIf $i < UBound($res) AND StringInStr($res[$i], "www") > 0 Then $s &= '<url href="' & $res[$i] & '">' & $res[$i] & '</url>' & @crlf $i += 1 ElseIf $i < UBound($res) AND StringInStr($res[$i], "http") > 0 Then $s &= '<url href="' & $res[$i] & '">' & $res[$i] & '</url>' & @crlf $i += 1 EndIf $s &= '</citation>' & @crlf $s &= '</File>' & @crlf Msgbox(0, $n, $s) Next1 point -
WebDriver UDF - Help & Support
Letraindusoir reacted to Danp2 for a topic
Take a look at the DemoActions function in wd_demo.au3 for an example of moving the mouse pointer to an element. As far as giving an element focus, just setting its value with _WD_ElementAction should be enough. You could send it a click with _WD_ElementAction as well.1 point -
WebDriver UDF - Help & Support
Letraindusoir reacted to Danp2 for a topic
First guess would be in the "goog:chromeOptions" of the DesiredCapabilities parameter that gets passed to _WD_CreateSession. You'll need to experiment to see what works. ; Name ..........: _WD_LoadWait ; Description ...: Wait for a browser page load to complete before returning Can you provide an example of where this is required? Take a look at _WD_ElementAction with the "text" command.1 point -
Radio menuitems not checked automatically by click
MONaH-Rasta reacted to Melba23 for a topic
MONaH-Rasta, That was a fun bit of debugging! The problem seems to be using the default menu along with items with the $TRAY_ITEM_RADIO style. If you get rid of the default menu everything seems to work normally: #include <TrayConstants.au3> Opt("TrayMenuMode", 1) ; No default menu $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, $TRAY_CHECKED) $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_CHECKED) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) TrayCreateItem('', $iTrayMenu1) ; Needed to close radio group $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_CHECKED) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) TrayCreateItem('', $iTrayMenu2) ; Needed to close radio group $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, $TRAY_CHECKED) TrayCreateItem('') $mExit = TrayCreateItem("Exit") ; Needed because there is no default menu While 1 Switch TrayGetMsg() Case $mExit Exit EndSwitch WEnd Which works fine for me - how about you? M231 point -
The idea to execute a function when you click in empty space is very interesting. In this example a mouse hook is used to detect double click in empty space of the listview in Windows Explorer right pane window (or File Explorer as it's called in Windows 10). Then the Back button in the navigation toolbar is clicked to navigate to the previous folder. You can open several Explorer windows. If you limit the empty space to the listview in the right pane window it's easy to detect empty space: In empty space of a listview the control under the mouse is the listview itself. If it isn't empty space the control under the mouse is a listview item or a child control of a listview item eg. an edit control. ;#AutoIt3Wrapper_UseX64=n #include <WinAPI.au3> #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Global $hHook, $hRightPaneWnd Example() Func Example() ; Press Esc to quit HotKeySet( "{ESC}", "Quit" ) OnAutoItExitRegister( "OnAutoItExit" ) ; Low level mouse hook to catch double clicks: Executes LowLevelMouseProc() on double click $hHook = _WinAPI_SetWindowsHookEx( $WH_MOUSE_LL, DllCallbackGetPtr( DllCallbackRegister( "LowLevelMouseProc", "long", "int;wparam;lparam" ) ), _WinAPI_GetModuleHandle( 0 ) ) LowLevelMouseProc( 0, 0, 0 ) ; Initialize $hTimer, $iDoubleClickSpeed and $oUIAutomation variables ; Wait for double clicks While 1 Sleep( 50 ) WEnd EndFunc Func Quit() Exit EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx( $hHook ) EndFunc Func LowLevelMouseProc( $iCode, $wParam, $lParam ) Static $hTimer = TimerInit(), $iDoubleClickSpeed = 0, $hExplorer, $fXP = ( @OSVersion = "WIN_XP" ) Static $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If $iDoubleClickSpeed = 0 Then $iDoubleClickSpeed = RegRead( "HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed" ) If @error Then $iDoubleClickSpeed = 500 EndIf If $iCode = 0 And $wParam = 0 And $lParam = 0 Then Return If $iCode < 0 Then Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) If $wParam = 0x0201 Then ; 0x0201 = $WM_LBUTTONDOWN If TimerDiff( $hTimer ) > $iDoubleClickSpeed Then ; First click ; Any open Explorer windows? Windows Explorer on XP, Vista, 7, 8, 10 Local $aExplorer = WinList( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If $aExplorer[0][0] = 0 Then ConsoleWrite( "No open Explorer windows" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ; Get a window to check that mouse click is inside an Explorer right pane ; listview. We want the same window as returned by _WinAPI_WindowFromPoint ; for a point inside an Explorer right pane listview. Local $iExplorer = 0 ReDim $aExplorer[$aExplorer[0][0]+1][3] For $i = 1 To $aExplorer[0][0] $hRightPaneWnd = 0 GetRightPaneWnd( $aExplorer[$i][1] ) If $hRightPaneWnd Then $aExplorer[$i][2] = $hRightPaneWnd $iExplorer += 1 EndIf Next If Not $iExplorer Then _ Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) ; _WinAPI_WindowFromPoint is used to check if a mouse click is inside an Explorer listview ; _WinAPI_WindowFromPoint returns the proper handle only if Explorer is the topmost window Local $tPoint = _WinAPI_GetMousePos() Local $hWindow = _WinAPI_WindowFromPoint( $tPoint ) For $i = 1 To $aExplorer[0][0] If $hWindow = $aExplorer[$i][2] Then ExitLoop Next If $i > $aExplorer[0][0] Then ConsoleWrite( "Mouse click not inside Explorer listview" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ; Explorer handle $hExplorer = $aExplorer[$i][1] ; Reset timer to check if it's a double click $hTimer = TimerInit() Else ; Double click ConsoleWrite( "Double click inside Explorer listview" & @CRLF ) ; Get control type and class name Local $pElement, $oElement, $iControlType, $sClassName $oUIAutomation.ElementFromPoint( _WinAPI_GetMousePos(), $pElement ) $oElement = ObjCreateInterface( $pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oElement.GetCurrentPropertyValue( $UIA_ControlTypePropertyId, $iControlType ) $oElement.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sClassName ) ; If it's a double click in empty space of a listview the control under the mouse is the listview itself. ; A double click not in empty space would have been a double click at a listview item or a child control. ; Double click in empty space of listview? If Not ( $iControlType = $UIA_ListControlTypeId _ And ( $sClassName = "UIItemsView" Or $sClassName = "SysListView32" ) ) Then ConsoleWrite( "Double click not in empty space of listview" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "Double click in empty space of listview" & @CRLF ) ; Perform double click action ; Go to previous folder by clicking the Back button in the navigation toolbar ; Explorer object Local $pExplorer, $oExplorer $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer ) ; $hExplorer handle is calculated above $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oExplorer ) Then ConsoleWrite( "$oExplorer ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$oExplorer OK" & @CRLF ) Local $pCondition1, $pCondition2, $pCondition Local $pButton, $oButton If $fXP Then ; Windows XP ; The Back button is the first splitbutton ; Condition to find Back button $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_SplitButtonControlTypeId, $pCondition ) If Not $pCondition Then ConsoleWrite( "$pCondition (button) ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$pCondition (button) OK" & @CRLF ) ; Find Back button $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pButton ) $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton ) Then ConsoleWrite( "$oButton ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$oButton OK" & @CRLF ) Else ; Other Windows versions ; The Back button is the first button in the first ToolbarWindow32-class toolbar ; Condition to find toolbar $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ToolBarControlTypeId, $pCondition1 ) If Not $pCondition1 Then ConsoleWrite( "$pCondition1 (toolbar) ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$pCondition1 (toolbar) OK" & @CRLF ) ; Condition to find ToolbarWindow32-class $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "ToolbarWindow32", $pCondition2 ) If Not $pCondition2 Then ConsoleWrite( "$pCondition2 (toolbar) ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$pCondition2 (toolbar) OK" & @CRLF ) ; And condition, both conditions $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition ) If Not $pCondition Then ConsoleWrite( "$pCondition (toolbar) ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$pCondition (toolbar) OK" & @CRLF ) ; Find toolbar Local $pToolbar, $oToolbar $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pToolbar ) $oToolbar = ObjCreateInterface( $pToolbar, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oToolbar ) Then ConsoleWrite( "$oToolbar ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$oToolbar OK" & @CRLF ) ; Condition to find Back button $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition ) If Not $pCondition Then ConsoleWrite( "$pCondition (button) ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$pCondition (button) OK" & @CRLF ) ; Find Back button $oToolbar.FindFirst( $TreeScope_Descendants, $pCondition, $pButton ) $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oButton ) Then ConsoleWrite( "$oButton ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$oButton OK" & @CRLF ) EndIf ; Button enabled? Local $bEnabled $oButton.CurrentIsEnabled( $bEnabled ) If Not $bEnabled Then ConsoleWrite( "Disabled" & @CRLF & @CRLF ) If $bEnabled Then ; Get Invoke object Local $pInvoke, $oInvoke $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke ) $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvoke ) Then ConsoleWrite( "$oInvoke ERR" & @CRLF & @CRLF ) Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndIf ConsoleWrite( "$oInvoke OK" & @CRLF & @CRLF ) ; Invoke (click) button $oInvoke.Invoke() EndIf EndIf EndIf Return _WinAPI_CallNextHookEx( $hHook, $iCode, $wParam, $lParam ) EndFunc ; The window of interest is the child of the SHELLDLL_DefView-class window. ; This window is one of the right pane windows which contains the listview. ; The window is the same as returned by _WinAPI_WindowFromPoint function. Func GetRightPaneWnd( $hParent ) If Not $hParent Then Return Local $hChild = _WinAPI_GetWindow( $hParent, $GW_CHILD ) While $hChild If _WinAPI_GetClassName( $hChild ) = "SHELLDLL_DefView" Then $hRightPaneWnd = _WinAPI_GetWindow( $hChild, $GW_CHILD ) ; A SysListView32-class listview is three levels down If _WinAPI_GetClassName( $hRightPaneWnd ) <> "DirectUIHWND" Then $hRightPaneWnd = _WinAPI_GetWindow( $hRightPaneWnd, $GW_CHILD ) $hRightPaneWnd = _WinAPI_GetWindow( $hRightPaneWnd, $GW_CHILD ) $hRightPaneWnd = _WinAPI_GetWindow( $hRightPaneWnd, $GW_CHILD ) EndIf $hChild = 0 EndIf GetRightPaneWnd( $hChild ) $hChild = _WinAPI_GetWindow( $hChild, $GW_HWNDNEXT ) WEnd EndFunc If you run the example in SciTE you should see output similar to this in the console: No open Explorer windows Mouse click not inside Explorer listview Double click inside Explorer listview Double click not in empty space of listview Double click inside Explorer listview Double click in empty space of listview $oExplorer OK $pCondition1 (toolbar) OK $pCondition2 (toolbar) OK $pCondition (toolbar) OK $oToolbar OK $pCondition (button) OK $oButton OK Disabled Double click inside Explorer listview Double click in empty space of listview $oExplorer OK $pCondition1 (toolbar) OK $pCondition2 (toolbar) OK $pCondition (toolbar) OK $oToolbar OK $pCondition (button) OK $oButton OK $oInvoke OK You need AutoIt 3.3.10 or later. Tested on Windows 10/7 32/64 bit and Windows XP 32 bit. I've not been able to test under Windows Vista or Windows 7 where Windows Explorer is based on a SysListView32-class listview. Let me know if there are any issues. The zip contains all code: DoubleClick.7z1 point
-
The example sets the search folder to C:\Windows\System32 and searches for files and folders with "com" in the name. Windows Explorer must be open before you run the example. 8) PerformSearch.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include "Includes\CUIAutomation2.au3" #include <WinAPIShellEx.au3> #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; --- Set search folder --- ; Get interfaces GetShellInterfaces() ; Set current folder, C:\Windows\System32 Local $pFolder = _WinAPI_ShellILCreateFromPath( "C:\Windows\System32" ) SetCurrentFolder( $pFolder, $SBSP_ABSOLUTE ) ; Free memory _WinAPI_CoTaskMemFree( $pFolder ) ; --- Start a search --- ; Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Explorer object Local $pExplorer, $oExplorer $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer ) $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oExplorer ) Then Return ConsoleWrite( "$oExplorer ERR" & @CRLF ) ConsoleWrite( "$oExplorer OK" & @CRLF ) ; Find condition Local $pCondition ; Use Inspect.exe (Inspect Objects) to verify that the search box is an Edit control $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) ; Find Edit Local $pEdit, $oEdit ; This is the first Edit control $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Exit ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) ; Get Edit Value object Local $pEditValue, $oEditValue $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pEditValue ) $oEditValue = ObjCreateInterface( $pEditValue, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oEditValue ) Then Exit ConsoleWrite( "$oEditValue ERR" & @CRLF ) ConsoleWrite( "$oEditValue OK" & @CRLF ) ; Set search text, com $oEditValue.SetValue( "com" ) ; Wait a second Sleep( 1000 ) ; --- Get search results --- ; Get interfaces (for Search Results right pane window) GetShellInterfaces() ; Wait while the search is performed Local $iCount = 0, $iCountPrev = -1 While $iCount <> $iCountPrev Sleep( 1000 ) ; Wait a second in each loop $iCountPrev = $iCount $iCount = CountItems() WEnd ; Get search results Local $aItems = GetItems( False, True ) ; $fSelected, $fFullPath _ArrayDisplay( $aItems, "Search Results" ) EndFunc The zip contains the example and all include files: Example8.7z I've tested the new example on Windows 10 and 7. It does not work on Windows XP. I've tested the old examples in post 7 on Windows 10. They are all working.1 point
-
Here is a collection of small examples. Windows Explorer should be open before you run the examples. If you create shortcuts for the scripts, and copy the shortcuts to the desktop, you can run the examples and use Windows Explorer at the same time. For some of the examples you can select files or folders before you run the example. 1) GetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current folder Local $pFolder = GetCurrentFolder(), $sFolder SHGetPathFromIDList( $pFolder, $sFolder ) MsgBox( 0, "Folder", $sFolder ) ; Free memory _WinAPI_CoTaskMemFree( $pFolder ) EndFunc 2) SetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set current folder to desktop Local $pDesktop = _WinAPI_ShellGetSpecialFolderLocation( $CSIDL_DESKTOP ) SetCurrentFolder( $pDesktop, $SBSP_ABSOLUTE ) ; Free memory _WinAPI_CoTaskMemFree( $pDesktop ) EndFunc 3) CountItems.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Count files and folders MsgBox( 0, "Count files and folders", CountItems() ) ; Count selected files and folders MsgBox( 0, "Count selected files and folders", CountItems( True ) ) EndFunc 4) GetFiles.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFiles = GetFiles( False, True ) _ArrayDisplay( $aFiles, "All files" ) ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFiles = GetFiles( True, True ) _ArrayDisplay( $aFiles, "Selected files" ) EndFunc 5) GetFolders.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFolders = GetFolders() _ArrayDisplay( $aFolders, "All folders" ) ; Get selected folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFolders = GetFolders( True ) _ArrayDisplay( $aFolders, "Selected folders" ) EndFunc 6) SetSelectedItem.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set second item selected SetSelectedItem( 1 ) EndFunc 7) GetSetIconView.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current icon view Local $view = GetIconView() Local $iView, $iSize If IsArray( $view ) Then ; OS > XP $iView = $view[0] ; Icon view $iSize = $view[1] ; Icon size If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS, 16 ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON, 48 ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView, $iSize ) ; Restore old view Else ; OS = XP $iView = $view If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView ) ; Restore old view EndIf EndFunc Zipfile The zip contains examples and necessary include files. Examples.7z1 point