AutoHotkey Community

It is currently May 27th, 2012, 11:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: December 27th, 2004, 7:01 pm 
Offline

Joined: October 29th, 2004, 3:35 pm
Posts: 56
Hi, I'm trying to get the subcontrol(the control below a control) name of a control but I dont know if it's possible with Autohotkey. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2004, 7:09 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
If you haven't already, try using Window Spy. Also, the following example displays in real time the active window's control list:

#Persistent
SetTimer, WatchActiveWindow, 200
return

WatchActiveWindow:
WinGet, ControlList, ControlList, A
ToolTip, %ControlList%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2004, 7:15 pm 
Offline

Joined: October 29th, 2004, 3:35 pm
Posts: 56
Well, I've tried Windows Spy. The problem is that I need to obtain this information within the script cause the control's name is always different. Is there any way to obtain the sub-control of a control within a script? Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2004, 7:24 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Not directly, but you can click on the control at a particular set of coordinates by using ControlClick in its X/Y mode.

Also, you can find the control under the mouse cursor via MouseGetPos.

Finally you can use "WinGet, ControlList" (as shown above) to find out all the controls inside a parent window.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 4th, 2010, 6:16 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
I am interested in exactly this - I have a DirectUIHWND control that I want to check if it is a direct child of SearchEditBoxWrapperClass control or a child of a SHELLDLL_DefView class. How would I go about this - (methods provided by Chris do not apply methinks - I want to check for the parent runtime)

Thanks :)

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2010, 12:24 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Bumpy bump bump

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2010, 6:46 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Found a workaround - still interested to know why would :
Code:
F1::
   ; WinGet, hw_dialog
   ControlGetFocus hw_dialog, A
   tooltip Control with focus = %hw_dialog%
   ; hw_dialog = 2804b6
   hw_owner := DllCall("GetAncestor", uint, hw_dialog, uint, 1) ; GA_ROOTOWNER = 3 ; GA_PARENT = 1
   WinGetClass, class, ahk_id %hw_owner%
   msgbox, Owner ID: %hw_owner%`nClass: %class%
   return
return 0 when I use it and return some crazy things (another control of class BreadCrump Parent - from another explorer win) when I set hw_dialog = 2804b6 (a particular DirectUIHWND1 control)

Danke

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Last edited by Mr_and_Mrs_D on November 1st, 2011, 10:22 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2010, 6:16 pm 
Offline

Joined: October 9th, 2006, 8:19 pm
Posts: 236
Location: Finland
Mr_and_Mrs_D wrote:
Found a workaround - still interested to know why would :
Code:
F1::
   ; WinGet, hw_dialog
   ControlGetFocus hw_dialog, A
   tooltip Control with focus = %hw_dialog%
   ; hw_dialog = 2804b6
   hw_owner := DllCall("GetAncestor", uint, hw_dialog, uint, 1) ; GA_ROOTOWNER = 3 ; GA_PARENT = 1
   WinGetClass, class, ahk_id %hw_owner%
   msgbox, Owner ID: %hw_owner%`nClass: %class%
   return

A workaround? It always returns 0, unless you uncomment the line "; hw_dialog = 2804b6" or replace it with a line which transforms the control name to its handle value: "ControlGet, hw_dialog, Hwnd, , %hw_dialog%, A".

_________________
Pekka Vartto


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2010, 6:26 am 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
Code:
GetParent( aWinID, byRef aClass, byRef aMenu )
{
   aWinID:=(!aWinID ? ( (aMenu:=aWinID:=WinExist("ahk_class #32768")) ? aWinID : WinExist("A")) : aWinID )
   aParent:=DllCall( "GetParent", UInt, aWinID ) + 0
   aParent:=(( !aParent ) ? WinExist("A") + 0 : aParent )
   WinGetClass, aClass, ahk_id %aParent%
return aParent
}

#p::
{ ;; Use ToolTip instead of Interrupting MsgBox
   parentID:=GetParent("", aClass, aMenu)
   ToolTip, % "`nParentHWND of this " (aMenu ? "menu: " : "Window: ") parentID "`n`nParent's AHKClass: " aClass "`n"
   KeyWait, LWin
   KeyWait, RWin
   ToolTip
return
}

#m::
{
   parentID:=GetParent("", aClass, aMenu)
   MsgBox, % "ParentHWND of this " (aMenu ? "menu: " : "Window: ") parentID "`nClass of the Parent: " aClass "
return
}


[Edit]Small Fix to detect contextMenu's[/Edit]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2010, 8:16 am 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
StandAlone version of GetParent() [with a few Tweaks]:
Usage:
Quote:
Passing Parameters to GetParent() ::
  • Param#2 and #3: byRef variables, used to pass back additional info (should be blank).
  • (Param#1): aWinID, Must be blank or a pure HWND only. (i.e. 0x01f324 or 1145823 )
  • If aWinID is blank:: GetParent() checks †1, else 2 (else 3).
    1. Returns the Parent of any existing DropDown|Context menu's (class #32768). ELSE
    2. Returns the Parent(HWND) of the Active (topMost) Window or Dialog. ELSE
    3. Returns the HWND of the Active Window or Dialog.

† :: Class #32768 can't be detected with WinActive().
In all the cases I can think of: a DropDown/Context Menu wont exist unless it's been activated by an active window. In the rare case this might be possible, it's likely beneficial to detect this type of menu that isn't owned by the active window.

Development Notes | Observations:
Parent is generally more useful than Ancestor, e.g. the Parent of a Find Dialog, or the Parent of a ContextMenu or DropDown Menu.

Whereas when there is no valid Parent for a given "window" the Ancestor is (as far as I can tell) always the DeskTop.

Thus the GetParent function returns the Windows HWND when there is no parent. Whereas in all my tests GetParentOrAncestor is returning 65546 (when there is no valid parent), which is equivalent to DllCall("GetDesktopWindow").

Code:
HotKey, #p, GetParent, ON
HotKey, #a, GetParentOrAncestor, ON
return

GetParent( byRef aWinID, byRef aClass, byRef aMenu )
{
   aWinID:=(!aWinID ? ( (aMenu:=aWinID:=WinExist("ahk_class #32768")) ? aWinID : WinExist("A")) : aWinID )
   aParent:=( (aParent:=DllCall( "GetParent", "UInt", aWinID ) + 0) ? aParent : WinExist("A") + 0 )
   WinGetClass, aClass, ahk_id %aParent%
return aParent
}


GetParentOrAncestor( byRef aWinID, byRef aClass, byRef aMenu )
{
   aWinID:=(!aWinID ? ( (aMenu:=aWinID:=WinExist("ahk_class #32768")) ? aWinID : WinExist("A")) : aWinID )
   aParent:=( (aParent:=DllCall( "GetParent", "UInt", aWinID ) + 0) ? aParent : ( (aParent:=DllCall( "GetAncestor", "UInt", aWinID, "UInt", 1 ) + 0) ? aParent : WinExist("A") + 0 ) )
   WinGetClass, aClass, ahk_id %aParent%
return aParent
}


DisplayParent(FName)
{
   if( FName == "GetParentOrAncestor" )
      compareID:=GetParent(aWinID2, aClass2, aMenu2)
   parentID:=%FName%(aWinID, aClass, aMenu)
   if( (parentStr:="`nParent's") && compareID && ( compareID <> parentID ) )
      parentStr:="`nAncestor's"
   if((aTitle:="Menu") && !aMenu )
   {
      if( parentStr=="`nAncestor's" && parentID==DllCall("GetDesktopWindow") )
         aTitle:=" |DeskTop| "
      else
         WinGetTitle, aTitle, ahk_id %aWinID%
   }
   ToolTip, % parentStr " HWND of (" aTitle "): " parentID "`n`nParent's AHKClass: " aClass "`n"
   KeyWait, LWin
   KeyWait, RWin
   ToolTip
return
}


GetParent:
   DisplayParent("GetParent")
return

GetParentOrAncestor:
   DisplayParent("GetParentOrAncestor")
return


[Edit: Clarified Usage. The only important function is GetParent(), the rest is just a functional wrapper.]


Last edited by Crash&Burn on October 5th, 2010, 3:50 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2010, 3:47 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
@svi : workaround == different code
@Crash&Burn : thanks a lot -I am on xp now - will check it ASAP and post back

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Edd, Exabot [Bot], HotkeyStick, Yahoo [Bot] and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group