How to create/open many GUI at same time? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Albireo
Posts: 1232
Joined: 16 Oct 2013, 13:53

How to create/open many GUI at same time?

05 Apr 2020, 15:54

One GUI is easy to create.
An example of one GUI
How to create a second GUI?
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: How to create/open many GUI at same time?  Topic is solved

05 Apr 2020, 16:27

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
Index := 0
OnMessage(0x112,"Msg")
return
GuiClose:
*ESC::
	Gui,1:+OwnDialogs
	MsgBox, 262144, , Gui 1 closed
	exitApp
	
NumPad1::
CreateNewGui:
	Index++
	Gui,% Index ":New", +hwndHwnd +AlwaysOnTop
	Gui,% Index ":Show",w200 h300
	return

Msg(w){
	if(w = 61536 && A_Gui != 1)
		Gui, %A_Gui%:Destroy
}
HTH
Albireo
Posts: 1232
Joined: 16 Oct 2013, 13:53

Re: How to create/open many GUI at same time?

06 Apr 2020, 09:29

I have tested the small GUI-program.
( I don't understand all functions )

When Numpad1 is pressed a new GUI opens. (OK!)
When the new GUI closes, nothing happens. (OK! in some way)
When the first GUI is closed, the message Gui 1 closed is shown. (OK!)

1) But I have no idea when this is used or how to use this .:
OnMessage(0x112,"Msg") / Msg(w)...

2) Or what this instruction is done MsgBox, 262144, , Gui 1 closed
( what's the meaning of 262144 - I only got the message Gui 1 closed)



Wrote a program where there is a main GUI and a small GUI in a function(), that opens after the button GUI2 is pressed in the main GUI.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

; GUI Window
	Gui 1: +AlwaysOnTop
	Gui 1: Default
	Gui 1: Color, white
	
	; Input
	Gui 1: Font, cBlack s12 Normal, Verdana
	Gui 1: Add, Text, x35 y80 h20 w120 vUserTxt1, Input . .:
	Gui 1: Font, cBlue s16 Bold, Verdana
	Gui 1: Add, Edit, xp+90 yp-10 w120 h30 +Center vInp gInputVal, 
	
	; Button
	Gui 1: Font, s18 Bold, Arial
	Gui 1: Add, Button, x150 y200 h40 w100 +Center vButtOK gButtMess1, Exit!
	Gui 1: Add, Button, x20 yp h40 w100 +Center vButtGUI2 gButtGUI2, GUI2

	Gui 1: Show, x40 y100 h260 w300, Test GUI	
Return
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


InputVal:
	Gui 1: Submit, NoHide
Return

ButtGUI2:
	SmallMessage("This works!")
Return


ButtMess1:
	Gui 1: Destroy
	MsgBox The program ends!
	ExitApp
Return



SmallMessage(InfoTxt)
{	Global UserTxt2, ButtOK2
	Gui 2: +AlwaysOnTop
	Gui 2: Font, cBlack s12 Normal, Verdana
	Gui 2: Add, Text, x20 y20 h20 w120 vUserTxt2, %InfoTxt%
	
	Gui 2: Add, Button, x70 y50 h40 w100 +Center vButtOK2 gButtMess2, OK!
	
	Gui 2: Show, x250 y350 h100 w200, Test GUI 2
}
ButtMess2:
	Gui 2: Destroy
Return



GuiClose:
GuiContextMenu:
	*Esc::
		MsgBox Maybe ESC is pressed!
	ExitApp
Return
1) The programming doesn't get that nice either (subroutine call from a function())
  • - Had wanted all information for this GUI in the same function().
  • - Maybe better to use only subroutines instead of a function()? (now all variables / handles must be global)
  • - Or all GUIs in their own function()?
2) Have thought how the small GUI can be dynamically placed based on the main GUI.
User avatar
Hellbent
Posts: 1058
Joined: 23 Sep 2017, 13:34

Re: How to create/open many GUI at same time?

06 Apr 2020, 12:38

Albireo wrote:
06 Apr 2020, 09:29
1) But I have no idea when this is used or how to use this .:
OnMessage(0x112,"Msg") / Msg(w)...
That gets triggered when you press the close button on a gui [ X ]
It is used so that you don't have to do something like this.

Code: Select all

1GuiClose:
2GuiClose:
3GuiClose:
4GuiClose:
5GuiClose:
6GuiClose:
7GuiClose:
...
nGuiClose:
Albireo wrote:
06 Apr 2020, 09:29
2) Or what this instruction is done MsgBox, 262144, , Gui 1 closed
( what's the meaning of 262144 - I only got the message Gui 1 closed)
262144 is the msgbox option for "AlwaysOnTop"

if the msgbox had Ok/Cancel Buttons and +AlwaysOnTop it would be 262145
Or if the msgbox had Yes/No/Cancel Buttons and +AlwaysOnTop it would be 262147




As for using the script I posted, press Numpad1 a few time in a row and you should end up with multiple windows. If you close any/all except window 1 it will just destroy that window, if you close window 1 you get a message and the script exits.

Return to “Ask For Help”

Who is online

Users browsing this forum: anon11235813, Bing [Bot], conracer, Google [Bot], H_pro1, mikeyww, rcmosher, teadrinker and 58 guests