Add a button after a certain time to scalable GUI with GuiSize active

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CaptainProton
Posts: 46
Joined: 06 May 2017, 13:38

Add a button after a certain time to scalable GUI with GuiSize active

27 May 2017, 13:58

Hi,

I'm trying to make a button appear after a certain time in a GUI window:

Code: Select all

Gui, 1:New, +Resize +MinSize600x600 +hwndID, Insert notes
Gui, 1:Add, Edit, r2 vMyEdit hwndCID VScroll
Gui, 1:Show
Sleep, 2000
Gui, 1:Add, Button, Default x100 y200 w200 h100, OK
return

GuiSize: 
If (A_EventInfo = 1)
	return
GuiControl, %A_GUI%:Move, MyEdit, % "H" . (A_GuiHeight-20) . " W" . (A_GuiWidth-20)
	return
	
; BIG shoutout to A_AhkUser for helping me with this earlier!
; https://autohotkey.com/boards/viewtopic.php?f=5&t=32346
The question is, how do I make this button appear below the Edit control, regardless of the window changing size? I assume that the size of the Edit control would need to be adjusted somehow, and the button position below it, and somehow fixated there regardless of the change in window size. I'm also assuming that this should somehow be done by changing the GuiSize label, but I really don't know how.

Any help would be greatly appreciated!
CaptainProton
Posts: 46
Joined: 06 May 2017, 13:38

Re: Add a button after a certain time to scalable GUI with GuiSize active

27 May 2017, 16:37

Ok I did it :) Now the button appears after 2 seconds and stays in perfect position when the window is resized.

Can somebody have a look and potentially improve?

Code: Select all

guiW := 600
guiH := 600
margin := 10
editW := guiW - (margin*2)
editH := guiH - (margin*2)
buttonID := 0

Gui, 1:New, +Resize +MinSize%guiW%x%guiH% +hwndguiID, Insert notes ; hwndID stores the GUI ID into "guiID" variable.
Gui, 1:Add, Edit, r2 vMyEdit hwndeditID VScroll w%editW% h%editH% ; adds the Edit control, and stores it's hwnd into "editID" variable.
Gui, Show, w%guiW% h%guiH%

Sleep, 2000

GetClientSize(guiID, guiW, guiH)
ControlGetPos, , , , editH, , ahk_id %editID%
buttonW := 70
buttonH := 30
buttonX := guiW - buttonW - (margin)
buttonY := guiH - buttonH - (margin)
buttonSpaceH := buttonH + (margin*2)

Gui, 1:Add, Button, Default x%buttonX% y%buttonY% w%buttonW% h%buttonH% hwndbuttonID, OK
GuiControl, Move, %editID%, % "W" . (guiW-(margin*2)) . "H" . (guiH-buttonSpaceH-margin) . "X" . (margin) . "Y" . (margin)
return

GuiSize: 
	If (A_EventInfo = 1)
		return
	If (buttonID)
	{
		GuiControl, 1:Move, %editID%, % "H" . (A_GuiHeight-buttonSpaceH-margin) . " W" . (A_GuiWidth-margin*2)
		GuiControl, 1:Move, %buttonID%, % "X" . (A_GuiWidth-buttonW-margin) . " Y" . (A_GuiHeight-buttonH-margin)
		return
	}
	GuiControl, 1:Move, %editID%, % "H" . (A_GuiHeight-margin*2) . " W" . (A_GuiWidth-margin*2)
		return


GetClientSize(hwnd, ByRef w, ByRef h) ; by jNizM, https://autohotkey.com/board/topic/91733-command-to-get-gui-client-areas-sizes/
{
    VarSetCapacity(rc, 16)
    DllCall("GetClientRect", "uint", hwnd, "uint", &rc)
    w := NumGet(rc, 8, "int")
    h := NumGet(rc, 12, "int")
}		
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Add a button after a certain time to scalable GUI with GuiSize active

27 May 2017, 19:23

There's no need for functions when there's a variable for the gui height and width.

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%

Gui, 1:New, +Resize +MinSize500x400 +hwndguiID, Insert notes
Gui, 1:Add, Edit, r2 vMyEdit vEdit VScroll x0 y0
Gui, 1:Add, Button, Default x345 y465 w60 h35 vButtonOK, OK
Gui, 1:Show, w400 h500
Return

GuiSize: 
If (A_EventInfo = 1)
	Return
GuiControl, Move, ButtonOk, % "x" A_GuiWidth - 62 " y" A_GuiHeight - 38
GuiControl, Move, Edit, % "h" A_GuiHeight - 40 " w" A_GuiWidth
Return

GuiEscape:
GuiClose:
ExitApp
Think smarter not harder.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

CaptainProton
Posts: 46
Joined: 06 May 2017, 13:38

Re: Add a button after a certain time to scalable GUI with GuiSize active

28 May 2017, 02:55

Delta Pythagorean wrote:There's no need for functions when there's a variable for the gui height and width.

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%

Gui, 1:New, +Resize +MinSize500x400 +hwndguiID, Insert notes
Gui, 1:Add, Edit, r2 vMyEdit vEdit VScroll x0 y0
Gui, 1:Add, Button, Default x345 y465 w60 h35 vButtonOK, OK
Gui, 1:Show, w400 h500
Return

GuiSize: 
If (A_EventInfo = 1)
	Return
GuiControl, Move, ButtonOk, % "x" A_GuiWidth - 62 " y" A_GuiHeight - 38
GuiControl, Move, Edit, % "h" A_GuiHeight - 40 " w" A_GuiWidth
Return

GuiEscape:
GuiClose:
ExitApp
Think smarter not harder.
Actually, maybe you didn't understand what I tried to do there. Because the button appears after a certain time, AND because the GUI window can be resized and any potential size before the buttons appears, I needed a way to determine it's current size in order to properly position the button. With that in mind, do you still think I could have done it some other way?
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Add a button after a certain time to scalable GUI with GuiSize active

28 May 2017, 17:49

CaptainProton wrote: Actually, maybe you didn't understand what I tried to do there. Because the button appears after a certain time, AND because the GUI window can be resized and any potential size before the buttons appears, I needed a way to determine it's current size in order to properly position the button. With that in mind, do you still think I could have done it some other way?
I don't think there is another way. I have another bit of code that I thought would work but it'll just give an error.
My question is, why would you need to have the gui button appear after a certain amount of time?
The way that I did it, made the gui, made it resizable and usable in all the ways possible. I don't think there is a way to do it. Sorry bud, you'll just have to live with it I guess.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

CaptainProton
Posts: 46
Joined: 06 May 2017, 13:38

Re: Add a button after a certain time to scalable GUI with GuiSize active

28 May 2017, 19:03

Delta Pythagorean wrote:
CaptainProton wrote: Actually, maybe you didn't understand what I tried to do there. Because the button appears after a certain time, AND because the GUI window can be resized and any potential size before the buttons appears, I needed a way to determine it's current size in order to properly position the button. With that in mind, do you still think I could have done it some other way?
I don't think there is another way. I have another bit of code that I thought would work but it'll just give an error.
My question is, why would you need to have the gui button appear after a certain amount of time?
The way that I did it, made the gui, made it resizable and usable in all the ways possible. I don't think there is a way to do it. Sorry bud, you'll just have to live with it I guess.
The time before the button appears is only what I'm using as an example. In reality, I intend to activate that second button after a certain event triggers its activation.

Thanks for giving it a shot. I'm fine with the way it is, was just wondering if it could be better.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Descolada, Nerafius and 216 guests