Jump to content
Sign in to follow this  
rodent1

unable to control a treeview under windows 8 64

Recommended Posts

rodent1

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

Share this post


Link to post
Share on other sites
rodent1

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.

Share this post


Link to post
Share on other sites
rodent1

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
rodent1

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.

Share this post


Link to post
Share on other sites
guinness

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

Share this post


Link to post
Share on other sites
KaFu

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."

Share this post


Link to post
Share on other sites
rodent1

yes, I build my print automation autoIt script with #AutoIt3Wrapper_UseX64=y and use it in 64 bit environments. Good thought, though.

Share this post


Link to post
Share on other sites
guinness

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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Sven-Seyfert
      By Sven-Seyfert
       
      Hi Community,

      I have a problem with the usage of _GUICtrlTreeView_AddChild and setting different item text colors (and different background colors), separately for the TreeView levels.

      I use the UDF GUITreeViewEx.au3 of 'Melba23' and I renamed the functions to increase my understanding about the content. I already talked to him about his UDF to respect his rights and intellectual property. I read many forum threads, I tried many ways to get it, but it's seems to be impossible in the way that I use the UDF.

      Question:
      How can I set different item text colors, separately for the TreeView levels?
      How can I set different item background colors, separately for the TreeView levels?

      I found out that _GUICtrlTreeView_AddChild don't let my set this properties directly. But after loading the TreeView content I can't change the items (children) too. Only the font weight to bold I could set with _GUICtrlTreeView_SetBold but I want to do this in a generic way directly at the creation (loading) of the TreeView.

      Of course I tried the different functions to set text color or bkgColor, but it didn't work - maybe I do it wrong.
      I really hope you can help me, give me a hint and understand what I want to do.
      [Solved] final solution made by @LarsJ (see below)

      Thanks for your help - I'm grateful!
      Sven

      CODE
      BEFORE
      AFTER
      ExecutionPlan.zip
    • gillesg
      By gillesg
      Hello,
      I am struggling in merging GUITreeViewEx, Shelltristate and enhancing to handle a third state that means : some items under are selected.
      I have difficulties handling expand order and key Space (especially when node is collapsed).
      Here the zip with UDF and and example.
       
      The problem I might need some advice to handle : 
      1- When load Treeview, have a correct settings of the checkbox for a tristate tree
      2 - Handle keyboard used for walking in tree
           Chicken is checked and  Steak is unchecked
          When walking with arrow to Meat, it gets unchecked
      3 - When node is collapsed and checked thru keyboard (space)
         the middle state is possible which should not
      Here is joined an animated gif showing the 3 problems
       
      Thanks for your advices
       
       
       
       
       
       
       
       
       
       
       

      GUITreeview3Ex.zip
    • gillesg
      By gillesg
      Hello,
      I just bumped into this problem with _GUICtrlTreeView_Sort.
      Just used doc example and comment out the child creation
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Example() Func Example() Local $aidItem[10], $iX = 9, $iY = 29, $idTreeView Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) GUICreate("TreeView Sort", 400, 300) $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) _GUICtrlTreeView_BeginUpdate($idTreeView) For $x = 0 To 3 $aidItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $iX), $idTreeView) $iX -= 1 For $y = 1 To 3 ; GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $iY), $aidItem[$x]) $iY -= 1 Next Next _GUICtrlTreeView_Expand($idTreeView) _GUICtrlTreeView_EndUpdate($idTreeView) MsgBox($MB_SYSTEMMODAL, "Information", "Sort") _GUICtrlTreeView_Sort($idTreeView) _GUICtrlTreeView_SelectItem($idTreeView, $aidItem[9]) ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example The tree is not sorted.
       
      There is a similar problem with deeper tree
      Also based on the example
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Example() Func Example() Local $aidItem[10], $bidItem[10], $iX = 9, $iY = 29, $idTreeView Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) GUICreate("TreeView Sort", 400, 300) $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) _GUICtrlTreeView_BeginUpdate($idTreeView) $index=0 For $x = 0 To 3 $aidItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $iX), $idTreeView) $iX -= 1 For $y = 1 To 2 $BidItem[$y]= GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $iY), $aidItem[$x]) $iY -= 1 For $z= 1 To 2 GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $iY), $BidItem[$y]) $iY -= 1 Next Next Next _GUICtrlTreeView_Expand($idTreeView) _GUICtrlTreeView_EndUpdate($idTreeView) MsgBox($MB_SYSTEMMODAL, "Information", "Sort") _GUICtrlTreeView_Sort($idTreeView) _GUICtrlTreeView_SelectItem($idTreeView, $aidItem[9]) ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example The tree is now 2 level deep and it is not properly sorted.
       
      Any advices ?
       
      Regards
    • corgano
      By corgano
      I can't explain easily what i want to do, so i made a picture:

      What i want to do is to specify a treeview item, and then be able to move it right to be a child of the previous item, or left to do the opposite (make a child into a sibling). I also want to move and child items of the target with it, like in the bottom half of the above image depicts. However I didn't see any functions in the help file to move items around. All i want is a button that when pressed, makes the selected item and any of selected item's children move one layer to the right / left. Does anyone know how?

      Edit: something along the lines of _GUICtrlTreeView_Level but SET level
    • Tjalve
      By Tjalve
      Hi everyone. Im creating a GUI for an application. Im usinga  treeview item and i want to add some information to the side of the treeview based on what cilditem you are pressing. For the moment i have a "get info" button that works. But that means that you have to select your child in the treeview, and then press a button to gte the info. I want the info to be visable as soon as you select it.
      With uther controls you can just add it to the loop but it doesnt seem to work with tyhe UDF version of the treeview control. Is there anything I can do?
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> ;~ Create GUI dim $guilabel[7] local $currentlevel = 1 Local $hGui = GUICreate( "Grejs", 1000, 500, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) ) Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui ) $idTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30 ) $root_level = _GUICtrlTreeView_Add($idTV,0,"Root") $item1 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child1") $item2 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child2") $item3 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child3") ;~ Start Gui GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idTV MsgBox(0,"","") EndSwitch WEnd GUIDelete($hGui) Exit In this example, i want the msgbox to appear whenevr i select something in the treeview. It ios not my full code, but its an example of the problam i have. Help is much appritiated
      /G
×