Jump to content

unable to control a treeview under windows 8 64


Recommended Posts

I need to take control of printer option selections in a treeview, and make selections. It works fine in XP, windows 2008, vista, windows 7. But not under windows 8 64 bits.

Here is what I've tried.

First, to bring up the window with the treeview,

1- start Notepad.

2- Press ctrl P to bring up the print dialog.

3- Select the "Microsoft XPS Document Writer" printer. I need to make this work on other printers, but this one is a good example, and should be present on any machine.

4- click on the Preferences button. This displays the Printing Preferences dialog.

5- click on Advanced.... This displays the "Microsoft XPS Document Writer v4 Advanced Options" dialog. In has a treeview. It is viewed by the autoit window tool as a SysTreeView32 class instance.

Coding attempts:

Local $hwndTV = ControlGetHandle("Microsoft XPS Document Writer v4 Advanced Options", "", "[Class:SysTreeView32; INSTANCE=1]") ; this succeeds and populates $hndTV
; try to find the root node
Local $ItemHnd = _GuiCtrlTreeView_FindItemEx($hwndTV, "Microsoft XPS Document Writer v4 Advanced Document Settings") ; this fails and returns a "0" handle
; try to get the handle of the first item
Local $FirstItemHnd = _GuiCtrlTreeView_GetFirstItem($hwndTV) ; this succeeds
; try to get the text of the first item
msgbox(0,"","_GUICtrlTreeView_GetText($hwndTV, $hStart) ; this fails and returns an empty string, so that I can't step through entries looking for text
; try to use ControlTreeView Commands
msgbox(0,"",ControltreeView("Microsoft XPS Document Writer v4 Advanced Options", "", "[Class:SysTreeView32; INSTANCE=1]", "Exists", "#0") ; this returns 1: it can see the root node
;check if it sees children of the root node

msgbox(0,"",ControltreeView("Microsoft XPS Document Writer v4 Advanced Options", "", "[Class:SysTreeView32; INSTANCE=1]", "Exists", "#0|#0") ; this returns 0: it only sees a root node. This means that I can't navigate and find nodes, much less select them and make selections.

I would appreciate other ideas to make those selections using AutoIT.

Thanks!

Edited by rodent1
Link to comment
Share on other sites

  • 2 months later...

The _GuiCtrlTreeView_GetText statement is what fails.

I went to the sub in GuiTreeView.au3, and checked return values where possible. There is no error, DllStructGetData($tText,"Buffer") just returns an empty string for each treeview item, so that I can't find the item I need AutoIt to update.

The problem has migrated to Windows 7, so that I think Microsoft has come up with a new version of the treeview for the print advanced options dialog, and so far my attempts at using AutoIT to read it have failed.

Link to comment
Share on other sites

in case someone faces the same problem, I came up with a solution. It's a work-around, it doesn't fix the problem where autoit doesn't get the node text from Windows. I noticed that the window hidden text contains the current treeview selection, if any. So I select each tree node, record the hidden text, and generate a map of the treeview, so that I then know what node to select.

If someone comes up with a better method to do this, I'm all ears etc.

Here is the code:

Dim $TVTreeList ; map to contain treeview node info
;$hwndTV is the treeview handle, $Fin is the print finishing I need to select, one of the treeview node text values.
Func TVSelect($hwndTV, $Fin)
Local $WinTitle = WinGetTitle($hwndTV)
;this is used repeatedly in 100s of tests, so I just build the map once and reuse it. The map is in $TVTreeList
if StringLen($TVTreeList)=0 Then
  TVGenTreeList($hwndTV, $WinTitle)
EndIf
; the map entries are CRLF-spearated, and consist of a node path followed by "" and the node text
if StringInStr($TVTreeList, "" & $Fin & ": " & @CRLF) > 0 Then
; split the map into an array of lines
  Local $arData = StringSplit($TVTreeList, @CRLF, 1)
; browse through all lines looking for the string with correct text, $Fin
  for $i = 1 to $arData[0]
   if StringRight($arData[$i], stringlen($Fin)+3) = "" & $Fin & ": " Then
; if I find it, select it. This will cause a combobox to appear for the selected value, but this is done elsewhere.
    ControlTreeView($WinTitle, "", $hwndTV, "Select", StringLeft($arData[$i], StringInStr($arData[$i], "")))
    Return True
   EndIf
  Next
Else
  MsgBox(0,"","didn't find " & $Fin & " in" & @LF & $TVTreeList)
EndIf
Return False
EndFunc
; generate the tree node list
Func TVGenTreeList($hwndTV, $WinTitle)
;let autoit know that I want to see the hidden text
AutoItSetOption("WinDetectHiddenText",1)
; get the hidden text before making selections
Local $OrigHiddenTxt = WinGetText("MicroPress 0120km Advanced Options")
Local $sTxt = ""
Local $sHiddenTxt = ""
Local $Stem = ""
$TVTreeList = "#0|#0|#0Paper Source"
; select each node in turn, record its address and text
for $i = 1 to ControlTreeView($WinTitle, "", $hwndTV, "GetItemCount", "#0") - 1
  $Stem = "#0|#" & $i
  for $j = 0 to ControlTreeView($WinTitle, "", $hwndTV, "GetItemCount", "#0|#" & $i) - 1
   Local $NumOfChildren = ControlTreeView($WinTitle, "", $hwndTV, "GetItemCount", "#0|#" & $i & "|#" & $j)
; if the current node has children, record those as well
   if $NumOfChildren > 0 Then
    for $k = 0 to ControlTreeView($WinTitle, "", $hwndTV, "GetItemCount", "#0|#" & $i & "|#" & $j) - 1
     ControlTreeView($WinTitle, "", $hwndTV, "Select", "#0|#" & $i & "|#" & $j & "|#" & $k)
     $sHiddenTxt = WinGetText($WinTitle)
;parse the hidden text and return what is new about it
     $sTxt = ExtractNewInfo($sHiddenTxt, $OrigHiddenTxt)
     $TVTreeList &= @CRLF & $Stem & "|#" & $j & "|#" & $k & "" & $sTxt
    Next
   Else
    ControlTreeView($WinTitle, "", $hwndTV, "Select", "#0|#" & $i & "|#" & $j)
    $sHiddenTxt = WinGetText($WinTitle)
    $sTxt = ExtractNewInfo($sHiddenTxt, $OrigHiddenTxt)
    $TVTreeList &= @CRLF & $Stem & "|#" & $j & "" & $sTxt
   EndIf
  Next
Next
AutoItSetOption("WinDetectHiddenText",0)
EndFunc
Func ExtractNewInfo($sHiddenTxt, $OrigHiddenTxt)
if $sHiddenTxt = $OrigHiddenTxt Then Return ""
Local $arNew = StringSplit($sHiddenTxt, @LF)
for $i = 1 to $arNew[0]
  if StringInStr(@LF & $OrigHiddenTxt & @LF, @LF & $arNew[$i] & @LF) = 0 Then
   if $arNew[$i] <> "Automatic" Then
    Return $arNew[$i]
   EndIf
  EndIf
Next
Return ""
EndFunc
Link to comment
Share on other sites

If you think it is an AutoIt bug then please open a ticket in Trac. Describe the problem and add a small reproducer script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'd love to, but I think it's a UDF problem rather than an AutoIt problem.

Microsoft sends a pointer to nothing in response to this line in _GuiCtrlTreeView_GetText().

_SendMessage($hWnd, $TVM_GETITEMW, 0, $pMemory, 0, "wparam", "ptr")

so that every function that depends on _GuiCtrlTreeView_GetText() ends up failing.

Link to comment
Share on other sites

But UDF problems can be reported to Trac as well. Though before you do, as water explained, create a small reproducer here first to see if the problem is the code you've written or AutoIt.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Is the treeview in a 64bit application and did you compile / run the AutoIt script as 64bit too?

See Remarks in help-file for ControlTreeView():

"As AutoIt is a 32-bit application some commands are not available when referencing a 64-bit application as Explorer when running on 64-bit Windows."

Link to comment
Share on other sites

Did you create the reproducer by any chance?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...