Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Class Name instead of Class ID



  • Please log in to reply
9 replies to this topic
cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

Hello all!

 

  I have a class id that constantly changes, but the name never does.  So I was trying to the below code with the Class Name instead of the ID, but MouseGetPos only seems to respond with the ID.

 

Is there a way to use the MouseGetPos command with a Class Name instead of the actual ClassNN (ID)?

 

MouseGetPos,,,, ClassNN
if ClassNN = SunBox

Thank you!

 



GEV
  • Members
  • 1364 posts
  • Last active:
  • Joined: 23 Oct 2013
Loop
{
 MouseGetPos,,,, Controlname
 If Controlname = SunBox
  ToolTip, SunBox
 else
  ToolTip
}
return


cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

Gev thanks for you reply!

 

However that only works if I replace "Controlname = SunBox" with "Controlname = WindowsForm.17ac012" (the actual Class ID).  Any way to get it to work without the Class ID?  I want to be able to use the Class Name "SunBox".

 

Thank you!



GEV
  • Members
  • 1364 posts
  • Last active:
  • Joined: 23 Oct 2013

This works for me

#Persistent

SetTimer, Controlname, 500
return

Controlname:
MouseGetPos,,,, ClassNN
ToolTip, %ClassNN%
return

"ClassNN" in the Tooltip is the same as in Window Spy



cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

GEV you are correct that does work.  

 

Perhaps I didn't explain myself clearly (I apologize).  I want to make sure I know when a specific button is clicked.  I found a way by using MouseGetPos, but it only seems to work by using the ClassNN instead of class text (name).

 

Window spy reports:

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: WindowsForms.03ad136 -- Can't use this because it constantly changes
Text: Sun Box -- I want to use this
 
This is what I have so far, but doesn't work with the Text (name):
~LButton::
MouseGetPos,,,, ControlText
if ControlText = Sun Box
msgbox, good to go
else
msgbox, no go


cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

Or perhaps there is a way to find the ClassNN by using the Class Text?



GEV
  • Members
  • 1364 posts
  • Last active:
  • Joined: 23 Oct 2013

 

ClassNN: WindowsForms.03ad136 -- Can't use this because it constantly changes

You could use only a part of this name in your script (the part that always appears in Window Spy) :

~LButton::
MouseGetPos,,,, ControlText
IfInString, ControlText, WindowsForms.03ad  ; use only the part of the ControlText that always appears in Window Spy
  msgbox, good to go
else
  msgbox, no go


cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

Well yes I'm still working on this.  I wasn't able to use part of the class name due to several others having a similar name.  Also unfortunately I wasn't able to figure out how to retrieve the ClassNN via the Class Text (I think would be my best option).  However I think I found a solution using the Hwnd instead (although I've never used Hwnd before and not familiar with it).

 

Back to my main point, I have this below but it always tells me it's a "no go" even though it appears to match.  Also sometimes the button is not there the "hCtrl" throws an error because it's blank.  Any way to prevent the error?  Any suggestions?

 

#Persistent
~LButton::
ControlGet, hCtrl, Hwnd,, Sun Box, Micro
MouseGetPos,,,, ClassNN, 2
msgbox, %hCtrl% -- %ClassNN%
Ifinstring, %hCtrl%, %ClassNN%
msgbox, good to go
else
msgbox, no go
return


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
✓  Best Answer

tried this

;- Test, Click Button TEST4 = OK
;- esc > quit

f1=%a_scriptdir%\test55.ahk
e4x=
(
Gui,2:default
Gui,2:add,button, x10 y10 h25 w100,TEST1
Gui,2:show,x0 y0 h70 w200,TEST4
return
2Guiclose:
exitapp
)
ifnotexist,%f1%
  fileappend,%e4x%,%f1%
run,%f1%
return


#Persistent
#singleinstance,force
~LButton::
ControlGet, hCtrl, Hwnd,,TEST1, TEST4
MouseGetPos,,,, ClassNN, 2
msgbox, 262208, , %hCtrl% -- %ClassNN%,2
If (hCtrl=ClassNN)
msgbox, 262208, , good to go,1
  else
msgbox, 262208, , no go,1
return
esc::exitapp



cjsmile999
  • Members
  • 78 posts
  • Last active: Nov 18 2016 05:24 AM
  • Joined: 29 Jun 2009

Bingo thank you for your help!