MsgBox Creator for AHK [v2]

Post your working scripts, libraries and tools.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

MsgBox Creator for AHK [v2]

06 Jul 2020, 08:48

This is a v2 version of the MsgBox creator used in SciTE4AutoHotkey and first posted by Thalon here. I always found it useful, so I wanted a version for v2. It of course is modified to output v2 code, and it has a couple extra v2-specific options. This version was made for use with any editor since it just copies the code to the clipboard, although it can be modified to be more integrated into specific editors.

MsgBox Creator for AHK v2_MBCv1_1.png
MsgBox Creator for AHK v2_MBCv1_1.png (52.82 KiB) Viewed 8258 times

The code:

Code: Select all

/*
	MsgBox Creator for AHK v2
	
	based on Thalon's original "Messagebox-Creator" script
	thanks to fincs for the icon from SciTE4AutoHotkey

	modified for v2 output and translated into v2 code by boiler, updated by AHK_user and sashaatx

	v1.0	- initial release
	v1.1	- added option for single quotes vs. double quotes as suggested by Helgef
			- automatically saves user preferences of the function format options:
				(parenthesis, numeric/string options, single/double quotes)
			- remembers last window position for next time it is run
	v1.2	- updated for AHK v2.0-beta.1 by AHK_user
	v1.3	- updated to produce code to handle return values by sashaatx
*/
#Requires AutoHotKey v2.0-beta.1
#SingleInstance Ignore
try {
TraySetIcon("MsgBox.ico", 1)
} catch {
	
}

buttonConditions := [
	["Ok", "Cancel"], ["Abort", "Retry", "Ignore"], ["Yes", "No", "Cancel"], ["Yes", "No"], ["Retry", "Cancel"], ["Cancel", "Try Again", "Continue"]
]
Paren := IniRead("MsgBox Creator settings.ini", "Main", "Paren", 1)
NumOpt := IniRead("MsgBox Creator settings.ini", "Main", "NumOpt", 1)
DoubleQu := IniRead("MsgBox Creator settings.ini", "Main", "DoubleQu", 1)
WinPosX := IniRead("MsgBox Creator settings.ini", "Main", "WinPosX", "NONE")
WinPosY := IniRead("MsgBox Creator settings.ini", "Main", "WinPosY", "NONE")

global TestMode := 0

MainGui := Gui(, "MsgBox Creator for AHK v2")
MainGui.Add("Text", "x10 y10 Section", "Title:")
MainGui.Add("Edit", "xs+0 ys+15 section w400 vTitle").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("Text", "xs+0 ys+25 section", "Text:")
MainGui.Add("Edit", "xs+0 ys+15 section r3 w400 vText WantTab").OnEvent("Change", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x10 y120 h215 w190 section", "Buttons")
MainGui.Add("Radio", "xs+10 ys+20 section vButtonSelection1 Checked", "OK").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection2", "OK/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection3", "Abort/Retry/Ignore").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection4", "Yes/No/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection5", "Yes/No").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection6", "Retry/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection7", "Cancel/Try Again/Continue").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+0 ys+25 vButtonSelectionHelp", "Help button").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x220 y120 h215 w190 section", "Icons")
Icon1Ctrl := MainGui.Add("Radio", "xs+10 ys+25 section vIcon1 Checked", "No Icon")
Icon1Ctrl.OnEvent("Click", SelectIcon)
Icon2Ctrl := MainGui.Add("Radio", "xs+0 ys+40 vIcon2", "Stop/Error")
Icon2Ctrl.OnEvent("Click", SelectIcon)
Icon3Ctrl := MainGui.Add("Radio", "xs+0 ys+80 vIcon3", "Question")
Icon3Ctrl.OnEvent("Click", SelectIcon)
Icon4Ctrl := MainGui.Add("Radio", "xs+0 ys+120 vIcon4", "Exclamation")
Icon4Ctrl.OnEvent("Click", SelectIcon)
Icon5Ctrl := MainGui.Add("Radio", "xs+0 ys+160 vIcon5", "Info")
Icon5Ctrl.OnEvent("Click", SelectIcon)

MainGui.Add("Picture", "xs+90 ys-10 h30 w20").OnEvent("Click", (*) => SelectIcon(Icon1Ctrl))
MainGui.Add("Picture", "xs+90 ys+30 icon4 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon2Ctrl))
MainGui.Add("Picture", "xs+90 ys+70 icon3 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon3Ctrl))
MainGui.Add("Picture", "xs+90 ys+110 icon2 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon4Ctrl))
MainGui.Add("Picture", "xs+90 ys+150 icon5 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon5Ctrl))

MainGui.Add("Groupbox", "x430 y20 h120 w190 section", "Modality")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vModality1", "Normal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality2", "Task Modal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality3", "System Modal (always on top)").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality4", "Always on top").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y160 h45 w190 section", "Default Button")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vDefault1", "1st").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault2", "2nd").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault3", "3rd").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y220 h45 w190 section", "Alignment")
MainGui.Add("Checkbox", "xs+10 ys+20 vAlignment1 section", "Right-justified").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+100 ys+0 vAlignment2", "Right-to-left").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y280 h45 w100 section", "Timeout")
MainGui.Add("Edit", "xs+10 ys+17 w80 vTimeout").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("UpDown", "Range-1-2147483", "-1")

MainGui.Add("Button", "x540 y285 h40 w80 vTest", "&Test").OnEvent("Click", Test)
MainGui.Add("Button", "x430 y345 h45 w100 Default", "&Copy result to clipboard").OnEvent("Click", CopyCode)
MainGui.Add("Button", "x540 y345 h45 w80", "&Reset").OnEvent("Click", (*) => Reset(MainGui))

MainGui.Add("Groupbox", "x10 y340 w105 h50 section", "Function Format")
ParenOptCtrl := MainGui.Add("Checkbox", "xs+10 ys+22 w90 vParen", "Parentheses")
ParenOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x125 ys w140 h50 section", "Options Format")
NumOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vNumOpt", "Numeric")
NumOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
StrOptCtrl := MainGui.Add("Radio", "x+10 yp w50 vStrOpt", "String")
StrOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x275 ys w135 h50 section", "Quotation Marks")
DoubleQuOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vDoubleQu", "Double")
DoubleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
SingleQuOptCtrl := MainGui.Add("Radio", "x+5 yp w50 vSingleQu", "Single")
SingleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x10 y395 w610 h95 section", "Result")
MainGui.SetFont(, "Courier New")
MainGui.SetFont(, "Lucida Sans Typewriter") ; preferred
MainGui.Add("Edit", "xs+10 ys+20 w590 h300 r5 vFunctionText")

lastParenValue := 1
lastParenStatus := 1
ParenOptCtrl.Value := Paren
if NumOpt
	NumOptCtrl.Value := 1
else
	StrOptCtrl.Value := 1
if DoubleQu
	DoubleQuOptCtrl.Value := 1
else
	SingleQuOptCtrl.Value := 1

MainGui.OnEvent("Close", (*) => ExitApp())
if (WinPosX = "NONE") || (WinPosY = "NONE")
	MainGui.Show()
else
	MainGui.Show("x" WinPosX " y" WinPosY)
CreateMsgBoxFunction(MainGui) ; initialize function string
OnMessage(0x232, WM_EXITSIZEMOVE)
return

CreateMsgBoxFunction(this, *) {
	global lastParenValue, lastParenStatus
	Try
		saved := this.Submit(0)
	Catch {
		this := this.Gui
		saved := this.Submit(0)
	}
	loop 7 {
		if (saved.ButtonSelection%A_Index% = 1) {
			buttonSelection := A_Index - 1
			break
		}
	}
	help := (saved.ButtonSelectionHelp ? 16384 : 0)
	loop 5 {
		if (saved.Icon%A_Index% = 1) {
			icon := [0, 16, 32, 48, 64][A_Index]
			break
		}
	}
	loop 4 {
		if (saved.Modality%A_Index% = 1) {
			modality := [0, 8192, 4096, 262144][A_Index]
			break
		}
	}
	loop 3 {
		if (saved.Default%A_Index% = 1) {
			default := [0, 256, 512][A_Index]
			break
		}
	}
	if (buttonSelection < 1) && (lastParenStatus = 0) {
		ParenOptCtrl.Enabled := 1
		ParenOptCtrl.Value := lastParenValue
		saved.Paren := lastParenValue
		lastParenStatus := 1
	}
	else if (buttonSelection > 0) && (lastParenStatus = 1) {
			lastParenValue := ParenOptCtrl.Value
			ParenOptCtrl.Value := 1
			saved.Paren := 1
			ParenOptCtrl.Enabled := 0
			lastParenStatus := 0
		}


	title := EscapeCharacters(saved.Title, saved.DoubleQu)
	text := EscapeCharacters(saved.Text, saved.DoubleQu)
	timeout := saved.Timeout
	alignment := (saved.Alignment1 = 1) * 524288 + (saved.Alignment2 = 1) * 1048576
	if saved.StrOpt
		options :=	StrReplace(RTrim(["O", "OC", "ARI", "YNC", "YN", "RC", "CTC"][buttonSelection + 1] . " "
						. Map(0, "", 16, "IconX", 32, "Icon?", 48, "Icon!", 64, "Iconi")[icon] . " "
						. Map(0, "", 256, "Default2", 512, "Default3", 768, "Default4")[default] . " "
						. (modality + alignment + help ? modality + alignment + help : "")), "  ", " ")
	else
		options := buttonSelection + icon + modality + default + alignment + help
	
	if TestMode
		return {Options: options, Title: title, Text: text, Timeout: timeout}

	if (timeout = -1) || (timeout = "")
		timeout := ""
	else 
		timeout := "T" StrReplace(timeout, ",", ".") ; allows "," as decimal point

	Qu := saved.DoubleQu ? Chr(34) : "'"
	functionText :=	"MsgBox" . (saved.Paren ? "(" : " ") ; insert paren if selected
						. (text ? Qu . text . Qu : "") "," ; insert quotes around text if it exists
						. (title ? " " . Qu . title . Qu : "") . "," ; insert space and insert quotes around title if it exists
						. ((options . timeout) ? " " . Qu : "") ; insert space and open quote if there are options or timeout
						. (options ? options : "") ; if sum of options is 0, leave it blank, otherwise put in options
						. (options && timeout ? " " : "") ; if there is both an option number and a timeout, insert a space
						. timeout . ((options . timeout) ? Qu : "") ; add timeout if it exists and close quote if necessary
						;. buttonSelection > 0 ? buttonSelectionConditions(buttonConditions) : ""
	functionText := RTrim(functionText, ",") ; remove unnecessary commas on the right
						. (saved.Paren ? ")" : "") ; add closing paren if selected
	functionText := buttonSelection > 0 ? (saved.Paren ? "userResponse := " functionText buttonSelectionConditions(buttonSelection) : functionText)  : functionText

	this.__Item["FunctionText"].Value := functionText
}
buttonSelectionConditions(index){
	if (buttonConditions[index].Length <= 3) {
		conditional := Format("`nif (userResponse = `"{1}`"){`n`t;action here`n} else if (userResponse = `"{2}`"){`n`t;action here`n}", buttonConditions[index][1], buttonConditions[index][2])
	}
	if (buttonConditions[index].Length = 3) {
		conditional .= Format(" else if (userResponse = `"{1}`"){`n`t;action here`n}", buttonConditions[index][3])
	}
	return conditional
}


SelectIcon(thisCtrl, *) {
	thisCtrl.Value := 1
	CreateMsgBoxFunction(thisCtrl.Gui)
}

EscapeCharacters(str, doubleQu) {
	if doubleQu
		str := StrReplace(str, Chr(34), "``" Chr(34))
	else
		str := StrReplace(str, "'", "``" "'")
	return StrReplace(str, "`n", "``n")
}

Test(thisCtrl, *) {
	global
	TestMode := 1
	info := CreateMsgBoxFunction(thisCtrl)
	TestMode := 0
	thisCtrl.Gui.Opt("+OwnDialogs")
	title := info.Title ? info.Title : "(Name of script)"
	text := StrReplace(info.Text, "``n", "`n")
	if (thisCtrl.Gui.__Item["DoubleQu"].Value = 1)
		text := StrReplace(text, "```"", "`"")
	else
		text := StrReplace(text, "``'", "`'")
	MsgBox text, title, info.Options . (info.Timeout = -1 ? "" : " T" info.Timeout)
}

CopyCode(thisCtrl, *) {
	saved := thisCtrl.Gui.Submit(0)
	A_Clipboard := saved.FunctionText
	MsgBox "The MsgBox code has been copied to the clipboard.`n`nIt is ready to be pasted into your editor.", "MsgBox Code Copied", "4160 T3"
}

Reset(thisGui, *) {
	thisGui.__Item["Title"].Value := ""
	thisGui.__Item["Text"].Value := ""
	thisGui.__Item["ButtonSelection1"].Value := 1
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["Icon1"].Value := 1
	thisGui.__Item["Modality1"].Value := 1
	thisGui.__Item["Default1"].Value := 1
	thisGui.__Item["Alignment1"].Value := 0
	thisGui.__Item["Alignment2"].Value := 0
	thisGui.__Item["Timeout"].Value := -1
	thisGui.__Item["NumOpt"].Value := 1
	thisGui.__Item["Paren"].Value := 1
	CreateMsgBoxFunction(thisGui)
}

SaveOptions(thisGui, *) {
	saved := thisGui.Submit(0)
	IniWrite saved.Paren, "MsgBox Creator settings.ini", "Main", "Paren"
	IniWrite saved.NumOpt, "MsgBox Creator settings.ini", "Main", "NumOpt"
	IniWrite saved.DoubleQu, "MsgBox Creator settings.ini", "Main", "DoubleQu"
	CreateMsgBoxFunction(thisGui)
}

WM_EXITSIZEMOVE(*) {
	global MainGui
	MainGui.GetPos(&x, &y)
	IniWrite x, "MsgBox Creator settings.ini", "Main", "WinPosX"
	IniWrite y, "MsgBox Creator settings.ini", "Main", "WinPosY"
}

The zip file below includes the associated icon (taken from SciTE4AutoHotkey -- thanks, fincs). The forum doesn't allow a .ico file to be dropped in directly, so I zipped it along with the .ahk file (updated to include updated script for v2.0-beta.1):
MsgBox Creator for AHK v2_MBCv1_3.zip
(4.15 KiB) Downloaded 189 times

v1.1 Changes:
  • added option for single quotes vs. double quotes as suggested by Helgef
  • automatically saves user preferences of the function format options (parenthesis, numeric/string options, single/double quotes)
  • remembers last window position for next time it is run
v1.2 Changes:
  • updated for v2.0-beta.1 by AHK_user
v1.3 Changes:
  • updated to produce code to handle return values by sashaatx
Last edited by boiler on 15 Sep 2021, 20:30, edited 2 times in total.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: MsgBox Creator for AHK v2 - a115

06 Jul 2020, 09:43

Cool, thanks! I love continuing to see more v2 stuff created! Keep it coming as this is what is needed to create momentum and encourage others to use v2 as well.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: MsgBox Creator for AHK v2 - a115

06 Jul 2020, 14:16

Is there a difference to MagicBox?
ciao
toralf
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK v2 - a115

06 Jul 2020, 14:27

This is a tool for allowing you to create the parameters for AHK's built-in MsgBox function for AHK v2 by making selections from a graphical interface.

MagicBox by Alguimist allows you to build other types of message boxes with more features. I don't know if Alguimist plans to make a version of it for AHK v2.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: MsgBox Creator for AHK v2 - a115

09 Jul 2020, 01:50

Good work, thanks for sharing :thumbsup:. I usually use ' instead of " to quote text, an option for that would be nice.

Cheers.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK v2 - a115

09 Jul 2020, 07:10

Thanks! Good suggestion. I will add that option and have it escape that character if used within the quoted text if necessary (and of course not have it escape the double quote in that case).
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK v2 - a115

10 Jul 2020, 14:00

Edited first post to update to v1.1 with these changes:
  • added option for single quotes vs. double quotes as suggested by Helgef
  • automatically saves user preferences of the function format options (parenthesis, numeric/string options, single/double quotes)
  • remembers last window position for next time it is run
(Also, thanks for the comment @kczx3! Missed that before.)
Larkal
Posts: 21
Joined: 08 Mar 2019, 00:36

Re: MsgBox Creator for AHK v2 - a115

19 Jul 2020, 07:47

Awesome! Thanks, amazing work! I used to use the one for AHK 1 as well, much appreciated.
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: MsgBox Creator for AHK v2 - a115

19 Jul 2020, 08:48

@boiler thank you , very useful , I use longtime Thalon's MSGBOX-creator script
it's not easy for me to learn AHK_v2
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK v2 - a115

19 Jul 2020, 10:55

Thanks, @garry. I think the more you use v2, the more you’ll find it’s more consistent than v1.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: MsgBox Creator for AHK v2 - a115

15 Sep 2021, 11:39

Here is the version for AHK V2.0 beta.1:

Code: Select all

/*
	MsgBox Creator for AHK v2
	
	based on Thalon's original "Messagebox-Creator" script
	thanks to fincs for the icon from SciTE4AutoHotkey

	modified for v2 output and translated into v2 code by boiler

	v1.0	- initial release
	v1.1	- added option for single quotes vs. double quotes as suggested by Helgef
			- automatically saves user preferences of the function format options:
				(parenthesis, numeric/string options, single/double quotes)
			- remembers last window position for next time it is run
	v1.2    - Changed for beta (update by AHK_user)
*/
#Requires AutoHotKey v2.0-beta.1
#SingleInstance Ignore

TraySetIcon("MsgBox.ico", 1)

Paren := IniRead("MsgBox Creator settings.ini", "Main", "Paren", 1)
NumOpt := IniRead("MsgBox Creator settings.ini", "Main", "NumOpt", 1)
DoubleQu := IniRead("MsgBox Creator settings.ini", "Main", "DoubleQu", 1)
WinPosX := IniRead("MsgBox Creator settings.ini", "Main", "WinPosX", "NONE")
WinPosY := IniRead("MsgBox Creator settings.ini", "Main", "WinPosY", "NONE")

global TestMode := 0

MainGui := Gui(, "MsgBox Creator for AHK v2")
MainGui.Add("Text", "x10 y10 Section", "Title:")
MainGui.Add("Edit", "xs+0 ys+15 section w400 vTitle").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("Text", "xs+0 ys+25 section", "Text:")
MainGui.Add("Edit", "xs+0 ys+15 section r3 w400 vText WantTab").OnEvent("Change", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x10 y120 h215 w190 section", "Buttons")
MainGui.Add("Radio", "xs+10 ys+20 section vButtonSelection1 Checked", "OK").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection2", "OK/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection3", "Abort/Retry/Ignore").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection4", "Yes/No/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection5", "Yes/No").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection6", "Retry/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection7", "Cancel/Try Again/Continue").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+0 ys+25 vButtonSelectionHelp", "Help button").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x220 y120 h215 w190 section", "Icons")
Icon1Ctrl := MainGui.Add("Radio", "xs+10 ys+25 section vIcon1 Checked", "No Icon")
Icon1Ctrl.OnEvent("Click", SelectIcon)
Icon2Ctrl := MainGui.Add("Radio", "xs+0 ys+40 vIcon2", "Stop/Error")
Icon2Ctrl.OnEvent("Click", SelectIcon)
Icon3Ctrl := MainGui.Add("Radio", "xs+0 ys+80 vIcon3", "Question")
Icon3Ctrl.OnEvent("Click", SelectIcon)
Icon4Ctrl := MainGui.Add("Radio", "xs+0 ys+120 vIcon4", "Exclamation")
Icon4Ctrl.OnEvent("Click", SelectIcon)
Icon5Ctrl := MainGui.Add("Radio", "xs+0 ys+160 vIcon5", "Info")
Icon5Ctrl.OnEvent("Click", SelectIcon)

MainGui.Add("Picture", "xs+90 ys-10 h30 w20").OnEvent("Click", (*) => SelectIcon(Icon1Ctrl))
MainGui.Add("Picture", "xs+90 ys+30 icon4 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon2Ctrl))
MainGui.Add("Picture", "xs+90 ys+70 icon3 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon3Ctrl))
MainGui.Add("Picture", "xs+90 ys+110 icon2 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon4Ctrl))
MainGui.Add("Picture", "xs+90 ys+150 icon5 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon5Ctrl))

MainGui.Add("Groupbox", "x430 y20 h120 w190 section", "Modality")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vModality1", "Normal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality2", "Task Modal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality3", "System Modal (always on top)").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality4", "Always on top").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y160 h45 w190 section", "Default Button")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vDefault1", "1st").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault2", "2nd").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault3", "3rd").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y220 h45 w190 section", "Alignment")
MainGui.Add("Checkbox", "xs+10 ys+20 vAlignment1 section", "Right-justified").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+100 ys+0 vAlignment2", "Right-to-left").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y280 h45 w100 section", "Timeout")
MainGui.Add("Edit", "xs+10 ys+17 w80 vTimeout").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("UpDown", "Range-1-2147483", "-1")

MainGui.Add("Button", "x540 y285 h40 w80 vTest", "&Test").OnEvent("Click", Test)
MainGui.Add("Button", "x430 y345 h45 w100 Default", "&Copy result to clipboard").OnEvent("Click", CopyCode)
MainGui.Add("Button", "x540 y345 h45 w80", "&Reset").OnEvent("Click", (*) => Reset(MainGui))

MainGui.Add("Groupbox", "x10 y340 w105 h50 section", "Function Format")
ParenOptCtrl := MainGui.Add("Checkbox", "xs+10 ys+22 w90 vParen", "Parentheses")
ParenOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x125 ys w140 h50 section", "Options Format")
NumOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vNumOpt", "Numeric")
NumOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
StrOptCtrl := MainGui.Add("Radio", "x+10 yp w50 vStrOpt", "String")
StrOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x275 ys w135 h50 section", "Quotation Marks")
DoubleQuOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vDoubleQu", "Double")
DoubleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
SingleQuOptCtrl := MainGui.Add("Radio", "x+5 yp w50 vSingleQu", "Single")
SingleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x10 y395 w610 h75 section", "Result")
MainGui.SetFont(, "Courier New")
MainGui.SetFont(, "Lucida Sans Typewriter") ; preferred
MainGui.Add("Edit", "xs+10 ys+20 w590 r3 vFunctionText")

ParenOptCtrl.Value := Paren
if NumOpt
	NumOptCtrl.Value := 1
else
	StrOptCtrl.Value := 1
if DoubleQu
	DoubleQuOptCtrl.Value := 1
else
	SingleQuOptCtrl.Value := 1

MainGui.OnEvent("Close", (*) => ExitApp())
if (WinPosX = "NONE") || (WinPosY = "NONE")
	MainGui.Show()
else
	MainGui.Show("x" WinPosX " y" WinPosY)
CreateMsgBoxFunction(MainGui) ; initialize function string
OnMessage(0x232, WM_EXITSIZEMOVE)
return

CreateMsgBoxFunction(this, *) {
	Try
		saved := this.Submit(0)
	Catch {
		this := this.Gui
		saved := this.Submit(0)
	}
	loop 7 {
		if (saved.ButtonSelection%A_Index% = 1) {
			buttonSelection := A_Index - 1
			break
		}
	}
	help := (saved.ButtonSelectionHelp ? 16384 : 0)
	loop 5 {
		if (saved.Icon%A_Index% = 1) {
			icon := [0, 16, 32, 48, 64][A_Index]
			break
		}
	}
	loop 4 {
		if (saved.Modality%A_Index% = 1) {
			modality := [0, 8192, 4096, 262144][A_Index]
			break
		}
	}
	loop 3 {
		if (saved.Default%A_Index% = 1) {
			default := [0, 256, 512][A_Index]
			break
		}
	}
	title := EscapeCharacters(saved.Title, saved.DoubleQu)
	text := EscapeCharacters(saved.Text, saved.DoubleQu)
	timeout := saved.Timeout
	alignment := (saved.Alignment1 = 1) * 524288 + (saved.Alignment2 = 1) * 1048576
	if saved.StrOpt
		options :=	StrReplace(RTrim(["O", "OC", "ARI", "YNC", "YN", "RC", "CTC"][buttonSelection + 1] . " "
						. Map(0, "", 16, "IconX", 32, "Icon?", 48, "Icon!", 64, "Iconi")[icon] . " "
						. Map(0, "", 256, "Default2", 512, "Default3", 768, "Default4")[default] . " "
						. (modality + alignment + help ? modality + alignment + help : "")), "  ", " ")
	else
		options := buttonSelection + icon + modality + default + alignment + help
	
	if TestMode
		return {Options: options, Title: title, Text: text, Timeout: timeout}

	if (timeout = -1) || (timeout = "")
		timeout := ""
	else 
		timeout := "T" StrReplace(timeout, ",", ".") ; allows "," as decimal point

	Qu := saved.DoubleQu ? Chr(34) : "'"
	functionText :=	"MsgBox" . (saved.Paren ? "(" : " ") ; insert paren if selected
						. (text ? Qu . text . Qu : "") "," ; insert quotes around text if it exists
						. (title ? " " . Qu . title . Qu : "") . "," ; insert space and insert quotes around title if it exists
						. ((options . timeout) ? " " . Qu : "") ; insert space and open quote if there are options or timeout
						. (options ? options : "") ; if sum of options is 0, leave it blank, otherwise put in options
						. (options && timeout ? " " : "") ; if there is both an option number and a timeout, insert a space
						. timeout . ((options . timeout) ? Qu : "") ; add timeout if it exists and close quote if necessary
	functionText := RTrim(functionText, ",") ; remove unnecessary commas on the right
						. (saved.Paren ? ")" : "") ; add closing paren if selected
	this.__Item["FunctionText"].Value := functionText
}

SelectIcon(thisCtrl, *) {
	thisCtrl.Value := 1
	CreateMsgBoxFunction(thisCtrl.Gui)
}

EscapeCharacters(str, doubleQu) {
	if doubleQu
		str := StrReplace(str, Chr(34), "``" Chr(34))
	else
		str := StrReplace(str, "'", "``" "'")
	return StrReplace(str, "`n", "``n")
}

Test(thisCtrl, *) {
	global
	TestMode := 1
	info := CreateMsgBoxFunction(thisCtrl)
	TestMode := 0
	thisCtrl.Gui.Opt("+OwnDialogs")
	title := info.Title ? info.Title : "(Name of script)"
	text := StrReplace(info.Text, "``n", "`n")
	if (thisCtrl.Gui.__Item["DoubleQu"].Value = 1)
		text := StrReplace(text, "```"", "`"")
	else
		text := StrReplace(text, "``'", "`'")
	MsgBox text, title, info.Options . (info.Timeout = -1 ? "" : " T" info.Timeout)
}

CopyCode(thisCtrl, *) {
	saved := thisCtrl.Gui.Submit(0)
	A_Clipboard := saved.FunctionText
	MsgBox "The MsgBox code has been copied to the clipboard.`n`nIt is ready to be pasted into your editor.", "MsgBox Code Copied", "4160 T3"
}

Reset(thisGui, *) {
	thisGui.__Item["Title"].Value := ""
	thisGui.__Item["Text"].Value := ""
	thisGui.__Item["ButtonSelection1"].Value := 1
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["Icon1"].Value := 1
	thisGui.__Item["Modality1"].Value := 1
	thisGui.__Item["Default1"].Value := 1
	thisGui.__Item["Alignment1"].Value := 0
	thisGui.__Item["Alignment2"].Value := 0
	thisGui.__Item["Timeout"].Value := -1
	thisGui.__Item["NumOpt"].Value := 1
	thisGui.__Item["Paren"].Value := 1
	CreateMsgBoxFunction(thisGui)
}

SaveOptions(thisGui, *) {
	saved := thisGui.Submit(0)
	IniWrite saved.Paren, "MsgBox Creator settings.ini", "Main", "Paren"
	IniWrite saved.NumOpt, "MsgBox Creator settings.ini", "Main", "NumOpt"
	IniWrite saved.DoubleQu, "MsgBox Creator settings.ini", "Main", "DoubleQu"
	CreateMsgBoxFunction(thisGui)
}

WM_EXITSIZEMOVE(*) {
	global MainGui
	MainGui.GetPos(&x, &y)
	IniWrite x, "MsgBox Creator settings.ini", "Main", "WinPosX"
	IniWrite y, "MsgBox Creator settings.ini", "Main", "WinPosY"
}
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK [v2.0-beta.1]

15 Sep 2021, 20:31

Updated first post with update for v2.0-beta.1. Thanks, @AHK_user!
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: MsgBox Creator for AHK [v2.0-beta.1]

23 Sep 2021, 05:23

I am not sure if somebody is interested, but I added a parameter DarkMode to set the colors to darkmode, as my editor is also dark.

It is not perfect, as ahk does not has a simple way to set the Gui to dark mode, but it at least reduces the contrast.

- Update: added extra Dark mode settings to set title, menu, edit and button controls
2021-10-24 11_24_57-MsgBox Creator for AHK v2.png
2021-10-24 11_24_57-MsgBox Creator for AHK v2.png (47.22 KiB) Viewed 4915 times

Code: Select all

/*
	MsgBox Creator for AHK v2
	
	based on Thalon's original "Messagebox-Creator" script
	thanks to fincs for the icon from SciTE4AutoHotkey

	modified for v2 output and translated into v2 code by boiler

	v1.0	- initial release
	v1.1	- added option for single quotes vs. double quotes as suggested by Helgef
			- automatically saves user preferences of the function format options:
				(parenthesis, numeric/string options, single/double quotes)
			- remembers last window position for next time it is run
	v1.2    - Changed for beta (update by AHK_user)
	v1.3    - Added Dark mode colors (update by AHK_user)
*/
#Requires AutoHotKey v2.0-beta.1
#SingleInstance Ignore

DarkMode := 1

try TraySetIcon("MsgBox.ico", 1)

Paren := IniRead("MsgBox Creator settings.ini", "Main", "Paren", 1)
NumOpt := IniRead("MsgBox Creator settings.ini", "Main", "NumOpt", 1)
DoubleQu := IniRead("MsgBox Creator settings.ini", "Main", "DoubleQu", 1)
WinPosX := IniRead("MsgBox Creator settings.ini", "Main", "WinPosX", "NONE")
WinPosY := IniRead("MsgBox Creator settings.ini", "Main", "WinPosY", "NONE")

global TestMode := 0

MainGui := Gui(, "MsgBox Creator for AHK v2")

if DarkMode{
	
	; Setting the script menu to dark mode
	uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
	SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
	FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
	DllCall(SetPreferredAppMode, "int", 1)	; Dark
	DllCall(FlushMenuThemes)

    ; Changing the title bar to dark
    attr := VerCompare(A_OSVersion, "10.0.18985") >= 0 ? 20 : VerCompare(A_OSVersion, "10.0.17763") >= 0 ? 19 : ""
     DllCall("dwmapi\DwmSetWindowAttribute", "ptr", MainGui.hwnd, "int", attr, "int*", true, "int", 4)

	MainGui.BackColor := "0x1E1E1E"
	MainGui.SetFont("c0xBBBBBB")
}


MainGui.Add("Text", "x10 y10 Section", "Title:")
ogEditTitle :=MainGui.Add("Edit", "xs+0 ys+15 section w400 vTitle")
ogEditTitle.OnEvent("Change", CreateMsgBoxFunction)
if DarkMode{
	ogEditTitle.Opt("+Background0x3C3C3C")
}


MainGui.Add("Text", "xs+0 ys+25 section", "Text:")
ogEditText := MainGui.Add("Edit", "xs+0 ys+15 section r3 w400 vText WantTab")
ogEditText.OnEvent("Change", CreateMsgBoxFunction)
if DarkMode{
	ogEditText.Opt("+Background0x3C3C3C")
}
MainGui.Add("Groupbox", "x10 y120 h215 w190 section", "Buttons")
MainGui.Add("Radio", "xs+10 ys+20 section vButtonSelection1 Checked", "OK").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection2", "OK/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection3", "Abort/Retry/Ignore").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection4", "Yes/No/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection5", "Yes/No").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection6", "Retry/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection7", "Cancel/Try Again/Continue").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+0 ys+25 vButtonSelectionHelp", "Help button").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x220 y120 h215 w190 section", "Icons")
Icon1Ctrl := MainGui.Add("Radio", "xs+10 ys+25 section vIcon1 Checked", "No Icon")
Icon1Ctrl.OnEvent("Click", SelectIcon)
Icon2Ctrl := MainGui.Add("Radio", "xs+0 ys+40 vIcon2", "Stop/Error")
Icon2Ctrl.OnEvent("Click", SelectIcon)
Icon3Ctrl := MainGui.Add("Radio", "xs+0 ys+80 vIcon3", "Question")
Icon3Ctrl.OnEvent("Click", SelectIcon)
Icon4Ctrl := MainGui.Add("Radio", "xs+0 ys+120 vIcon4", "Exclamation")
Icon4Ctrl.OnEvent("Click", SelectIcon)
Icon5Ctrl := MainGui.Add("Radio", "xs+0 ys+160 vIcon5", "Info")
Icon5Ctrl.OnEvent("Click", SelectIcon)

MainGui.Add("Picture", "xs+90 ys-10 h30 w20").OnEvent("Click", (*) => SelectIcon(Icon1Ctrl))
MainGui.Add("Picture", "xs+90 ys+30 icon4 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon2Ctrl))
MainGui.Add("Picture", "xs+90 ys+70 icon3 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon3Ctrl))
MainGui.Add("Picture", "xs+90 ys+110 icon2 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon4Ctrl))
MainGui.Add("Picture", "xs+90 ys+150 icon5 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon5Ctrl))

MainGui.Add("Groupbox", "x430 y20 h120 w190 section", "Modality")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vModality1", "Normal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality2", "Task Modal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality3", "System Modal (always on top)").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality4", "Always on top").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y160 h45 w190 section", "Default Button")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vDefault1", "1st").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault2", "2nd").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault3", "3rd").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y220 h45 w190 section", "Alignment")
MainGui.Add("Checkbox", "xs+10 ys+20 vAlignment1 section", "Right-justified").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+100 ys+0 vAlignment2", "Right-to-left").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y280 h45 w100 section", "Timeout")
ogEditTimeout := MainGui.Add("Edit", "xs+10 ys+17 w80 vTimeout")
ogEditTimeout.OnEvent("Change", CreateMsgBoxFunction)

if DarkMode{
	ogEditTimeout.Opt("+Background0x3C3C3C")
}

MainGui.Add("UpDown", "Range-1-2147483", "-1")

MainGui.Add("Button", "x540 y285 h40 w80 vTest", "&Test").OnEvent("Click", Test)
MainGui.Add("Button", "x430 y345 h45 w100 Default", "&Copy result to clipboard").OnEvent("Click", CopyCode)
MainGui.Add("Button", "x540 y345 h45 w80", "&Reset").OnEvent("Click", (*) => Reset(MainGui))

MainGui.Add("Groupbox", "x10 y340 w105 h50 section", "Function Format")
ParenOptCtrl := MainGui.Add("Checkbox", "xs+10 ys+22 w90 vParen", "Parentheses")
ParenOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x125 ys w140 h50 section", "Options Format")
NumOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vNumOpt", "Numeric")
NumOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
StrOptCtrl := MainGui.Add("Radio", "x+10 yp w50 vStrOpt", "String")
StrOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x275 ys w135 h50 section", "Quotation Marks")
DoubleQuOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vDoubleQu", "Double")
DoubleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
SingleQuOptCtrl := MainGui.Add("Radio", "x+5 yp w50 vSingleQu", "Single")
SingleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x10 y395 w610 h75 section", "Result")
MainGui.SetFont(, "Courier New")
MainGui.SetFont(, "Lucida Sans Typewriter") ; preferred
ogEditResult :=MainGui.Add("Edit", "xs+10 ys+20 w590 r3 vFunctionText")

if DarkMode{
	ogEditResult.Opt("+Background0x3C3C3C")
}

ParenOptCtrl.Value := Paren
if NumOpt
	NumOptCtrl.Value := 1
else
	StrOptCtrl.Value := 1
if DoubleQu
	DoubleQuOptCtrl.Value := 1
else
	SingleQuOptCtrl.Value := 1

MainGui.OnEvent("Close", (*) => ExitApp())

if DarkMode{
	For Hwnd, GuiCtrlObj in MainGui {
		if (GuiCtrlObj.Type = "Button" or GuiCtrlObj.Type = "Edit") {
			DllCall("uxtheme\SetWindowTheme", "ptr", GuiCtrlObj.hwnd, "str", "DarkMode_Explorer", "ptr", 0)
		}
	}
}

if (WinPosX = "NONE") || (WinPosY = "NONE")
	MainGui.Show()
else
	MainGui.Show("x" WinPosX " y" WinPosY)
CreateMsgBoxFunction(MainGui) ; initialize function string
OnMessage(0x232, WM_EXITSIZEMOVE)
return

CreateMsgBoxFunction(this, *) {
	Try
		saved := this.Submit(0)
	Catch {
		this := this.Gui
		saved := this.Submit(0)
	}
	loop 7 {
		if (saved.ButtonSelection%A_Index% = 1) {
			buttonSelection := A_Index - 1
			break
		}
	}
	help := (saved.ButtonSelectionHelp ? 16384 : 0)
	loop 5 {
		if (saved.Icon%A_Index% = 1) {
			icon := [0, 16, 32, 48, 64][A_Index]
			break
		}
	}
	loop 4 {
		if (saved.Modality%A_Index% = 1) {
			modality := [0, 8192, 4096, 262144][A_Index]
			break
		}
	}
	loop 3 {
		if (saved.Default%A_Index% = 1) {
			default := [0, 256, 512][A_Index]
			break
		}
	}
	title := EscapeCharacters(saved.Title, saved.DoubleQu)
	text := EscapeCharacters(saved.Text, saved.DoubleQu)
	timeout := saved.Timeout
	alignment := (saved.Alignment1 = 1) * 524288 + (saved.Alignment2 = 1) * 1048576
	if saved.StrOpt
		options :=	StrReplace(RTrim(["O", "OC", "ARI", "YNC", "YN", "RC", "CTC"][buttonSelection + 1] . " "
						. Map(0, "", 16, "IconX", 32, "Icon?", 48, "Icon!", 64, "Iconi")[icon] . " "
						. Map(0, "", 256, "Default2", 512, "Default3", 768, "Default4")[default] . " "
						. (modality + alignment + help ? modality + alignment + help : "")), "  ", " ")
	else
		options := buttonSelection + icon + modality + default + alignment + help
	
	if TestMode
		return {Options: options, Title: title, Text: text, Timeout: timeout}

	if (timeout = -1) || (timeout = "")
		timeout := ""
	else 
		timeout := "T" StrReplace(timeout, ",", ".") ; allows "," as decimal point

	Qu := saved.DoubleQu ? Chr(34) : "'"
	functionText :=	"MsgBox" . (saved.Paren ? "(" : " ") ; insert paren if selected
						. (text ? Qu . text . Qu : "") "," ; insert quotes around text if it exists
						. (title ? " " . Qu . title . Qu : "") . "," ; insert space and insert quotes around title if it exists
						. ((options . timeout) ? " " . Qu : "") ; insert space and open quote if there are options or timeout
						. (options ? options : "") ; if sum of options is 0, leave it blank, otherwise put in options
						. (options && timeout ? " " : "") ; if there is both an option number and a timeout, insert a space
						. timeout . ((options . timeout) ? Qu : "") ; add timeout if it exists and close quote if necessary
	functionText := RTrim(functionText, ",") ; remove unnecessary commas on the right
						. (saved.Paren ? ")" : "") ; add closing paren if selected
	this.__Item["FunctionText"].Value := functionText
}

SelectIcon(thisCtrl, *) {
	thisCtrl.Value := 1
	CreateMsgBoxFunction(thisCtrl.Gui)
}

EscapeCharacters(str, doubleQu) {
	if doubleQu
		str := StrReplace(str, Chr(34), "``" Chr(34))
	else
		str := StrReplace(str, "'", "``" "'")
	return StrReplace(str, "`n", "``n")
}

Test(thisCtrl, *) {
	global
	TestMode := 1
	info := CreateMsgBoxFunction(thisCtrl)
	TestMode := 0
	thisCtrl.Gui.Opt("+OwnDialogs")
	title := info.Title ? info.Title : "(Name of script)"
	text := StrReplace(info.Text, "``n", "`n")
	if (thisCtrl.Gui.__Item["DoubleQu"].Value = 1)
		text := StrReplace(text, "```"", "`"")
	else
		text := StrReplace(text, "``'", "`'")
	MsgBox text, title, info.Options . (info.Timeout = -1 ? "" : " T" info.Timeout)
}

CopyCode(thisCtrl, *) {
	saved := thisCtrl.Gui.Submit(0)
	A_Clipboard := saved.FunctionText
	MsgBox "The MsgBox code has been copied to the clipboard.`n`nIt is ready to be pasted into your editor.", "MsgBox Code Copied", "4160 T3"
}

Reset(thisGui, *) {
	thisGui.__Item["Title"].Value := ""
	thisGui.__Item["Text"].Value := ""
	thisGui.__Item["ButtonSelection1"].Value := 1
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["Icon1"].Value := 1
	thisGui.__Item["Modality1"].Value := 1
	thisGui.__Item["Default1"].Value := 1
	thisGui.__Item["Alignment1"].Value := 0
	thisGui.__Item["Alignment2"].Value := 0
	thisGui.__Item["Timeout"].Value := -1
	thisGui.__Item["NumOpt"].Value := 1
	thisGui.__Item["Paren"].Value := 1
	CreateMsgBoxFunction(thisGui)
}

SaveOptions(thisGui, *) {
	saved := thisGui.Submit(0)
	IniWrite saved.Paren, "MsgBox Creator settings.ini", "Main", "Paren"
	IniWrite saved.NumOpt, "MsgBox Creator settings.ini", "Main", "NumOpt"
	IniWrite saved.DoubleQu, "MsgBox Creator settings.ini", "Main", "DoubleQu"
	CreateMsgBoxFunction(thisGui)
}

WM_EXITSIZEMOVE(*) {
	global MainGui
	MainGui.GetPos(&x, &y)
	IniWrite x, "MsgBox Creator settings.ini", "Main", "WinPosX"
	IniWrite y, "MsgBox Creator settings.ini", "Main", "WinPosY"
}
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: MsgBox Creator for AHK [v2.0-beta.1]

22 Mar 2023, 12:35

Very useful script which I before finding out had to use the converter by using Scite first! I never remember all these codes and icons!

One request would be if you could add an extra option for the Ltrim like Pulover's macro creator for better readability when messages are long :)

Code: Select all

(LTrim
First line

Sec

Third
)
Thank you boiler!
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK [v2.0-beta.1]

22 Mar 2023, 13:43

I'm not sure what you're saying. If you type your message in and put some line breaks in there, it already puts the appropriate linefeed characters into the statement so that it will reproduce them when producing the MsgBox. Try it out and I think you'll say it already has the capability you're looking for.
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: MsgBox Creator for AHK [v2.0-beta.1]

04 Apr 2023, 10:09

Yes I know that `n is the same for the user but not for the maintainer :)

For example in v1 of AHK PMC makes this code:

Code: Select all

MsgBox, 0, , 
(LTrim
first

second
)
Return
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: MsgBox Creator for AHK [v2.0-beta.1]

04 Apr 2023, 10:45

I see. I won't be adding that capability to this tool, but anyone is free to modify it to their preferences, of course.
sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Re: MsgBox Creator for AHK [v2.0-beta.1]

16 Apr 2023, 22:49

boiler wrote:
06 Jul 2020, 08:48
This is a v2 version of the MsgBox creator used in SciTE4AutoHotkey and first posted by Thalon here. I always found it useful, so I wanted a version for v2. It of course is modified to output v2 code, and it has a couple extra v2-specific options. This version was made for use with any editor since it just copies the code to the clipboard, although it can be modified to be more integrated into specific editors.


MsgBox Creator for AHK v2_MBCv1_1.png


The code:

Code: Select all

/*
	MsgBox Creator for AHK v2
	
	based on Thalon's original "Messagebox-Creator" script
	thanks to fincs for the icon from SciTE4AutoHotkey

	modified for v2 output and translated into v2 code by boiler, updated by AHK_user

	v1.0	- initial release
	v1.1	- added option for single quotes vs. double quotes as suggested by Helgef
			- automatically saves user preferences of the function format options:
				(parenthesis, numeric/string options, single/double quotes)
			- remembers last window position for next time it is run
	v1.2    - updated for AHK v2.0-beta.1 by AHK_user
*/
#Requires AutoHotKey v2.0-beta.1
#SingleInstance Ignore

TraySetIcon("MsgBox.ico", 1)

Paren := IniRead("MsgBox Creator settings.ini", "Main", "Paren", 1)
NumOpt := IniRead("MsgBox Creator settings.ini", "Main", "NumOpt", 1)
DoubleQu := IniRead("MsgBox Creator settings.ini", "Main", "DoubleQu", 1)
WinPosX := IniRead("MsgBox Creator settings.ini", "Main", "WinPosX", "NONE")
WinPosY := IniRead("MsgBox Creator settings.ini", "Main", "WinPosY", "NONE")

global TestMode := 0

MainGui := Gui(, "MsgBox Creator for AHK v2")
MainGui.Add("Text", "x10 y10 Section", "Title:")
MainGui.Add("Edit", "xs+0 ys+15 section w400 vTitle").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("Text", "xs+0 ys+25 section", "Text:")
MainGui.Add("Edit", "xs+0 ys+15 section r3 w400 vText WantTab").OnEvent("Change", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x10 y120 h215 w190 section", "Buttons")
MainGui.Add("Radio", "xs+10 ys+20 section vButtonSelection1 Checked", "OK").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection2", "OK/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection3", "Abort/Retry/Ignore").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection4", "Yes/No/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection5", "Yes/No").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection6", "Retry/Cancel").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vButtonSelection7", "Cancel/Try Again/Continue").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+0 ys+25 vButtonSelectionHelp", "Help button").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x220 y120 h215 w190 section", "Icons")
Icon1Ctrl := MainGui.Add("Radio", "xs+10 ys+25 section vIcon1 Checked", "No Icon")
Icon1Ctrl.OnEvent("Click", SelectIcon)
Icon2Ctrl := MainGui.Add("Radio", "xs+0 ys+40 vIcon2", "Stop/Error")
Icon2Ctrl.OnEvent("Click", SelectIcon)
Icon3Ctrl := MainGui.Add("Radio", "xs+0 ys+80 vIcon3", "Question")
Icon3Ctrl.OnEvent("Click", SelectIcon)
Icon4Ctrl := MainGui.Add("Radio", "xs+0 ys+120 vIcon4", "Exclamation")
Icon4Ctrl.OnEvent("Click", SelectIcon)
Icon5Ctrl := MainGui.Add("Radio", "xs+0 ys+160 vIcon5", "Info")
Icon5Ctrl.OnEvent("Click", SelectIcon)

MainGui.Add("Picture", "xs+90 ys-10 h30 w20").OnEvent("Click", (*) => SelectIcon(Icon1Ctrl))
MainGui.Add("Picture", "xs+90 ys+30 icon4 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon2Ctrl))
MainGui.Add("Picture", "xs+90 ys+70 icon3 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon3Ctrl))
MainGui.Add("Picture", "xs+90 ys+110 icon2 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon4Ctrl))
MainGui.Add("Picture", "xs+90 ys+150 icon5 w32 h32", A_WinDir "\system32\user32.dll").OnEvent("Click", (*) => SelectIcon(Icon5Ctrl))

MainGui.Add("Groupbox", "x430 y20 h120 w190 section", "Modality")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vModality1", "Normal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality2", "Task Modal").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality3", "System Modal (always on top)").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+0 ys+25 section vModality4", "Always on top").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y160 h45 w190 section", "Default Button")
MainGui.Add("Radio", "xs+10 ys+20 section Checked vDefault1", "1st").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault2", "2nd").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Radio", "xs+65 ys+0 section vDefault3", "3rd").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y220 h45 w190 section", "Alignment")
MainGui.Add("Checkbox", "xs+10 ys+20 vAlignment1 section", "Right-justified").OnEvent("Click", CreateMsgBoxFunction)
MainGui.Add("Checkbox", "xs+100 ys+0 vAlignment2", "Right-to-left").OnEvent("Click", CreateMsgBoxFunction)

MainGui.Add("Groupbox", "x430 y280 h45 w100 section", "Timeout")
MainGui.Add("Edit", "xs+10 ys+17 w80 vTimeout").OnEvent("Change", CreateMsgBoxFunction)
MainGui.Add("UpDown", "Range-1-2147483", "-1")

MainGui.Add("Button", "x540 y285 h40 w80 vTest", "&Test").OnEvent("Click", Test)
MainGui.Add("Button", "x430 y345 h45 w100 Default", "&Copy result to clipboard").OnEvent("Click", CopyCode)
MainGui.Add("Button", "x540 y345 h45 w80", "&Reset").OnEvent("Click", (*) => Reset(MainGui))

MainGui.Add("Groupbox", "x10 y340 w105 h50 section", "Function Format")
ParenOptCtrl := MainGui.Add("Checkbox", "xs+10 ys+22 w90 vParen", "Parentheses")
ParenOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x125 ys w140 h50 section", "Options Format")
NumOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vNumOpt", "Numeric")
NumOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
StrOptCtrl := MainGui.Add("Radio", "x+10 yp w50 vStrOpt", "String")
StrOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x275 ys w135 h50 section", "Quotation Marks")
DoubleQuOptCtrl := MainGui.Add("Radio", "xs+10 ys+22 w60 vDoubleQu", "Double")
DoubleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))
SingleQuOptCtrl := MainGui.Add("Radio", "x+5 yp w50 vSingleQu", "Single")
SingleQuOptCtrl.OnEvent("Click", (*) => SaveOptions(MainGui))

MainGui.Add("Groupbox", "x10 y395 w610 h75 section", "Result")
MainGui.SetFont(, "Courier New")
MainGui.SetFont(, "Lucida Sans Typewriter") ; preferred
MainGui.Add("Edit", "xs+10 ys+20 w590 r3 vFunctionText")

ParenOptCtrl.Value := Paren
if NumOpt
	NumOptCtrl.Value := 1
else
	StrOptCtrl.Value := 1
if DoubleQu
	DoubleQuOptCtrl.Value := 1
else
	SingleQuOptCtrl.Value := 1

MainGui.OnEvent("Close", (*) => ExitApp())
if (WinPosX = "NONE") || (WinPosY = "NONE")
	MainGui.Show()
else
	MainGui.Show("x" WinPosX " y" WinPosY)
CreateMsgBoxFunction(MainGui) ; initialize function string
OnMessage(0x232, WM_EXITSIZEMOVE)
return

CreateMsgBoxFunction(this, *) {
	Try
		saved := this.Submit(0)
	Catch {
		this := this.Gui
		saved := this.Submit(0)
	}
	loop 7 {
		if (saved.ButtonSelection%A_Index% = 1) {
			buttonSelection := A_Index - 1
			break
		}
	}
	help := (saved.ButtonSelectionHelp ? 16384 : 0)
	loop 5 {
		if (saved.Icon%A_Index% = 1) {
			icon := [0, 16, 32, 48, 64][A_Index]
			break
		}
	}
	loop 4 {
		if (saved.Modality%A_Index% = 1) {
			modality := [0, 8192, 4096, 262144][A_Index]
			break
		}
	}
	loop 3 {
		if (saved.Default%A_Index% = 1) {
			default := [0, 256, 512][A_Index]
			break
		}
	}
	title := EscapeCharacters(saved.Title, saved.DoubleQu)
	text := EscapeCharacters(saved.Text, saved.DoubleQu)
	timeout := saved.Timeout
	alignment := (saved.Alignment1 = 1) * 524288 + (saved.Alignment2 = 1) * 1048576
	if saved.StrOpt
		options :=	StrReplace(RTrim(["O", "OC", "ARI", "YNC", "YN", "RC", "CTC"][buttonSelection + 1] . " "
						. Map(0, "", 16, "IconX", 32, "Icon?", 48, "Icon!", 64, "Iconi")[icon] . " "
						. Map(0, "", 256, "Default2", 512, "Default3", 768, "Default4")[default] . " "
						. (modality + alignment + help ? modality + alignment + help : "")), "  ", " ")
	else
		options := buttonSelection + icon + modality + default + alignment + help
	
	if TestMode
		return {Options: options, Title: title, Text: text, Timeout: timeout}

	if (timeout = -1) || (timeout = "")
		timeout := ""
	else 
		timeout := "T" StrReplace(timeout, ",", ".") ; allows "," as decimal point

	Qu := saved.DoubleQu ? Chr(34) : "'"
	functionText :=	"MsgBox" . (saved.Paren ? "(" : " ") ; insert paren if selected
						. (text ? Qu . text . Qu : "") "," ; insert quotes around text if it exists
						. (title ? " " . Qu . title . Qu : "") . "," ; insert space and insert quotes around title if it exists
						. ((options . timeout) ? " " . Qu : "") ; insert space and open quote if there are options or timeout
						. (options ? options : "") ; if sum of options is 0, leave it blank, otherwise put in options
						. (options && timeout ? " " : "") ; if there is both an option number and a timeout, insert a space
						. timeout . ((options . timeout) ? Qu : "") ; add timeout if it exists and close quote if necessary
	functionText := RTrim(functionText, ",") ; remove unnecessary commas on the right
						. (saved.Paren ? ")" : "") ; add closing paren if selected
	this.__Item["FunctionText"].Value := functionText
}

SelectIcon(thisCtrl, *) {
	thisCtrl.Value := 1
	CreateMsgBoxFunction(thisCtrl.Gui)
}

EscapeCharacters(str, doubleQu) {
	if doubleQu
		str := StrReplace(str, Chr(34), "``" Chr(34))
	else
		str := StrReplace(str, "'", "``" "'")
	return StrReplace(str, "`n", "``n")
}

Test(thisCtrl, *) {
	global
	TestMode := 1
	info := CreateMsgBoxFunction(thisCtrl)
	TestMode := 0
	thisCtrl.Gui.Opt("+OwnDialogs")
	title := info.Title ? info.Title : "(Name of script)"
	text := StrReplace(info.Text, "``n", "`n")
	if (thisCtrl.Gui.__Item["DoubleQu"].Value = 1)
		text := StrReplace(text, "```"", "`"")
	else
		text := StrReplace(text, "``'", "`'")
	MsgBox text, title, info.Options . (info.Timeout = -1 ? "" : " T" info.Timeout)
}

CopyCode(thisCtrl, *) {
	saved := thisCtrl.Gui.Submit(0)
	A_Clipboard := saved.FunctionText
	MsgBox "The MsgBox code has been copied to the clipboard.`n`nIt is ready to be pasted into your editor.", "MsgBox Code Copied", "4160 T3"
}

Reset(thisGui, *) {
	thisGui.__Item["Title"].Value := ""
	thisGui.__Item["Text"].Value := ""
	thisGui.__Item["ButtonSelection1"].Value := 1
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["ButtonSelectionHelp"].Value := 0
	thisGui.__Item["Icon1"].Value := 1
	thisGui.__Item["Modality1"].Value := 1
	thisGui.__Item["Default1"].Value := 1
	thisGui.__Item["Alignment1"].Value := 0
	thisGui.__Item["Alignment2"].Value := 0
	thisGui.__Item["Timeout"].Value := -1
	thisGui.__Item["NumOpt"].Value := 1
	thisGui.__Item["Paren"].Value := 1
	CreateMsgBoxFunction(thisGui)
}

SaveOptions(thisGui, *) {
	saved := thisGui.Submit(0)
	IniWrite saved.Paren, "MsgBox Creator settings.ini", "Main", "Paren"
	IniWrite saved.NumOpt, "MsgBox Creator settings.ini", "Main", "NumOpt"
	IniWrite saved.DoubleQu, "MsgBox Creator settings.ini", "Main", "DoubleQu"
	CreateMsgBoxFunction(thisGui)
}

WM_EXITSIZEMOVE(*) {
	global MainGui
	MainGui.GetPos(&x, &y)
	IniWrite x, "MsgBox Creator settings.ini", "Main", "WinPosX"
	IniWrite y, "MsgBox Creator settings.ini", "Main", "WinPosY"
}

The zip file below includes the associated icon (taken from SciTE4AutoHotkey -- thanks, fincs). The forum doesn't allow a .ico file to be dropped in directly, so I zipped it along with the .ahk file (updated to include updated script for v2.0-beta.1):
MsgBox Creator for AHK v2_MBCv1_2.zip.zip


v1.1 Changes:
  • added option for single quotes vs. double quotes as suggested by Helgef
  • automatically saves user preferences of the function format options (parenthesis, numeric/string options, single/double quotes)
  • remembers last window position for next time it is run
v1.2 Changes:
  • updated for v2.0-beta.1 by AHK_user
@boiler
here's a conversion for the button style a la magicbox

Code: Select all

;AutoGUI 2.5.8 
;Auto-GUI-v2 credit to autohotkey.com/boards/viewtopic.php?f=64&t=89901
;AHKv2converter credit to github.com/mmikeww/AHK-v2-script-converter
#SingleInstance Force

; REMOVED: #NoEnv

SetWorkingDir(A_ScriptDir)

; REMOVED: SetBatchLines -1

myGui := Gui()

myGui.Add("GroupBox", "x8 y5 w76 h298", "Icon")

ogcButtonNone := myGui.Add("Button", "x22 y25 w48 h48", "None")

ogcButton := myGui.Add("Button", "x22 y79 w48 h48")

ogcButton := myGui.Add("Button", "x22 y133 w48 h48")

ogcButton := myGui.Add("Button", "x22 y187 w48 h48")

ogcButton := myGui.Add("Button", "x22 y242 w48 h48")

ogcButtonIcon := myGui.Add("Button", "x8 y310 w76 h23", "&Icon...")

myGui.Add("Text", "x29 y344 w32 h32")

ogcButtonHelp := myGui.Add("Button", "x8 y401 w76 h23", "Help")

ogcButtonAbout := myGui.Add("Button", "x8 y430 w76 h23", "A&bout")

myGui.Add("GroupBox", "x93 y5 w353 h54", "Title")

myGui.Add("Edit", "x104 y25 w330 h21")

myGui.Add("GroupBox", "x455 y5 w154 h54", "Type")

myGui.Add("DropDownList", "x466 y24 w133", ["MsgBoxEx", "MsgBox", "SHMessageBoxCheck", "MessageBoxIndirect", "SoftModalMessageBox", "MsiMessageBox", "WTSSendMessage", "TaskDialog", "TaskDialogIndirect"])

myGui.Add("GroupBox", "x93 y64 w353 h148", "Text")

myGui.Add("Edit", "x104 y83 w330 h116 +Multi")

myGui.Add("GroupBox", "x93 y216 w353 h237", "Buttons")

myGui.Add("Radio", "x105 y236 w23 h23 +Checked")

myGui.Add("Radio", "x105 y262 w23 h23")

myGui.Add("Radio", "x105 y288 w23 h23")

myGui.Add("Radio", "x105 y314 w23 h23")

myGui.Add("Radio", "x105 y341 w23 h23")

myGui.Add("Radio", "x105 y368 w23 h23")

myGui.Add("Radio", "x105 y395 w23 h23")

ogcButtonOK := myGui.Add("Button", "x130 y236 w87 h23", "OK")

ogcButtonOK := myGui.Add("Button", "x130 y262 w87 h23", "OK")

ogcButtonCancel := myGui.Add("Button", "x222 y262 w87 h23", "Cancel")

ogcButtonYes := myGui.Add("Button", "x130 y288 w87 h23", "&Yes")

ogcButtonNo := myGui.Add("Button", "x222 y288 w87 h23", "&No")

ogcButtonYes := myGui.Add("Button", "x130 y314 w87 h23", "&Yes")

ogcButtonNo := myGui.Add("Button", "x222 y314 w87 h23", "&No")

ogcButtonCancel := myGui.Add("Button", "x314 y314 w87 h23", "Cancel")

ogcButtonAbort := myGui.Add("Button", "x130 y341 w87 h23", "&Abort")

ogcButtonRetry := myGui.Add("Button", "x222 y341 w87 h23", "&Retry")

ogcButtonIgnore := myGui.Add("Button", "x314 y341 w87 h23", "&Ignore")

ogcButtonCancel := myGui.Add("Button", "x130 y368 w87 h23", "Cancel")

ogcButtonTryAgain := myGui.Add("Button", "x222 y368 w87 h23", "&Try Again")

ogcButtonContinue := myGui.Add("Button", "x314 y368 w87 h23", "&Continue")

ogcButtonRetry := myGui.Add("Button", "x130 y395 w87 h23", "&Retry")

ogcButtonCancel := myGui.Add("Button", "x222 y395 w87 h23", "Cancel")

myGui.Add("CheckBox", "x105 y423 w112 h23", "&Help Button")

myGui.Add("GroupBox", "x455 y64 w154 h148", "Options")

myGui.Add("Radio", "x467 y81 w120 h23 +Checked", "&No owner window")

myGui.Add("Radio", "x467 y106 w120 h23", "Application &modal")

myGui.Add("Radio", "x467 y131 w120 h23", "Tas&k modal")

myGui.Add("CheckBox", "x467 y156 w120 h23", "&Always on top")

myGui.Add("CheckBox", "x467 y181 w120 h23", "Right-to-&left reading")

myGui.Add("GroupBox", "x455 y216 w154 h52")

ogcButtonCustomButtons := myGui.Add("Button", "x474 y233 w118 h23", "C&ustom Buttons...")

myGui.Add("GroupBox", "x455 y270 w154 h59", "Position")

myGui.Add("Text", "x463 y291 w16 h23 +Right", "X:")

myGui.Add("Edit", "x485 y293 w40 h21")

myGui.Add("Text", "x530 y291 w16 h23 +Right", "Y:")

myGui.Add("Edit", "x552 y293 w40 h21")

myGui.Add("GroupBox", "x455 y332 w154 h59", "Timeout")

myGui.Add("CheckBox", "x467 y354 w21 h23")

myGui.Add("Edit", "x488 y355 w41 h21", "1")

myGui.Add("UpDown", "x527 y355 w17 h21 -16")

myGui.Add("Text", "x553 y354 w43 h23", "seconds")

ogcButtonTest := myGui.Add("Button", "x455 y401 w75 h23", "&Test")

ogcButtonCode := myGui.Add("Button", "x535 y401 w75 h23", "&Code")

ogcButtonReset := myGui.Add("Button", "x455 y430 w75 h23", "&Reset")

ogcButtonCopy := myGui.Add("Button", "x535 y430 w75 h23", "Cop&y")

Tab := myGui.Add("Tab3", "x0 y0 w0 h0", ["1", "TaskDialogIndirect", "SoftModalMessageBox", "MsgBoxEx"])

Tab.UseTab()

myGui.Title := "MagicBox (Clone)"

myGui.Show("w617 h462")

Return

GuiEscape(*)

{ ; V1toV2: Added bracket

GuiClose:

    ExitApp()

} ; Added bracket in the end

image.png
image.png (103.91 KiB) Viewed 3076 times
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :
sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Re: MsgBox Creator for AHK [v2.0-beta.1]

10 Jun 2023, 13:24

boiler wrote:
04 Apr 2023, 10:45
I see. I won't be adding that capability to this tool, but anyone is free to modify it to their preferences, of course.
if this is on github can I have a link to fork, or get the permission to expand to include functional outputs. IE

Code: Select all

answer := MsgBox("xxxx", "xxxx", "8193")
if (answer = "Yes"){
   Msgbox("Yes")
}
else if (answer = "No") {
   Msgbox("No")
}
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 40 guests