get classNN from Control hwnd Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Taurus
Posts: 89
Joined: 20 Jan 2015, 10:31

get classNN from Control hwnd

15 Oct 2020, 10:06

Hi,

i am using

Code: Select all

WinGet Clist, ControlList, % WinID
because the classes of the window are like
ahk_class layout_window_t#6
1
ahk_class gui.tabbar_panel#34
1
(= classes with linebreak adding 1, so i cannot use Loop Parse, CList, `n)

Spy is telling the right name:

Code: Select all

MouseGetPos, msX, msY, msWin, msCtrlHwnd, 2

>>> So how do i get the classNN from Control hwnd?
Last edited by Taurus on 16 Oct 2020, 03:01, edited 1 time in total.
:beard: Full Stack Developer > Dev for a better world | PHP for Web | AHK H for Local | with KISS (Keep IT Short and Simple) on Win 10 Pro (Version 2004) x64
User avatar
mikeyww
Posts: 2140
Joined: 09 Sep 2014, 18:38

Re: get classNN from Control hwnd

15 Oct 2020, 10:10

Code: Select all

str =
(
ahk_class layout_window_t#6
1
ahk_class gui.tabbar_panel#34
1
)
classes =
Loop, Parse, str, `n, `r
 classes .= (toggle := !toggle) ? A_LoopField "`n" : ""
MsgBox, 64, Classes, %classes%
If you want an array:

Code: Select all

str =
(
ahk_class layout_window_t#6
1
ahk_class gui.tabbar_panel#34
1
)
class := [], classes := ""
Loop, Parse, str, `n, `r
 If (toggle := !toggle)
  class.Push(A_LoopField), classes .= A_LoopField "`n"
MsgBox, 64, Classes, %classes%
User avatar
Taurus
Posts: 89
Joined: 20 Jan 2015, 10:31

Re: get classNN from Control hwnd

16 Oct 2020, 03:01

How does this help getting the classNN from Control hwnd?
:beard: Full Stack Developer > Dev for a better world | PHP for Web | AHK H for Local | with KISS (Keep IT Short and Simple) on Win 10 Pro (Version 2004) x64
User avatar
SKAN
Posts: 853
Joined: 29 Sep 2013, 16:58

ClassNN()

16 Oct 2020, 04:06

Taurus wrote:
15 Oct 2020, 10:06
how do i get the classNN from Control hwnd?
 
Quickly written. Let me know if this helps:
 

Code: Select all

ClassNN( hCtrl ) {                                     ; By SKAN on D3AG @ tiny.cc/classnn
Local   hWnd := "", NN := "", Class, hPar
  WinGetClass, Class, ahk_id %hCtrl%
  If ( (hPar := DllCall("GetAncestor", "Ptr",hCtrl, "Int",2, "Ptr")) != hCtrl )  ; GA_ROOT
  While ( hWnd!=0 && hWnd!=hCtrl )
      hWnd := DllCall("FindWindowEx", "Ptr",hPar, "Ptr",hWnd, "Str",Class, "Ptr",0, "Ptr")
    , NN := A_Index
Return hWnd ? (Class . NN) : ""
}
teadrinker
Posts: 1900
Joined: 29 Mar 2015, 09:41
Contact:

Re: get classNN from Control hwnd  Topic is solved

16 Oct 2020, 06:15

A couple of options:

Code: Select all

GetClassNN(hCtrl, isEnum := "") {
   static GA_ROOT := 2, info, className, _ := VarSetCapacity(className, 200 << !!A_IsUnicode, 0)
   DllCall("GetClassName", "Ptr", hCtrl, "Str", className, "Int", 200)
   if isEnum {
      (className = info.class && info.count++)
      Return info.handle != hCtrl
   }
   else {
      hParent := DllCall("GetAncestor", "Ptr", hCtrl, "UInt", GA_ROOT, "Ptr")
      info := {handle: hCtrl, class: className, count: 0}
      DllCall("EnumChildWindows", "Ptr", hParent, "Ptr", RegisterCallback(A_ThisFunc, "Fast", 2), "Ptr", true)
      Return className . info.count
   }
}

GetClassNN2(hCtrl) {
   hParent := DllCall("GetAncestor", "Ptr", hCtrl, "UInt", GA_ROOT := 2, "Ptr")
   WinGet, ctrList, ControlList, ahk_id %hParent%
   WinGet, ctrListID, ControlListHWND, ahk_id %hParent%
   ctrListArr := StrSplit(ctrList, "`n")
   ctrListIDArr := StrSplit(ctrListID, "`n")
   found := 0
   for k, v in ctrListIDArr {
      if (v = hCtrl && found := ctrListArr[k])
         break
   }
   Return found
}
Last edited by teadrinker on 16 Oct 2020, 10:19, edited 1 time in total.
User avatar
mikeyww
Posts: 2140
Joined: 09 Sep 2014, 18:38

Re: get classNN from Control hwnd

16 Oct 2020, 07:03

Sorry I misunderstood what you wanted.
User avatar
Taurus
Posts: 89
Joined: 20 Jan 2015, 10:31

Re: get classNN from Control hwnd

18 Oct 2020, 04:07

Perfect, it's working. Thanks! :thumbup:
:beard: Full Stack Developer > Dev for a better world | PHP for Web | AHK H for Local | with KISS (Keep IT Short and Simple) on Win 10 Pro (Version 2004) x64

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, Bing [Bot], DaveT1, JoeWinograd, LakaiHigh, mikeyww, TheProdigyC2, TXShooter and 82 guests