Leaderboard
Popular Content
Showing content with the highest reputation on 05/10/2015 in all areas
-
Not sure if anyone else was ever looking for a way to get the DOM object of IE by the XPath, but i sure was. I Created this UDF... _IEGetDOMObjByXPathWithAttributes Still needs some work, here are the limitations: Solved: 1) no distinction between // and /, all are handled as // ...Won't address, use syntax like #3: 2) only able to search for Elements, can't end the xpath in an attribute, such as ...//@id='test' Solved: 3) When searching for only Elements with specific attributes, I'm only handling any number of condition, such as //test[@id="test2"] Solved: 4) use of contains() now 5) No use of strucutes, such as :Parent, or :Sibling 6) Solved * due to number 1, it's possible to return the same object mutliple times...that'll be the first correction Edit: This can still occur if using xpath provided leaves mutliple paths to the specific element...make xpath more specific to stop 7) No use of enumerated nodes...such as //test[4] 8) No use of <> when defining attributes //test[@id<>"test2"] So it's very simple, but returns an array of all objects matching the xpath provided...example xpaths to search for on the google home page: "//td[@id='gs_tti0']/div/input[@id='gbqfq']" this gives object of the search input #region SCITE_CallTipsForFunctions ;BGe_IEGetDOMObjByXPathWithAttributes($oIEObj, $sXPath, [$iMaxWait=2000]) Return array of objects on browser matching callers xpath #endregion SCITE_CallTipsForFunctions #include <ie.au3> #include <array.au3> #region GLOBALVariables Global $gbBGe_PerformConsoleWrites = True ; The XPath array to work with will be 2d, with the following Global Enum $giBGe_XPath_Dim2_sRawNode, _ $giBGe_XPath_Dim2_sNodeName, _ $giBGe_XPath_Dim2_bNodeIsRelative, _ $giBGe_XPath_Dim2_sRawNodeConstraints, _ $giBGe_XPath_Dim2_bIsConstrainted, _ $giBGe_XPath_Dim2_aNodeConstraints, _ $giBGe_XPath_Dim2_UBound ; $giBGe_XPath_Dim2_aNodeConstraints will contain a 2d, with the following Global Enum $giBGe_Constraint_Dim2_sNodeName, _ $giBGe_Constraint_Dim2_bIsAttribute, _ $giBGe_Constraint_Dim2_bIsSelf, _ $giBGe_Constraint_Dim2_sNodeValue, _ $giBGe_Constraint_Dim2_bIsContains, _ $giBGe_Constraint_Dim2_UBound ; Regexp to split xpath Global $gsBGe_RegExpNodeSplit = "(?U)(.*(?:['""].*['""].*){0,})(?:\/)" ; Split Xpath into nodes...split by / where it is part of x-path Global $gsBGe_RegExpNodeAndCondSplit = "([^\[\]]+)\[(.*)\]" ; Get node name and conditions...conditions can be empty Global $gsBGe_RegExpOrSplit = "(?i)(?U)(.*['""].*['""\)])(?:\sor\s)|.{1,}?" ; Split Or statements inside [] Global $gsBGe_RegExpAndSplit = "(?i)(?U)(.*['""].*['""\)])(?:\sand\s)|.{1,}?" ; Split And statements inside [] Global $gsBGe_RegExpSplitContains = "(?i)contains\s*\(\s*(.+)\s*,\s*['""](.+)['""]\s*\)" ; Split contains, remove spaces that are not needed Global $gsBGe_RegExpSplitNonContains = "(.*)\s*\=\s*['""](.*)['""]" ; Split constraint that is not a contains, remove spaces that are not needed #endregion GLOBALVariables #region SAMPLE ; Using multiple levels as an example...made comples on purpose to demonstrate...: $xpathForumLink = "//div[@id='top-menu']/ul[contains(@class,'WONT BE FOUND') or @id='menu-mainmenu']//a[contains(@href,'forum')]" $xpathGeneralHelpSuprt = "//table[contains(@class,'table') and @summary='Forums within the category 'AutoIt v3'']//h4/a[@title='General Help and Support']" $xpathGeneralHelpUsers = "//div[@id='forum_active_users']//span[@itemprop='name']" ; Create/navigate to page $oIE = _IECreate("http://www.autoitscript.com/site/",True,True) If IsObj($oIE) Then ConsoleWrite("Able to _IECreate('http://www.autoitscript.com/site/')" & @CRLF) Else ConsoleWrite("UNable to _IECreate('http://www.autoitscript.com/site/')" & @CRLF) Exit 1 EndIf ; Get Forum Link $aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpathForumLink) If IsArray($aForumLink) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathForumLink & ")" & @CRLF) For $i = 0 To UBound($aForumLink)-1 ConsoleWrite(" " & $aForumLink[$i].outerhtml ) Next Else ConsoleWrite("UNable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathForumLink & ")" & @CRLF) Exit 2 EndIf ; Click the link _IEAction($aForumLink[0], "focus") If _IEAction($aForumLink[0], "click") Then ConsoleWrite("Able to _IEAction($aForumLink[0], 'click')" & @CRLF) _IELoadWait($oIE) Else ConsoleWrite("UNable to _IEAction($aForumLink[0], 'click')" & @CRLF) Exit 3 EndIf ; Get General help link $aGenHelpLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpathGeneralHelpSuprt) If IsArray($aGenHelpLink) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathGeneralHelpSuprt & ")" & @CRLF) For $i = 0 To UBound($aGenHelpLink)-1 ConsoleWrite(" " & $aGenHelpLink[$i].outerhtml ) Next Else ConsoleWrite("UNable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathGeneralHelpSuprt & ")" & @CRLF) Exit 4 EndIf ; Click the link _IEAction($aGenHelpLink[0], "focus") If _IEAction($aGenHelpLink[0], "click") Then ConsoleWrite("Able to _IEAction($aGenHelpLink[0], 'click')" & @CRLF) _IELoadWait($oIE) Else ConsoleWrite("UNable to _IEAction($aGenHelpLink[0], 'click')" & @CRLF) Exit 5 EndIf ; Get current users on page $aGenHelpUsers = BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpathGeneralHelpUsers) If IsArray($aGenHelpUsers) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathGeneralHelpSuprt & ")" & @CRLF) For $i = 0 To UBound($aGenHelpUsers)-1 ConsoleWrite(" " & $aGenHelpUsers[$i].outerhtml & @CRLF ) ConsoleWrite(" " & $aGenHelpUsers[$i].innertext & @CRLF ) Next Else ConsoleWrite("UNable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathGeneralHelpSuprt & ")" & @CRLF) Exit 6 EndIf #endregion SAMPLE #region ExternalFunctions Func BGe_IEGetDOMObjByXPathWithAttributes($oIEObject, $sXPath, $iMaxWait=2000) ; Get dom object by XPath If $gbBGe_PerformConsoleWrites Then ConsoleWrite("Start Function=[BGe_IEGetDOMObjByXPathWithAttributes] with $sXPath=[" & $sXPath & "]." & @CRLF) Local $aReturnObjects = "" Local $aSplitXpath = BGe_ParseXPath($sXPath) If Not IsArray($aSplitXpath) Then ConsoleWrite("BGe_IEGetDOMObjByXPathWithAttributes: Callers XPath/Node/Conditions not well formed=[" & $sXPath & "]" & @CRLF) Return SetError(1,0,False) EndIf Local $iTimer = TimerInit() While TimerDiff($iTimer)<$iMaxWait And Not IsArray($aReturnObjects) $aReturnObjects = BGe_RecursiveGetObjWithAttributes($oIEObject,$aSplitXpath) WEnd Return $aReturnObjects EndFunc ;==>BGe_IEGetDOMObjByXPathWithAttributes #endregion ExternalFunctions #region InternalFunctions Func BGe_RecursiveGetObjWithAttributes($oParent, $aCallersSplitXPath, $asHolder="", $Level=0) $asObjects = $asHolder Local $sNodeName = $aCallersSplitXPath[$Level][$giBGe_XPath_Dim2_sNodeName] Local $bNodeIsRelative = $aCallersSplitXPath[$Level][$giBGe_XPath_Dim2_bNodeIsRelative] ; true=relative false=absolute Local $bIsConstrainted = $aCallersSplitXPath[$Level][$giBGe_XPath_Dim2_bIsConstrainted] ; array[OR] of arrays[AND]; all constraints on the node Local $aNodeOrConstraints = $aCallersSplitXPath[$Level][$giBGe_XPath_Dim2_aNodeConstraints] ; array[OR] of arrays[AND]; all constraints on the node Local $aPossibleNodeMatch = "" If $gbBGe_PerformConsoleWrites Then ConsoleWrite("Start Function=[BGe_RecursiveGetObjWithAttributes] level=[" & $Level & "]: $sNodeName=[" & $sNodeName & "], $bNodeIsRelative=[" & $bNodeIsRelative & "] $bIsConstrainted=[" & $bIsConstrainted & "]."& @CRLF) If Not IsObj($oParent) Then Return $asObjects ; Get nodes that match If $bNodeIsRelative Then If $sNodeName = "*" Then $oPossibleNodes = _IETagNameAllGetCollection($oParent) Else $oPossibleNodes = _IETagNameGetCollection($oParent, $sNodeName) EndIf For $oPossibleNode In $oPossibleNodes If $oPossibleNode.NodeType == 1 Then ; only add nodes If IsArray($aPossibleNodeMatch) Then _ArrayAdd($aPossibleNodeMatch,$oPossibleNode) Else Local $aPossibleNodeMatch[1] = [$oPossibleNode] EndIf EndIf Next Else $oPossibleNodes = $oParent.childnodes For $oPossibleNode In $oPossibleNodes If String($oPossibleNode.NodeName) = $sNodeName Or $sNodeName = "*" Then If IsArray($aPossibleNodeMatch) Then _ArrayAdd($aPossibleNodeMatch,$oPossibleNode) Else Local $aPossibleNodeMatch[1] = [$oPossibleNode] EndIf EndIf Next EndIf ; Loop through nodes against restraints If IsArray($aPossibleNodeMatch) Then For $iChild = 0 To UBound($aPossibleNodeMatch) - 1 Local $oChild = $aPossibleNodeMatch[$iChild] ; Find matching conditions, when necessary If $bIsConstrainted Then ; Loop through OR Conditions For $i = 0 To UBound($aNodeOrConstraints) - 1 Local $aNodeAndConstraints = $aNodeOrConstraints[$i] Local $bAndConditionsMet = True ; Loop through And Conditions, or conditions are outside of this loop, and will go if current and's are not met For $j = 0 To UBound($aNodeAndConstraints) - 1 ; Remove the @... Local $sConstraintName = StringReplace($aNodeAndConstraints[$j][$giBGe_Constraint_Dim2_sNodeName],"@","") Local $bConstraintIsAtt = $aNodeAndConstraints[$j][$giBGe_Constraint_Dim2_bIsAttribute] Local $bConstraintIsNode = $aNodeAndConstraints[$j][$giBGe_Constraint_Dim2_bIsSelf] Local $sConstraintValue = $aNodeAndConstraints[$j][$giBGe_Constraint_Dim2_sNodeValue] Local $bConstraintIsContains= $aNodeAndConstraints[$j][$giBGe_Constraint_Dim2_bIsContains] If $bConstraintIsNode Then If $bConstraintIsContains Then If Not StringInStr(String($oChild.innertext), $sConstraintValue) Then $bAndConditionsMet = False Else If String($oChild.innertext) <> $sConstraintValue Then $bAndConditionsMet = False EndIf ElseIf $bConstraintIsAtt Then Local $sAttributeValue = "" Switch $sConstraintName Case "class" $sAttributeValue = $oChild.className() Case "style" $sAttributeValue = $oChild.style.csstext Case "onclick" $sAttributeValue = $oChild.getAttributeNode($sConstraintName).value Case Else $sAttributeValue = $oChild.getAttribute($sConstraintName) EndSwitch If $bConstraintIsContains Then If Not StringInStr(String($sAttributeValue), $sConstraintValue) Then $bAndConditionsMet = False Else If String($sAttributeValue) <> $sConstraintValue Then $bAndConditionsMet = False EndIf Else ; failure EndIf ; Skip looping if a condition of the And array was not met If Not $bAndConditionsMet Then ExitLoop Next If $bAndConditionsMet Then ; If last level, add the object If $Level = UBound($aCallersSplitXPath) - 1 Then If Not IsArray($asObjects) Then Local $asObjects[1]=[$oChild] Else $bUnique = True ; Only add if not present in the array For $iObject = 0 To UBound($asObjects)-1 If $oChild = $asObjects[$iObject] Then $bUnique=False ExitLoop EndIf Next If $bUnique Then _ArrayAdd($asObjects, $oChild) EndIf Else $asObjects = BGe_RecursiveGetObjWithAttributes($oChild, $aCallersSplitXPath, $asObjects, $Level + 1) EndIf EndIf ; No need to loop additional or if already found one and If $bAndConditionsMet Then ExitLoop Next Else ; No constraints, match is implied If $Level = UBound($aCallersSplitXPath) - 1 Then ; Final xpath level, so add to final array If Not IsArray($asObjects) Then Local $asObjects[1]=[$oChild] Else Local $bUnique=True ; Only add if not present in the array For $iObject = 0 To UBound($asObjects)-1 If $oChild = $asObjects[$iObject] Then $bUnique=False ExitLoop EndIf Next If $bUnique Then _ArrayAdd($asObjects, $oChild) EndIf Else ; Continue Recurssion $asObjects = BGe_RecursiveGetObjWithAttributes($oChild, $aCallersSplitXPath, $asObjects, $Level + 1) EndIf EndIf Next EndIf Return $asObjects EndFunc ;==>BGe_RecursiveGetObjWithAttributes Func BGe_ParseXPath($sCallersXPath) ; RegExp require a trailing "/" $sCallersXPath &= "/" Local $aReturnParsedXPath=False ; Parse all the '/' outside of single, or double, quotes Local $aNodesWithQualifiers = StringRegExp($sCallersXPath,$gsBGe_RegExpNodeSplit,3) ; Loop through, and determine if the node is direct, or relative.../ vs // Local $iSlashCount = 0 For $i = 0 To UBound($aNodesWithQualifiers) - 1 If StringLen($aNodesWithQualifiers[$i])=0 Then $iSlashCount+=1 Else ; Add dimentions to the return array If Not IsArray($aReturnParsedXPath) Then Local $aReturnParsedXPath[1][$giBGe_XPath_Dim2_UBound] Else ReDim $aReturnParsedXPath[UBound($aReturnParsedXPath)+1][$giBGe_XPath_Dim2_UBound] EndIf $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_sRawNode] = $aNodesWithQualifiers[$i] ; Split current Node Local $aSplitNodeAndCond = StringRegExp($aNodesWithQualifiers[$i],$gsBGe_RegExpNodeAndCondSplit,3) If UBound($aSplitNodeAndCond) = 2 Then Local $sNodeName = $aSplitNodeAndCond[0] Local $sNodeConstraints = $aSplitNodeAndCond[1] $aNodeConstraints = BGe_ParseXPathConstraints($sNodeConstraints) If Not IsArray($aNodeConstraints) Then ConsoleWrite("ParseXPath: Callers XPath/Node/Conditions not well formed=[" & $aNodesWithQualifiers[$i] & "]" & @CRLF) Return SetError(1,1,False) EndIf ElseIf UBound($aSplitNodeAndCond) = 0 Then Local $sNodeName = $aNodesWithQualifiers[$i] Local $sNodeConstraints = "" Local $aNodeConstraints = "" Else ConsoleWrite("ParseXPath: Callers XPath/Node/Conditions not well formed=[" & $aNodesWithQualifiers[$i] & "]" & @CRLF) Return SetError(1,2,False) EndIf $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_sNodeName] = $sNodeName $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_sRawNodeConstraints] = $sNodeConstraints $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_bIsConstrainted] = (StringLen($sNodeConstraints)>0) $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_aNodeConstraints] = $aNodeConstraints $aReturnParsedXPath[UBound($aReturnParsedXPath)-1][$giBGe_XPath_Dim2_bNodeIsRelative] = $iSlashCount>1 $iSlashCount=1 EndIf Next Return $aReturnParsedXPath EndFunc Func BGe_ParseXPathConstraints($sCallersXPathConstraints) ; Returns array of arrays ; Array is split of all 'or' statements, and then includes array of 'and' statements, which are split out into 2d array of name/value/bcontains Local $aReturnParsedXPathConstraints[1] ; Will always return at least the first condition Local $aOrQualifiers = StringRegExp($sCallersXPathConstraints,$gsBGe_RegExpOrSplit,3) ReDim $aReturnParsedXPathConstraints[UBound($aOrQualifiers)] For $i = 0 To UBound($aReturnParsedXPathConstraints)-1 Local $aAndQualifiers = StringRegExp($aOrQualifiers[$i],$gsBGe_RegExpAndSplit,3) Local $aaSplitQualitfiers = BGe_ParseXPathConstraint($aAndQualifiers) If IsArray($aaSplitQualitfiers) Then $aReturnParsedXPathConstraints[$i]=$aaSplitQualitfiers Else ConsoleWrite("ParseXPathConstraints: Callers XPath/Node/Conditions not well formed=[" & $aOrQualifiers[$i] & "]" & @CRLF) Return SetError(1,3,False) EndIf Next Return $aReturnParsedXPathConstraints EndFunc Func BGe_ParseXPathConstraint($aCallersXPathConstraint) Local $aReturnParsedXPathConstraints[UBound($aCallersXPathConstraint)][$giBGe_Constraint_Dim2_UBound] For $i = 0 To UBound($aCallersXPathConstraint)-1 ; Remove leading and trailing spaces Local $sCurrentConstraint = StringStripWS($aCallersXPathConstraint[$i], 3) ; Check if $sCurrentConstraint makes use of contains() Local $aTempContains = StringRegExp($sCurrentConstraint,$gsBGe_RegExpSplitContains,3) Local $aTempNonContains = StringRegExp($sCurrentConstraint,$gsBGe_RegExpSplitNonContains,3) If UBound($aTempContains)=2 Then $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsContains] = True $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsSelf] = ($aTempContains[0]=".") $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_sNodeName] = $aTempContains[0] $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsAttribute] = (StringLeft($aTempContains[0],1)="@") $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_sNodeValue] = $aTempContains[1] ElseIf UBound($aTempNonContains)=2 And Not StringInStr($aTempNonContains[0],"(") Then $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsContains] = False $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsSelf] = ($aTempNonContains[0]=".") $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_sNodeName] = $aTempNonContains[0] $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_bIsAttribute] = (StringLeft($aTempNonContains[0],1)="@") $aReturnParsedXPathConstraints[$i][$giBGe_Constraint_Dim2_sNodeValue] = $aTempNonContains[1] Else ConsoleWrite("ParseXPathConstraint: Callers XPath/Node/Conditions not well formed=[" & $aCallersXPathConstraint[$i] & "]" & @CRLF) Return SetError(1,4,False) EndIf Next Return $aReturnParsedXPathConstraints EndFunc #endregion InternalFunctions Edit 08/12/2015...navigate here to get new functionality which allows for specific types of predicates:1 point
-
Bitmap2AscII use Lucida Console font with a size set to 8, so Windows 8/8.1 users need to change their notepad font and size for get a correct display. Image Rescale slider is only available when saving as image. A click on the "PreviewEdit" open AscII string in Notepad. You can save as Text, Html or Image (add the extension you want) Each setting change is immediately applied. Downloads available in the download section Hope you like it !1 point
-
A transparent rolling text example with GDI Font and background picture are embedded in script. TransparentRollingText.au31 point
-
Hello, I have a mistake, I can try not unfortunately, sorry! in the following line is missing a 'c', therefore can not determine the required buffer size! $iConns = DllStructGetData($tREC_lpcConns, "lpConns")change to $iConns = DllStructGetData($tREC_lpcConns, "lpcConns")sorry1 point
-
Simply use $tpcSize to allocate memory. $tpcSize I wanted to mean this: Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0) If $iRet[0] = $ERROR_BUFFER_TOO_SMALL Then Local $tpcbSize = $iRet[2] MsgBox(0, "required buffer size", $tpcbSize) Local $tBuffer=DllStructCreate("byte[" & $tpcbSize & "]") ;then call RasEnumConnectionsW again Else MsgBox(0, "There are no active RAS connections", $tpcbSize) EndIf Saludos1 point
-
hi mate. trying with rasdial again. This should work. and should returns the buffer required size. Global Const $ERROR_SUCCESS = 0x0 Global Const $RAS_MaxAreaCode = 10 Global Const $RAS_MaxPhoneNumber = 128 Global Const $RAS_MaxDeviceType = 16 Global Const $RAS_MaxDeviceName = 128 Global Const $RAS_MaxPadType = 32 Global Const $RAS_MaxX25Address = 200 Global Const $RAS_MaxFacilities = $RAS_MaxX25Address Global Const $RAS_MaxUserData = $RAS_MaxFacilities Global Const $RAS_MaxDnsSuffix = 256 Global Const $RAS_MaxEntryName = 256 Global Const $WM_RASDIALEVENT = 0xCCCD Global Const $RASCS_DONE = 0x2000 Global Const $WAIT_OBJECT_0 = 0 Global $hConection = 0 Global Const $MAX_PATH = 256 Global Const $tagRASDIALPARAMS = "dword dwSize;handle hrasconn;wchar szEntryName[" & $RAS_MaxEntryName + 1 & "];wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];wchar szPhonebook[" & $MAX_PATH & "];DWORD dwSubEntry;GUID guidEntry;DWORD dwFlags; LUID luid;GUID guidCorrelationId" Local $tRASDIALPARAMS = DllStructCreate($tagRASDIALPARAMS) Sleep(100) DllStructSetData($tagRASDIALPARAMS, "dwSize", DllStructGetSize($tRASDIALPARAMS)) $lpcb = DllStructGetSize($tRASDIALPARAMS) Local $iRet = DllCall("Rasapi32.dll", "dword", "RasEnumConnectionsW", "ptr", 0, "dword*", Null, "ptr*", 0) If Not ($iRet[0] = $ERROR_SUCCESS) Then Local $tpcbSize = $iRet[2] MsgBox(0, "required buffer size", $tpcbSize) Else MsgBox(0, "There are no active RAS connections", $tpcbSize) EndIf Saludos1 point
-
Change GUI depending on checkbox state
SuperFletch reacted to kylomas for a topic
SuperFletch, You will receive better help if you post runnable code. kylomas1 point -
Hello, which values are to be returned? Oh I see now I forgot index in the following line If $aRet = 603 Then ; ERROR_BUFFER_TOO_SMALLcorrect is If $aRet[0] = 603 Then ; ERROR_BUFFER_TOO_SMALL1 point
-
I have been searching for a while for a script to toggle the default sound device, so that i can easily switch between Speakers and Headphones. Some added a tray icon and keep running on background, some will call up the control panel briefly, while some need to call nircmd externally. I ended up gathered some cool scripts (sorry, i failed to recall the original source) and modified for my own taste. It will get the current default playback device, and then set to the next one. It will print an icon on the screen, and then will just exit. Good to use with shortcut key on keyboards, etc. Feel free to try. I was able to retrieve the actual icons info but found it not satisfactory to draw the icon using GUI. So, I simply use SplashText with Webdings font. ;========================================================== ; Set Default Playback Device ; to the next available one ;========================================================== #NoTrayIcon #include <WinAPI.au3> #include <Constants.au3> Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" Global Const $sCLSID_CPolicyConfigClient = "{870af99c-171d-4f9e-af0d-e63df40c2bc9}" Global Const $sIID_IPolicyConfig = "{f8679f50-850a-41cf-9c72-430f290290c8}" Global Const $tagIPolicyConfig = "GetMixFormat hresult(wstr;ptr*);" & _ "GetDeviceFormat hresult(wstr;int;ptr*);" & _ "ResetDeviceFormat hresult(wstr);" & _ "SetDeviceFormat hresult(wstr;ptr;ptr);" & _ "GetProcessingPeriod hresult(wstr;int;int64*;int64*);" & _ "SetProcessingPeriod hresult(wstr;int64*);" & _ "GetShareMode hresult(wstr;ptr);" & _ "SetShareMode hresult(wstr;ptr);" & _ "GetPropertyValue hresult(wstr;struct;variant*);" & _ "SetPropertyValue hresult(wstr;struct;variant*);" & _ "SetDefaultEndpoint hresult(wstr;int);" & _ "SetEndpointVisibility hresult(wstr;int);" Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}" Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);" & _ "Item hresult(uint;ptr*)" Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}" Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _ "GetAt hresult(dword;ptr*);" & _ "GetValue hresult(ptr;variant*);" & _ "SetValue hresult(ptr;variant);" & _ "Commit hresult();" Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0} 2" Global Const $sPKEY_Device_Icon = "{259abffc-50a7-47ce-af08-68c9a7d73366} 12" Global Const $STGM_READ = 0 Global Const $DEVICE_STATE_ACTIVE = 0x00000001 Global Const $S_OK = 0 Global Const $E_INVALIDARG = 0x80070057 Global Const $eRender = 0 Global Const $eCapture = 1 Global Const $eAll = 2 Global Const $EDataFlow_enum_count = 3 Global Const $eConsole = 0 Global Const $eMultimedia = 1 Global Const $eCommunications = 2 Global Const $ERole_enum_count = 3 ;========================================================== If @OSVersion <> "WIN_7" Then Exit ; God knows what $tagIPolicyConfig is for other systems ; First generate array filled with devices data Global $aArray = _EnumerateDevices() ; FY: Get default device id Global $sDefID = _GetDefaultDevice() ; Set next device as default device $nDev = UBound($aArray, 2) ; no. of devices For $i = 0 to $nDev -1 If $aArray[0][$i]=$sDefID Then $sDev=$i+1 Next If $sDev >= $nDev Then $sDev = 0 _SwitchToDevice($aArray[0][$sDev]) $logo = "U" if $aArray[1][$sDev] = "Headphones" Then $logo=chr(178) $xTT = @DesktopWidth/2-50 $yTT = @DesktopHeight/2-70 ToolTip(" ", $xTT, $yTT, $aArray[1][$sDev],0) SplashTextOn("",$logo, 100, 100, -1, -1, 33, "Webdings", 80) Sleep(2000) SplashOff() Exit ; THE END Func _GetDefaultDevice() ; Error monitoring Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") #forceref $oErrorHandler ; MMDeviceEnumerator Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice) Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $IID_IMMDevice, $tagIMMDevice) Local $pDefID, $sDefId $oDefaultDevice.GetId($pDefID) $sDefId = DllStructGetData(DllStructCreate("wchar ID[" & _WinAPI_PtrStringLenW($pDefID) & "]", $pDefID), "ID") _WinAPI_CoTaskMemFree($pDefID) Return $sDefID EndFunc ;==>_GetDefaultDevice Func _EnumerateDevices() ; Error monitoring Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") #forceref $oErrorHandler ; Creae MMDeviceEnumerator object Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) ; Get collection out of it Local $pCollection $oEnumerator.EnumAudioEndpoints($eRender, $DEVICE_STATE_ACTIVE, $pCollection) ; Turn it into object Local $oCollection = ObjCreateInterface($pCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection) ; Check the number of devices in collection Local $iCount $oCollection.GetCount($iCount) ; Array for out Local $aArray[2][$iCount] Local $pEndpoint, $oEndpoint Local $pID, $sId, $pProps, $oProps Local $sName Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName) Local $tPKEY_Device_Icon = _WinAPI_PKEYFromString($sPKEY_Device_Icon) ; Actual enumeration For $i = 0 To $iCount - 1 ; Item at "i" index is audio endpoint device $oCollection.Item($i, $pEndpoint) $oEndpoint = ObjCreateInterface($pEndpoint, $IID_IMMDevice, $tagIMMDevice) ; Collect ID $oEndpoint.GetId($pID) $sId = DllStructGetData(DllStructCreate("wchar ID[" & _WinAPI_PtrStringLenW($pID) & "]", $pID), "ID") _WinAPI_CoTaskMemFree($pID) $aArray[0][$i] = $sId ; PropertyStore stores properties, lol $oEndpoint.OpenPropertyStore($STGM_READ, $pProps) $oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore) ; Collect FriendlyName property $sName = 0 $sIcon = 0 $oProps.GetValue(DllStructGetPtr($tPKEY_Device_FriendlyName), $sName) $oProps.GetValue(DllStructGetPtr($tPKEY_Device_Icon), $sIcon) $aArray[1][$i] = $sName Next Return $aArray EndFunc ;==>_EnumerateDevices Func _SwitchToDevice($sId) Local $oPolicyConfig = ObjCreateInterface($sCLSID_CPolicyConfigClient, $sIID_IPolicyConfig, $tagIPolicyConfig) Local $hResult $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eConsole) If $hResult = $S_OK Then $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eCommunications) Return $hResult = $S_OK EndFunc ;==>_SwitchToDevice Func _WinAPI_PKEYFromString($sPKEY, $pID = Default) Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;") DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "ptr", DllStructGetPtr($tPKEY)) If @error Then ; alternative for unsupported systems Local $tGUID = _WinAPI_GUIDFromString($sPKEY) If Not @error Then DllStructSetData($tPKEY, "GUID", DllStructGetData(DllStructCreate("byte Data[16]", DllStructGetPtr($tGUID)), 1)) EndIf DllStructSetData($tPKEY, "PID", Number(StringRegExpReplace($sPKEY, ".*?}", ""))) EndIf If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID) Return $tPKEY EndFunc ;==>_WinAPI_PKEYFromString Func _WinAPI_PtrStringLenW($pString) Local $aCall = DllCall("kernel32.dll", "dword", "lstrlenW", "ptr", $pString) If @error Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ;==>_WinAPI_PtrStringLenW Func _WinAPI_CoTaskMemFree($pMem) DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $pMem) If @error Then Return SetError(1, 0, False) Return True EndFunc ;==>_WinAPI_CoTaskMemFree Func _ErrFunc($oError) ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF) EndFunc ;==>_ErrFunc1 point
-
How to change the Path of Basic window info Title, "Open"
232showtime reacted to jguinch for a topic
Use ControlGetHandle to retrieve its handle and use it with _GUICtrlComboBox UDF functions1 point -
Notify - New version 17 Mar 22
argumentum reacted to Melba23 for a topic
argumentum, Sorry, I left a @DeskTopWidth in the location formula for the "click to bring onto screen" notifications rather then using the new calculated value I used for the others. Please try this modified version: <snip> M231 point -
You are right there are 3 "group_actions_item" elements. And we need to click on the third one. So we start to calculate the elements with a simple addon to our function and when we come to the third one, click on it Local $oElements = _IETagNameGetCollection($oIE, "a") $i = 0 For $oElement In $oElements if $oElement.classname=="group_actions_item" then $i = $i+1 if ($i==3) then _IEAction ($oElement, "click") endif EndIf ConsoleWrite ( $oElement.classname & @CRLF) next Thats it1 point
-
My output isn't formatted like yours, this was most convenient for me.... ATi Radeon HD 4290, onboard, current drivers though the CPU-Z info shows old dates...... CPU-Z graphics info: Working textures: $GL_RGBA32F_ARB $GL_RGB32F_ARB $GL_INTENSITY32F_ARB Looking forward to seeing what capabilities this will bring! Ian1 point
-
[Build 0.03] (Testing needed!) The MiniCL Project - GPU computation made easy
argumentum reacted to minxomat for a topic
Seems i found the answer... Edit: Intel is a mess! This issue was reported over and over and no fix in sight, duh. https://communities.intel.com/message/2639411 point -
_SplashTextOnEx UDF build 2015-05-10
argumentum reacted to UEZ for a topic
I agree wakillon. Everyone should have the freedom either to like a post or to write to comment. After forum upgrade on German forum we had a discussion whether to activate the like or not. The majority was against the like button because writing a comment is more meaningful than pushing a button.1 point -
1 point
-
It is funny to see how such sites as vk are trying to limit its automatisation for coders. so what happens there? In fact programmatically the button is clicked but as it sees there is no mouse over there it just immediately hides the dropdown. So- you think that you cant click it, but in fact you have clicked it- just it doesnt show up- because your mouse is not over.... The question is: Why do you want to click that button? May be because it will show you the drop down with some menu such as "пригласить друзей" ? Am I right? And then you wanna click that button? _IENavigate($oIE, "https://vk.com/club92594181") _IELoadWait($oIE) Local $oElements = _IETagNameGetCollection($oIE, "a") For $oElement In $oElements if $oElement.classname=="group_actions_item" then _IEAction ($oElement, "click") EndIf ;ConsoleWrite ( $oElement.classname & @CRLF) nextAnd voila....1 point
-
1 point
-
LAST VERSION - 1.0 12-Jul-10 This library allows to create and manage a pop-up windows are based on your images (transparency also supported). Use this UDF is very simple: create or load the bitmap from a file and display it on desktop screen by using _Popup_Show() function (see example). Run the example that is below, and press SHIFT+1 or SHIFT+2 (several times). iKey and iSwitcher from my sig. also based on this "engine". Try playing with this UDF, and please post any comments and suggestions. Available functions Pop-ups UDF Library v1.0 Previous downloads: 122 Pop-ups.zip Example #Include <GDIPlus.au3> #Include <Pop-ups.au3> Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) _GDIPlus_Startup() Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png') Global $hPopup1 = _Popup_Register(), $hPopup2 = _Popup_Register() HotKeySet('+1', '_Popup1') ; SHIFT+1 HotKeySet('+2', '_Popup2') ; SHIFT+2 While 1 Sleep(1000) WEnd _GDIPlus_Shutdown() Func _Popup1() Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN) ; Draw current time (xx:xx) on "Image1.png" and create bitmap $hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea) $hFamily = _GDIPlus_FontFamilyCreate('Tahoma') $hFont = _GDIPlus_FontCreate($hFamily, 38, 0, 2) $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) $hFormat = _GDIPlus_StringFormatCreate() $hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF) _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3) $aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat) $tLayout = $aData[0] DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2) DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_FontDispose($hFont) _GDIPlus_BrushDispose($hBrush) _GDIPlus_ImageDispose($hArea) ; Show pop-up image _Popup_Show($hPopup1, $hBitmap, 1) EndFunc ;==>_Popup1 Func _Popup2() ; Show or hide pop-up image ("Image2.png") If Not _Popup_IsActive($hPopup2) Then _Popup_Show($hPopup2, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2), 1, @DesktopWidth - 90, @DesktopHeight - 110, -1) Else _Popup_Hide($hPopup2) EndIf EndFunc ;==>_Popup2 #Region GDI+ Functions Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint) Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint) If @error Then Return SetError(1, 0, 0) Else If $aResult[0] Then Return SetError($aResult[0], 0, 0) EndIf EndIf Return 1 EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint #EndRegion GDI+ Functions1 point