If WinExist, ClassNN Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

If WinExist, ClassNN

18 Mar 2017, 08:29

Hello Fellow AHK friends!

I have been on the hunt to find a working functioning method to execute my idea.

GOAL: Wait for a classNN to exist, then continue.

NOTE: This isn't my actual code for what I am trying to do, all of that is stored at work. This is just an example.

My code that isn't working.....below.
------------------------------
-----------------------------


#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force

home::

;not sure how to add a loop in here, but I think I need one in order for it to wait for class

#If WinExist("ahk_class button1")
{
ControlClick, Button1, MacroGamer, , Left, 1
sleep, 10
return
}


IfWinNotExist("ahk_class button1") ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it.
{

Msgbox not found
}

return

---------------------------
---------------------------


So while this code may get working, I need to also comment that the program I'm using at work has an environment inside of it. So to have WinWaitActive, yadaya - won't work. This is why I want to wait for a class. I am closing accounts at work.

I hope this is enough information and my goal is clear. Any help is appreciated.

Thank you,

Vh_
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: If WinExist, ClassNN

18 Mar 2017, 09:33

You might be interested in SetTimer, eg,

Code: Select all

#Persistent
SetTimer, checkIfClassExist, 100

return
checkIfClassExist:
	If WinExist("ahk_class button1")
	{
		ControlClick, Button1, MacroGamer, , Left, 1
		sleep, 10
		return
	}
	else ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it.
	{
		Msgbox not found 
	}
return
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

18 Mar 2017, 10:13

Helgef wrote:You might be interested in SetTimer, eg,

Code: Select all

#Persistent
SetTimer, checkIfClassExist, 100

return
checkIfClassExist:
	If WinExist("ahk_class button1")
	{
		ControlClick, Button1, MacroGamer, , Left, 1
		sleep, 10
		return
	}
	else ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it.
	{
		Msgbox not found 
	}
return
this code doesn't work :/
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

18 Mar 2017, 10:15

Still hops directly to msgbox when Button1 is present
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: If WinExist, ClassNN

18 Mar 2017, 10:41

That means that WinExist(...) returns 0. See WinExist, WinTitle and ControlClick.
Vh__

Re: If WinExist, ClassNN

19 Mar 2017, 09:30

I read these docs and can't seemingly connect the dots.. can you give an example please?

Thank you! :)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: If WinExist, ClassNN

19 Mar 2017, 09:54

My guess is, Button1 is the ClassNN of a control, not the window class of the window in which the control resides. So, instead of WinExist("ahk_class Button1"), you migth identify the window which holds the control (Button1) by other means, eg, open WindowSpy and hover the mouse over the window, at the top, you'll see ahk_class something, use that instead, or ahk_exe something.exe. Here is an example,
Image

Good luck.
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

19 Mar 2017, 13:49

Thanks for the reply!

Here is the thing.While I can tell it to identify with the program name, my purpose is for a program at work that has an environment inside of the window. So the program will exist. I want it to execute upon class existence rather window exist. does that make sense?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: If WinExist, ClassNN

19 Mar 2017, 14:06

Consider this,

Code: Select all

Gui, add, button,, hi
Gui show
MsgBox, % WinExist("ahk_class Button1")
ExitApp
You can use WinGet to get a list of controls for a window of your choise.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: If WinExist, ClassNN

19 Mar 2017, 14:22

Code: Select all

q:: ;check control (ClassNN) exists
;try this on Notepad and on Notepad's Find dialog
ControlGet, hCtl, Hwnd, , Button1, A
if hCtl
	MsgBox % "control exists"
else
	MsgBox % "control doesn't exist"
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

19 Mar 2017, 19:57

Im sorry jeeswg, control existed in either state.. I am starting to think this is not possible with AHK. :(
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

19 Mar 2017, 20:19

ok guys. here is the actual code. See line 42 with ControlClick
---------------------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force


Gui, +Caption
Gui, +AlwaysOnTop
Gui, Add, Text, x10 y5 +BackgroundTrans cWhite, Status ;add colored text in options, (after x/y coord. eg, cBlue)
Gui, Add, DropDownList, x10 y20 w180 h100 vStatus, CLOSED|INACTIVE|ACTIVE|PENDING
Gui, Add, Text, x10 y45 +BackgroundTrans cWhite, Note
Gui, Add, Edit, x10 y60 w180 h50 vMyEdit
Gui, Add, Text, x10 y114 +BackgroundTrans cWhite, Bind Key
Gui, Add, Hotkey, x10 y+4 w180 h20, vChosenHotkey gHotkey
Gui, Add, Text, x10 y160 +BackgroundTrans cWhite, Run without key (optional)
Gui, Add, Button, x10 y175 w180 h30 gOK , Run
Gui, Color, 474747

Gui, Show, w200 h220, Assistant ;Window title is Account Assistant

return

; Labels
;---------------
;----------------------
;-------------------------------
OK:

Gui, Submit, NoHide

SetTitleMatchMode, 2
WinActivate, PAYCheque
IfWinActive, PAYCheque

{

ControlClick, ThunderRT6ListBox1 ;This is where I want it to wait for the class to exist before continuing

sleep, 1

if (Status = "CLOSED")
{
Send, C
} else if (Status = "INACTIVE") {
Send, I
} else if (Status = "ACTIVE") {
Send, A
else if (Status = "PENDING") {
Send, P
}

Send, {tab}
sleep, 1
Send, %MyEdit%
}
return

Hotkey:

If (ChosenHotkey)

{
Hotkey, %ChosenHotkey%, OK
}

return
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: If WinExist, ClassNN  Topic is solved

19 Mar 2017, 20:42

as mentioned on irc (for others to see), just toss in

Code: Select all

loop
{
	sleep, 50
	ControlGet, hCtl, Hwnd, , ThunderRT6ListBox1, INSERT THE WINDOW TITLE HERE
}
until (errorlevel=0)
where "INSERT THE WINDOW TITLE HERE" is the ahk_class (as shown by helgef) or the actual title, if it never changes
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: If WinExist, ClassNN

19 Mar 2017, 20:43

It looks to me you could use the example code jeeswg gave to loop check if the control exists before continuing.
something like:

Code: Select all

loop
{
	ControlGet, hCtl, Hwnd, , ThunderRT6ListBox1, A ; (If its not in the active window change 'A' to be the window it is in, either its name or class.)
	if hCtl
		Break
}
ControlClick, ThunderRT6ListBox1
I'm not sure this is the best way to accomplish what you want but it should work.

**Edit I guess I'm a tad bit too slow.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: If WinExist, ClassNN

20 Mar 2017, 00:53

You could also check if the control is enabled or visible.

Code: Select all

q:: ;check if control exists/is enabled/is visible (+ get styles)
vCtlClassNN := "Button1"
WinGet, hWnd, ID, A
ControlGet, hCtl, Hwnd, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vIsEnabled, Enabled, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vIsVisible, Visible, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlStyle, Style, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlExStyle, ExStyle, , % vCtlClassNN, % "ahk_id " hWnd

vOutput := hCtl " -- " vIsEnabled " -- " vIsVisible " -- " vCtlStyle " -- " vCtlExStyle
Clipboard := vOutput
MsgBox % vOutput
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: If WinExist, ClassNN

20 Mar 2017, 17:17

Ladies & Gentlemen. I must extend great appreciation for joining me on this quest. I deem this solved. Thank you for your patience and EXCELLENT INPUT, ALL!

Vh
:D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Google [Bot], marypoppins_1 and 116 guests