Sign in to follow this  
Followers 0
Unc3nZureD

Get Control's Title & it's Path

6 posts in this topic

#1 ·  Posted (edited)

I'm trying to retieve if a defined control exists, and if it exists then gets the related title and it's path. Here's the code I'm trying:

Opt("WinDetectHiddenText", 1)
Opt("WinTitleMatchMode", -1)
Opt("WinWaitDelay", 50)

$control = ControlGetHandle("", "[Class:SysListView32]", "")
;~ $control = ControlGetHandle("", "", "[Class:SysListView32]")

If @error = 1 Then
$title = "Null"
$Path = "Null"
Else
$title = WinGetTitle($control)
$path = _WinGetPath($title)
EndIf

While 1
ToolTip($path & @crlf & $title)
Sleep(200)
WEnd

Func _WinGetPath($Title="", $strComputer='localhost')
$win = WinGetTitle($Title)
$pid = WinGetProcess($win)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
If $objItem.ExecutablePath Then Return $objItem.ExecutablePath
Next
EndIf
EndFunc

(Does anybody know why the forum deletes the tabs?)

For example the desktop even uses this Class, that's why I'm confused, since the script returns Null all the time. Any idea why?

Edited by Unc3nZureD

Share this post


Link to post
Share on other sites



ControlGetHandle probably requires the Window's title to work correctly.


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

#3 ·  Posted (edited)

Oh, I changed the source to this:

$control = ControlGetHandle("[ACTIVE]", "[Class:SysListView32]", "")

Now it returns unbelievable goddamned random string :D

Edit:

Tried

ToolTip(WinGetTitle("[ACTIVE]", "[Class:SysListView32]"))

But it returns the currently active window, even if it doesn't have that Class.

Edited by Unc3nZureD

Share this post


Link to post
Share on other sites

Here's a change to your script that will update the tooltip as you move from window to window.

Opt("WinDetectHiddenText", 1)
Opt("WinTitleMatchMode", -1)
Opt("WinWaitDelay", 50)


While 1
     $control = ControlGetHandle("[ACTIVE]", "[Class:SysListView32]", "")
;~ $control = ControlGetHandle("", "", "[Class:SysListView32]")

     If @error = 1 Then
          $title = "Null"
          $Path = "Null"
     Else
          $title = WinGetTitle($control)
          $Path = _WinGetPath($title)
     EndIf
     ToolTip($Path & @CRLF & $title)
     Sleep(200)
WEnd

Func _WinGetPath($title = "", $strComputer = 'localhost')
     $win = WinGetTitle($title)
     $pid = WinGetProcess($win)
     $wbemFlagReturnImmediately = 0x10
     $wbemFlagForwardOnly = 0x20
     $colItems = ""
     $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _
               $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
     If IsObj($colItems) Then
          For $objItem In $colItems
               If $objItem.ExecutablePath Then Return $objItem.ExecutablePath
          Next
     EndIf
EndFunc   ;==>_WinGetPath

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

#5 ·  Posted (edited)

Hah :) I forgot it. That was a nice idea but sadly the result is still a huge mess.

Hey! An idea... Does WinGetTitle accept HWND at all?! I have to look into it...

Edited by Unc3nZureD

Share this post


Link to post
Share on other sites

Yes, WinGetTitle will work with a handle instead of an actual title. BTW, when I changed your script I copied over an error that you had in your original script.

;this line
$control = ControlGetHandle("[ACTIVE]", "[Class:SysListView32]", "")
; should be like this
$control = ControlGetHandle("[ACTIVE]", "", "[Class:SysListView32]")
; You had the control in the text position in the function, which is why it would return something for every active window.

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

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