DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Hide Gui Buttons previously created  (Read 10,267 times)

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Hide Gui Buttons previously created
« on: July 29, 2011, 12:37 PM »
In a loop I create a bunch of buttons with the following code:
Code:
Code: (autohotkey)
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Hide Gui Buttons previously created
« Reply #1 on: July 29, 2011, 01:06 PM »
GuiControlGet doesn't handle hiding/showing/disabling/enabling of buttons.  GuiControl does.  Consider this example:

Code: (autohotkey)
Loop, 6
{
    Gui, Add, Button, vmyButton%A_Index%, Click me
}
Gui, Show


Sleep, 1500 ; Small delay to show form before changes.


Loop, 6
{
    If ( Mod( A_Index, 2 ) = 1 ) ; Hide odd-numbered buttons.
    {
        GuiControl, Hide, myButton%A_Index%
    }
    Else ; Disable even-numbered buttons.
    {
        GuiControl, Disable, myButton%A_Index%
    }
    Sleep, 500 ; Small delay to show changes happening.
}

Return ; End of auto-execute section.


GuiClose:
GuiEscape:
{
    ExitApp
}
Return

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Hide Gui Buttons previously created
« Reply #2 on: July 29, 2011, 01:09 PM »
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Hide Gui Buttons previously created
« Reply #3 on: July 29, 2011, 01:26 PM »
In regards to GuiControl -- you have two choices if you don't have variable names assigned to the buttons.

  1. 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.
  2. 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

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Hide Gui Buttons previously created
« Reply #4 on: July 29, 2011, 01:30 PM »
Got it to work :) Great.
Code: (autohotkey)
Errorlevel =
GuiControl,Enable,btn1%a_index%
		If ErrorLevel 
			Gui, Add, Button, vbtn1%a_index%, %ButtonLabel%
		Else
		{
			GuiControl,Text,btn1%a_index%,%ButtonLabel%
			GuiControl,Show,btn1%a_index%
		}
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.

Original address: https://www.donationcoder.com/forum/index.php?topic=27484.0