Page 1 of 1

Apply action only to a certain type of ClassNN control

Posted: 17 Jan 2022, 18:50
by Lem2001
I want to run some code (within a specific application) whenever a ComboBox control has focus, and some different code if a multi-line text edit box has focus. For any other type of control other than these two, nothing should be done.

I've looked at GUIControlGet but it only seems to retrieve things like the actual content of the ComboBox (or its class name or position or whatever) but I can't figure out how to do determine the type of control that it is, so that I can single out ComboBoxes and Multi-line text edit boxes (not single-line edit boxes).

I want to do something like this:

if currently active control is of type: ComboBox, then do <this>
if currently active control is of type: Multi-line text edit, then do <that>
... else do nothing.


Any help appreciated.

Re: Apply action only to a certain type of ClassNN control

Posted: 18 Jan 2022, 03:51
by lmstearn
Hi, an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable- check out the code for sure.
Multiline edit boxes have the ES_MULTILINE style, once you have the handle of the control, use WinGet to retrieve the style. :)

Re: Apply action only to a certain type of ClassNN control

Posted: 18 Jan 2022, 04:26
by gregster
lmstearn wrote:
18 Jan 2022, 03:51
an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable
AU3_Spy hasn't been included anymore in recent AHK versions, afaik.
But it's news to me that WindowSpy - which replaced it - should be less reliable.

Re: Apply action only to a certain type of ClassNN control

Posted: 18 Jan 2022, 04:40
by amateur+

Re: Apply action only to a certain type of ClassNN control

Posted: 18 Jan 2022, 08:19
by lmstearn
gregster wrote:
18 Jan 2022, 04:26
lmstearn wrote:
18 Jan 2022, 03:51
an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable
AU3_Spy hasn't been included anymore in recent AHK versions, afaik.
But it's news to me that WindowSpy - which replaced it - should be less reliable.
AU3_Spy only gets removed if AHK is uninstalled, so long time users like me never knew. ;) Reliable is a bad word, the script won't pick up the controls in some apps, e.g. Chrome, MS Teams, Windows Snipping Tool. Amateur's linked script looks like it will do the job. :)

Re: Apply action only to a certain type of ClassNN control

Posted: 19 Jan 2022, 21:45
by Lem2001
lmstearn wrote:
18 Jan 2022, 03:51
once you have the handle of the control, use WinGet ...
Thanks very much for your reply.

I know how to use WinSpy, but I don't understand what you mean by the "handle" of "the control".

Spy only shows the class name and there are masses of these combo boxes in this app (and their classNN names constantly change) so trying to target each one individually is not feasible or desirable. That's why I want to select only based on type of control (or, as it seems to be referred to by WinGet, "style" of control).

Re: Apply action only to a certain type of ClassNN control  Topic is solved

Posted: 19 Jan 2022, 22:07
by lmstearn
Here's info on the handle or HWND, along with a thread.
Dr. Google also helped out by retrieving @LinearSpoon's contribution to this thread. :)

Re: Apply action only to a certain type of ClassNN control

Posted: 20 Jan 2022, 05:44
by SOTE
@Lem2001

ahk_id/handle/HWND

"Each window or control has a unique ID, also known as a HWND (short for handle to window). This ID can be used to identify the window or control..."

You can even quickly code your own simple version of AU3/AHK/WindowSpy to display info that you want, like below.

Code: Select all

#Persistent
SetTimer, CursorWatch, 200
return

^p::pause

^g::
ControlGetText, WinInfo,,ahk_class tooltips_class32
WinInfo := StrReplace(WinInfo, A_Space . A_Space, "`r`n")
WinInfo := LTrim(WinInfo)
ClipBoard := WinInfo
Return

CursorWatch:
MouseGetPos, OutputVarX, OutputVarY, id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
WinGet, ActivePath, ProcessPath, A
ControlGetText, ControlText, %control%, A
ControlGet, ControlHwnd, Hwnd,, %control%, A
PixelGetColor, color, %OutputVarX%, %OutputVarY%
If not WinActive("Notepad") AND (control != "Edit1")
{
	ToolTip, ahk_id: %id%  `nahk_class: %class%  `nWindow Title: %title%  `nActive Path: %ActivePath%  `nControl: %control%  `nControlText: %ControlText%  `nMousePos: %OutputVarX%x%OutputVarY%  `nColor: %color%  `nCursor Info: %A_Cursor%
}
return

esc::ExitApp

Re: Apply action only to a certain type of ClassNN control

Posted: 08 Mar 2022, 06:50
by Lem2001
lmstearn wrote:
19 Jan 2022, 22:07
Here's info on the handle or HWND, along with a thread.
Dr. Google also helped out by retrieving @LinearSpoon's contribution to this thread. :)
Thank you @lmstearn. I've now managed to get it working exactly as I wanted.

Re: Apply action only to a certain type of ClassNN control

Posted: 09 Aug 2022, 03:45
by NopryGoul
Thanks a lot for your help. I had the same problem and had no idea what to do. Actually, I've tried everything except your suggestion, and I'm glad it's worked. Thanks a lot. Btw, I work at [link removed by moderator], so you've helped me improve the site, so I'm really grateful to you. Actually, I'd like to say that I love this community so much. Tbh, I've never seen so many people being ready to help each other totally selflessly. That's what society needs. That's what the world needs, I'd say. So I really appreciate your help. Keep us updated. Best wishes


[Moderator note: This post was apparently edited days after it was posted to add a link to a site, which has been removed. You really should be banned for this. Last warning.]