topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 1:44 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Hide Gui Buttons previously created  (Read 7601 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Hide Gui Buttons previously created
« on: July 29, 2011, 07:37 AM »
In a loop I create a bunch of buttons with the following code:
Code:
Code: Autohotkey [Select]
  1. Gui, Add, Button, gButtonDestinationSelect HWNDButtonDestinationSelect%a_index%, %ButtonLabel%

Later on I want to hide/disable all these buttons using GuiControlGet, Hide but I'm not able to 'point' to these buttons, could anyone write a quick example?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Hide Gui Buttons previously created
« Reply #1 on: July 29, 2011, 08:06 AM »
GuiControlGet doesn't handle hiding/showing/disabling/enabling of buttons.  GuiControl does.  Consider this example:

Code: Autohotkey [Select]
  1. Loop, 6
  2. {
  3.     Gui, Add, Button, vmyButton%A_Index%, Click me
  4. }
  5.  
  6.  
  7. Sleep, 1500 ; Small delay to show form before changes.
  8.  
  9.  
  10. Loop, 6
  11. {
  12.     If ( Mod( A_Index, 2 ) = 1 ) ; Hide odd-numbered buttons.
  13.     {
  14.         GuiControl, Hide, myButton%A_Index%
  15.     }
  16.     Else ; Disable even-numbered buttons.
  17.     {
  18.         GuiControl, Disable, myButton%A_Index%
  19.     }
  20.     Sleep, 500 ; Small delay to show changes happening.
  21. }
  22.  
  23. Return ; End of auto-execute section.
  24.  
  25.  
  26. {
  27.     ExitApp
  28. }
  29. Return

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Hide Gui Buttons previously created
« Reply #2 on: July 29, 2011, 08:09 AM »
Thanks, sorry that was lazy typing I meant GuiControl. However, my buttons to not have variables assigned to them for a specific reason I cannot remember why, is there a way to do it without?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Hide Gui Buttons previously created
« Reply #3 on: July 29, 2011, 08:26 AM »
In regards to GuiControl -- you have two choices if you don't have variable names assigned to the buttons.

  • You can use the "classname + instance number" combo.  Button1, Button2, etc.  I would advise against this method since that enumeration will change if you add other buttons before you add those looped buttons.
  • You can use the text of the button itself.  Obviously, the text would need to be unique for each button (which I don't think it is in your case).

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Hide Gui Buttons previously created
« Reply #4 on: July 29, 2011, 08:30 AM »
Got it to work :) Great.
Code: Autohotkey [Select]
  1. GuiControl,Enable,btn1%a_index%
  2.                 If ErrorLevel
  3.                         Gui, Add, Button, vbtn1%a_index%, %ButtonLabel%
  4.                 Else
  5.                 {
  6.                         GuiControl,Text,btn1%a_index%,%ButtonLabel%
  7.                         GuiControl,Show,btn1%a_index%
  8.                 }
I'm still not sure why I removed the variables initially, so will do serious testing.. Thanks so much skwire :) sometimes  AHK just lacks a simple example.