Autohotkey add or remove a gui button based on variable - autohotkey

How do I Add or remove a GUI Button based on a variable setting ?
My thought is if in the ini file I read if it has the 1 it will show
Gui, Add, Button, h30 w140 gAEFiles vButton13, Actual hours if is set to 0 it will not show.
I have tried several variation without success. Any help I would appreciate it.
if(%AEButton%=1)
{
gui Tab,Daily
Gui, Add, Button, h30 w140 gNewfolder vButton14, Make daily folder
Gui, Add, Button, h30 w140 gdailyfile vButton8, Daily file
Gui, Add, Button, h30 w140 gLaborfile vButton9, Labor
Gui, Add, Button, h30 w140 gCyclefile vButton10, Cycle Count
Gui, Add, Button, h30 w140 gGLQueryfile vButton11, gQuery
Gui, Add, Button, h30 w140 gEarnhoursfile vButton12, Earn Hours
Gui, Add, Button, h30 w140 gAEFiles vButton13, Actual hours
}
else
{
gui Tab,Daily
Gui, Add, Button, h30 w140 gNewfolder vButton14, Make daily folder
Gui, Add, Button, h30 w140 gdailyfile vButton8, Daily file
Gui, Add, Button, h30 w140 gLaborfile vButton9, Labor
Gui, Add, Button, h30 w140 gCyclefile vButton10, Cycle Count
Gui, Add, Button, h30 w140 gGLQueryfile vButton11, gQuery
Gui, Add, Button, h30 w140 gEarnhoursfile vButton12, Earn Hours
}

Give this a try:
config.ini
[General]
AEButton=1
script.ahk
dailyTabHeight := 250
IniRead, AEButton, config.ini, General, AEButton
If(AEButton = 1) {
dailyTabHeight += 35 ;make the tab 35 pixels higher
}
Gui, Add, Tab, w165 h%dailyTabHeight%, Daily
Gui, Add, Button, h30 w140 gNewfolder vButton14, Make daily folder
Gui, Add, Button, h30 w140 gdailyfile vButton8, Daily file
Gui, Add, Button, h30 w140 gLaborfile vButton9, Labor
Gui, Add, Button, h30 w140 gCyclefile vButton10, Cycle Count
Gui, Add, Button, h30 w140 gGLQueryfile vButton11, gQuery
Gui, Add, Button, h30 w140 gEarnhoursfile vButton12, Earn Hours
If(AEButton = 1)
{
Gui, Add, Button, h30 w140 gAEFiles vButton13, Actual hours
;you could put other things in here too
}
Gui, Show
Newfolder:
dailyfile:
Laborfile:
Cyclefile:
GLQueryfile:
Earnhoursfile:
AEFiles:
Return
GuiClose:
ExitApp

Related

How to create an edit controls with transparent background?

While reading the AutoHotkey docs i could find these commands: WinSet, Transparent WinSet, Transcolor
WinSet, Transparent makes the control disappear.
WinSet, Transcolor makes the control background transparent, however if the GUI has any other color than default, it causes glitches in the text.
Example:
Gui, Color, 0
Gui, Add, Edit, w200 h30 hWndTest, Test
Gui, Show, w400 h200
Return
F2::
WinSet, Transparent, , ahk_id %Test%
Return
F3::
WinSet, Transcolor, ffffff, ahk_id %Test%
Return
Would like to ask if someone knows how to create an edit control with background transparent without 'glitches'?

How to enable the maximize button in the gui?

When i create a GUI her maximize button is grayed out/disabled, how can i enable it?
Example:
Gui, Add, Button, w100 h30, Button
Gui, Show, w400 h300
I was reading the docs and found this parameter Maximize: Maximizes and activates the window.
It does maximize the GUI as soon its launched:
Gui, Show, Maximize w400 h300
However, i would like to enable maximizing/restoring upon clicking the maximize button.
You need to add the flag +Resize
From docs:
Resize: Makes the window resizable and enables its maximize button in the title bar. To avoid enabling the maximize button, specify +Resize -MaximizeBox.

Make borderless window behaves alwaysontop [Autohotkey]

I want to create a borderless window, but alwaysontop didn't work if the window is borderless, how to make borderless window behave alwaysontop ?
gui, Tool: add, button, x0 y0 h20 w140 gxub, TOOLS
gui, Tool: show, w150, TOOLS
WinGet, id1, ID, A ; GET ahk_id of active window
WinSet, Style, -0xC00000, A ; hide title bar
Winset, Alwaysontop, ON, ahk_id %id1%
Adding one line on the top will satisfy your need
gui, +alwaysontop

accessible, but out of tabstop sequence

Is there a way to get an edit control accessible, but out of the tabstop sequence? Eg I have
Gui, Add, Text, &a
Gui, Add, Edit, -Tabstop ReadOnly
I cannot tab to it (which is good) but i also cannot use alt-a to reach it nor can I reach it by mouse clicking it. This is a problem as the user cannot scroll and peruse its contents.
If one changes the - to a + one can reach it by tabs and alt-a. However I do not want it to be in the tabstop sequence. From the "GUI Styles" page of the AutoHotkey Help/manual these appear to be the only relevant styles for an edit command...
How can I have that control reachable, but outside the tab sequence?
If you turn Alt-a into a hotkey, this is how you get the requested result
Gui, Add, Text, ,&a
Gui, Add, Edit, -Tabstop Readonly vMyEdit, My Content
Gui, Add, Edit
Gui, Show
return
!a::
GuiControl,focus, MyEdit
return

GUI Buttons creating text 4 times

I am trying to create my 1st GUI. I just started using AHK today and for the most part have found it very simple to use. I am stuck on one thing though. I created this GUI to display buttons and then depending on what is selected certain text will be typed. When I select the button it is typing the correct text, but it is typing it four times. I have taken off one of the buttons, so there were only three, but it would still type it four times. What do I need to do to make sure it only types it once?
MyGUI:
#SingleInstance Force
Gui, +LastFound +AlwaysOnTop
GUI, Add, Button, x10 y10 w75 h25 gClick1, Button &1
GUI, Add, Button, x95 y10 w75 h25 gClick2, Button &2
GUI, Add, Button, x10 y45 w75 h25 gClick3, ButtonS &3
GUI, Add, Button, x95 y45 w75 h25 gClickCancel, &Cancel
GUI, Show, w200 h100,My GUI
Return
Click1:
Send The first button was selected
Gui Hide
Return
Click2:
Send The second button was selected
Gui Hide
Return
Click3:
Send The third button was selected
Gui Hide
Return
ClickCancel:
Send The cancel button was selected
Gui Hide
Return
I have not tested it yet, but it could be that your send is initiating this. remember that you first send a keyboard sequence and then hide the GUI, so in your situation the GUI is still active at the moment you send! Try to first hide the GUI and then send or initially replace send by MsgBox to test. You could also first send an !{Esc} to switch the focus back to the previous application before sending your data, That way you don't need to hide the GUI.
OK just tested my assumptions, add the !{Esc} and it works as expected.
#SingleInstance Force
Gui, +LastFound +AlwaysOnTop
GUI, Add, Button, x10 y10 w75 h25 gClick1, Button &1
GUI, Add, Button, x95 y10 w75 h25 gClick2, Button &2
GUI, Add, Button, x10 y45 w75 h25 gClick3, ButtonS &3
GUI, Add, Button, x95 y45 w75 h25 gClickCancel, &Cancel
GUI, Show, w200 h100,My GUI
Return
Click1:
Send, !{Esc}
Send, The first button was selected
;Gui Hide
Return
Click2:
Send, !{Esc}
MsgBox, The second button was selected
;Gui Hide
Return
Click3:
Send, !{Esc}
MsgBox, The third button was selected
;Gui Hide
Return
ClickCancel:
Send, !{Esc}
MsgBox, The cancel button was selected
;Gui Hide
Return