Sign in to follow this  
Followers 0
Exit

What is wrong with my _GUICtrlTreeView_GetText() ?

9 posts in this topic

The _GUICtrlTreeView_GetText() function returns an empty string.

#include <GuiTreeView.au3>
While WinClose("[class:MMCMainFrame]") ; close all device manager windows
WEnd
Run("mmc devmgmt.msc")
$winhandle = WinWaitActive("[class:MMCMainFrame]")
$hWnd = ControlGetHandle($winhandle, "", "[Class:SysTreeView32;Instance:1]")
ControlFocus($winhandle, "", $hWnd)
$hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
While Sleep(50)
$text = _GUICtrlTreeView_GetText($hWnd, $hItem) ; <======= get text
ConsoleWrite($hItem & ">" & $text & "<" & @LF)   ; <======= show text
$hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
If $hItem = 0 Then ExitLoop
_GUICtrlTreeView_SelectItem($hWnd, $hItem, $TVGN_CARET)
WEnd
Exit

Console output:

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
0x002C7340><
0x03488D60><
0x03488DC0><
0x03488E20><
.........
.........
.........
0x002C72E0><
0x002C71C0><
0x002C7220><
0x002C7160><
0x002C70A0><
+>01:05:15 AutoIT3.exe ended.rc:0

Where is the bug ?


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Please be more specific or give an example how to read the text entries of the devicemanagers treeview.

Thanks.

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Thanks for the link. The information is new and valuable to me.

There are two programs mentioned.

1.) DevCon.exe

Not applicable since it needs a separate installation of WDK.

The users of my program have no installed copy of this program.

2.) PNPUtil.exe

Is 'out of the box'. No installation needed.

But does not show the text of the devicemanager treeview.

Back to my original question.

What is wrong with my code ? Why I get empty text strings?

The function _GUICtrlTreeView_GetText() returns @error=0 and @extended=0

Here a new version of the code with @error and @extended display included

and a messagebox to see results in compiled version.

#include <GuiTreeView.au3>
While WinClose("[class:MMCMainFrame]") ; close all device manager windows
WEnd
$t = ""
Run("mmc devmgmt.msc")
$winhandle = WinWaitActive("[class:MMCMainFrame]", "", 3)
$hWnd = ControlGetHandle($winhandle, "", "[Class:SysTreeView32;Instance:1]")
ControlFocus($winhandle, "", $hWnd)
$hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
While Sleep(50)
$text = _GUICtrlTreeView_GetText($hWnd, $hItem) ; read the text
$t1 = @error & " " & @extended & " " & $hItem & ">" & $text & "<" & @LF
ConsoleWrite($t1) ; and show
$t &= $t1
$hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
If $hItem = 0 Then ExitLoop
_GUICtrlTreeView_SelectItem($hWnd, $hItem, $TVGN_CARET) ; to show, that the items are correct. See the blue selection of text moving down.
WEnd
MsgBox(262144, " ", $t, 0)
Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Works fine for me if I use #RequireAdmin on Windows 7 x64. I get nothing if I don't run it as Admin though, it won't even run the device manager.

EDIT: BTW, you should check out DevManView from Nirsoft.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Works fine for me if I use #RequireAdmin on Windows 7 x64. I get nothing if I don't run it as Admin though, it won't even run the device manager.

EDIT: BTW, you should check out DevManView from Nirsoft.

Thanks for your feedback.

DevManView is no option since my program will be used by other users who are not willing to install another software.

I compiled it with X64 and without #requireadmin

My system is WIN7 x64

Now, the text is shown.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

DevManView doesn't need to be installed, and you can FileInstall it in the compiled exe, and if needed delete it as you exit the script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I compiled my script on a Win7 x86 and it works there too.

Conclusion:

_GUICtrlTreeView_GetText() works ok in x86 mode on a x86 machine and in x64 mode on a x64 machine.

But not in x86 mode on a x64 machine.

I will fileinstall both exe's in a x86 wrapper exe.

No need to fileinstall DevManView.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

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  
Followers 0