 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Watcher
Joined: 28 Dec 2004 Posts: 60
|
Posted: Mon Feb 21, 2005 9:57 pm Post subject: Diffinitive addressing of controls |
|
|
In all the time I've been coding with AHK my biggest frustration is to be able to KNOW I'm addressing a specific control. Is there any way to define a control that can always be addressed specifically?
| Code: |
Gui Add, Button, , 1
|
Ok, I have 3000 buttons made like that (not really but for this example) and I want to change each button one by one to have a different label. I don't want to get out window spy and check with that and besides if I change my layout button1 can become button2 because I moved it and now my code doesn't work.
I have tried adding the vMyvar technique but it still seems to find 1 instead of myvar, the issue is not one of what the button should do wehn pressed, it's one of how do I change the label or check the focus or whatever else. I want that button to have a name or address that I can Always refer to it with. Something like
| Code: |
Gui Add, Button, nMyButton
|
So now that it has a name (MyButton) I can always refer to it with:
| Code: |
GuiControl, Hide, MyButton
|
and KNOW which one will get hidden. Am I missing something? If so please enlighten me.
[/code] |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Mon Feb 21, 2005 10:12 pm Post subject: |
|
|
GuiControl and GuiControlGet are designed to work with variables. In fact, the only use for a variable for a non-editing control like a button or a picture is to "name" it, just like you alluded to. I would be surprised if this didn't work:
| Code: | Gui, Add, Button, vMyButton, Button 1
GuiControl, Hide, MyButton |
|
|
| Back to top |
|
 |
Watcher
Joined: 28 Dec 2004 Posts: 60
|
Posted: Mon Feb 21, 2005 10:46 pm Post subject: |
|
|
Ok, let's do it this way... This code does not do as expected...
| Code: |
WinTitle = MyButtons
Gui, Add, Button, x+10 vMyButton1, 1
Gui, Add, Button, x+10 vMyButton2, 2
Gui, Add, Button, x+10 vMyButton3, 3
Gui Show,, %WinTitle%
Sleep 5000
ToolTip Changing buttons now.
ControlSetText MyButton1, 2, %WinTitle%
ControlSetText MyButton2, 3, %WinTitle%
ControlSetText MyButton3, 1, %WinTitle%
Sleep 5000
ExitApp
|
Am I doing it wrong? |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Mon Feb 21, 2005 11:46 pm Post subject: |
|
|
I hate to say it... but, yes.
| Code: | WinTitle = MyButtons
Gui, Add, Button, x+10 vMyButton1, 1
Gui, Add, Button, x+10 vMyButton2, 2
Gui, Add, Button, x+10 vMyButton3, 3
Gui Show,, %WinTitle%
Sleep 5000
ToolTip Changing buttons now.
GuiControl,, MyButton1, 2
GuiControl,, MyButton2, 3
GuiControl,, MyButton3, 1
Sleep 5000
ExitApp |
 |
|
| Back to top |
|
 |
Watcher
Joined: 28 Dec 2004 Posts: 60
|
Posted: Tue Feb 22, 2005 12:09 am Post subject: |
|
|
Well I'm thrilled you said it, but let's try again, how about this one:
| Code: |
WinTitle = MyButtons
Gui, Add, Button, x+10 vMyButton1, 1
Gui, Add, Button, x+10 vMyButton2, 2
Gui, Add, Button, x+10 vMyButton3, 3
Gui Show,, %WinTitle%
ToolTip Changing buttons now.
Sleep 5000
GuiControl,, MyButton1, 2
GuiControl,, MyButton2, 3
GuiControl,, MyButton3, 1
ToolTip Clicking 1
Sleep 2000
ControlClick MyButton1, %WinTitle%,,Left
ToolTip Clicking 2
Sleep 2000
ControlClick MyButton2, %WinTitle%,,Left
ToolTip Clicking 3
Sleep 2000
ControlClick MyButton3, %WinTitle%,,Left
Sleep 5000
ExitApp
|
I hope this one is as simple as the last one. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Feb 22, 2005 1:26 am Post subject: |
|
|
The variable-referencing method can only be used by GuiControl and GuiControlGet, unfortunately. To get around this, retrieve the current text of the control using GuiControlGet, as shown below. I attached labels to the buttons to show that they're actually being clicked, since it might be too fast to see.
| Code: | WinTitle = MyButtons
Gui, Add, Button, x+10 vMyButton1 gLabel1, 1
Gui, Add, Button, x+10 vMyButton2 gLabel2, 2
Gui, Add, Button, x+10 vMyButton3 gLabel3, 3
Gui Show,, %WinTitle%
ToolTip Changing buttons now.
Sleep 5000
GuiControl,, MyButton1, 2
GuiControl,, MyButton2, 3
GuiControl,, MyButton3, 1
ToolTip Clicking 1
Sleep 2000
GuiControlGet,var,,MyButton1
ControlClick %var%, %WinTitle%,,Left
ToolTip Clicking 2
Sleep 2000
GuiControlGet,var,,MyButton2
ControlClick %var%, %WinTitle%,,Left
ToolTip Clicking 3
Sleep 2000
GuiControlGet,var,,MyButton3
ControlClick %var%, %WinTitle%,,Left
Sleep 5000
ExitApp
Label1:
msgbox,4096,,Label 1 was activated.,1
return
Label2:
msgbox,4096,,Label 2 was activated.,1
return
Label3:
msgbox,4096,,Label 3 was activated.,1
return |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Feb 22, 2005 1:36 am Post subject: |
|
|
| I'm going to look into allowing the gui-variable method to be used with the other Control commands. Thanks for the idea. |
|
| Back to top |
|
 |
Watcher
Joined: 28 Dec 2004 Posts: 60
|
Posted: Tue Feb 22, 2005 7:38 am Post subject: |
|
|
| Chris wrote: | | I'm going to look into allowing the gui-variable method to be used with the other Control commands. Thanks for the idea. |
Now we have hit the problem I've been trying (very badly I'm afraid) to get at, if all the controls have a value of 1 and you want to change the 3rd one or click the 3rd one you can't do it with that method because it finds the first one with the string 1 in it. This is what I've been refering to when I say I want a diffinative way to refer to a control.
I VERY anxiously look forward to that upgrade Chris, the workarounds I've had to use are.... well functional but that's all and the strange debugging sessions I've had due to this have been interesting to say the least. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Feb 22, 2005 10:18 am Post subject: |
|
|
The definitive way to access GUI controls is by their variable names. It works 100% of the time with the following three commands: Gui, GuiControl, and GuiControlGet.
The definitive way to access all controls, whether GUI or not, is by their Class+NN, which can be discovered via Window Spy. The downside to ClassNN is that it will change if you reorder same-typed controls relative to each other. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|