MsgBox Option Calculator

Post your working scripts, libraries and tools
MarcusK35
Posts: 4
Joined: 30 Mar 2015, 15:06

MsgBox Option Calculator

30 Mar 2015, 15:16

All,

I use the following script to determine the options when when creating a MsgBox because it drove me crazy using a calculator to figure this out manually. Not sure if something is already out there but here ya go

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 C:\Temp  ; Ensures a consistent starting directory.
#SingleInstance, force

OptionsSelect:
YVar := 0
Lines := 0

Gui, Destroy
Gui, Font, s8, Verdana
Gui, Add, Checkbox, vOK, OK
Gui, Add, Checkbox, vOKCan, OK/Cancel
Gui, Add, Checkbox, vAbtRtryIgn, Abort/Retry/Ignore
Gui, Add, Checkbox, vYesNoCan, Yes/No/Cancel
Gui, Add, Checkbox, vYesNo, Yes/No
Gui, Add, Checkbox, vRtryCan, Retry/Cancel
Gui, Add, Checkbox, vCanTryCont, Cancel/TryAgain/Continue
Gui, Add, Checkbox, vHelpBut, Help Button
Gui, Add, Checkbox, vIcoHand, Icon Hand
Gui, Add, Checkbox, vIcoQuest, Icon Question
Gui, Add, Checkbox, vIcoExcl, Icon Exclamation
Gui, Add, Checkbox, vIcoAsk, Icon Askerisk
Gui, Add, Checkbox, v2ndButDef, Make 2nd button default
Gui, Add, Checkbox, v3rdButDef, Make 3rd button default
Gui, Add, Checkbox, vSysMod, System Modal
Gui, Add, Checkbox, vTaskMod, Task Modal
Gui, Add, Checkbox, vDefDesktop, MsgBox on default desktop
Gui, Add, Checkbox, vAlwOnTop, Always-on-top
Gui, Add, Checkbox, vTxtRtJust, Text right-justified
Gui, Add, Text, , 
Gui, Add, Button, x60 h25 gCalculate, Calculate
Gui, Show, , MsgBox Calculator
Gui, -0x20000
Return

Calculate:
Gui, Submit
Gui, Destroy

Gui, Font, s8, Verdana
Gui, Add, Text, ,Options Selected:
If OK = 1
{
	OK := 0
	Lines := Lines + 1
	Gui, Add, Text, , OK
}
If OKCan = 1
{
	OKCan := 1
	Lines := Lines + 1
	Gui, Add, Text, , OK/Cancel
}
If AbtRtryIgn = 1
{
	AbtRtryIgn := 2
	Lines := Lines + 1
	Gui, Add, Text, , Abort/Retry/Ignore
}
If YesNoCan = 1
{
	YesNoCan := 3
	Lines := Lines + 1
	Gui, Add, Text, , Yes/No/Cancel
}
If YesNo = 1
{
	YesNo := 4
	Lines := Lines + 1
	Gui, Add, Text, , Yes/No
}	
If RtryCan = 1
{
	RtryCan := 5
	Lines := Lines + 1	
	Gui, Add, Text, , Retry/Cancel
}
If CanTryCont = 1
{
	CanTryCont :=6
	Lines := Lines + 1
	Gui, Add, Text, , Cancel/TryAgain/Continue
}	
If HelpBut = 1
{
	HelpBut := 16384
	Lines := Lines + 1
	Gui, Add, Text, , Help Button
}
If IcoHand = 1
{
	IconHand := 16
	Lines := Lines + 1
	Gui, Add, Text, , Icon Hand
}	
If IcoQuest = 1
{
	IcoQuest := 32
	Lines := Lines + 1
	Gui, Add, Text, , Icon Question
}
If IcoExcl = 1
{
	IcoExcl := 48
	Lines := Lines + 1
	Gui, Add, Text, , Icon Exclamation
}	
If IcoAsk = 1
{
	IcoAsk := 64
	Lines := Lines + 1
	Gui, Add, Text, , Icon Askerisk
}
If 2ndButDef = 1
{
	2ndButDef := 256
	Lines := Lines + 1
	Gui, Add, Text, , Make 2nd button default
}
If 3rdButDef = 1
{
	3rdButDef := 512
	Lines := Lines + 1
	Gui, Add, Text, , Make 3rd button default
}
If SysMod = 1
{
	SysMod := 4096
	Lines := Lines + 1
	Gui, Add, Text, , System Modal
}	
If TaskMod = 1
{
	TaskMod := 8192
	Lines := Lines + 1
	Gui, Add, Text, , Task Modal
}
If DefDesktop = 1
{
	DefDesktop := 131072
	Lines := Lines + 1
	Gui, Add, Text, , MsgBox on default desktop
}
If AlwOnTop = 1
{
	AlwOnTop := 262144
	Lines := Lines + 1
	Gui, Add, Text, , Always-on-top
}	
If TxtRtJust = 1
{
	TxtRtJust := 524288
	Lines := Lines + 1
	Gui, Add, Text, , Text right-justified
}
Gui, Add, Text, ,
Total := OK + OKCan + AbtRtryIgn + YesNoCan + YesNo + RtryCan + CanTryCont + HelpBut + IcoHand + IcoQuest + IcoExcl + IcoAsk + 2ndButDef + 3rdButDef + SysMod + TaskMod + DefDesktop + AlwOnTop + TxtRtJust
Lines := Lines + 5 ;Use to adjust button placement
YVar := Lines * 26
Gui, Add, Text, , MsgBox variable:
Gui, Add, Text, ,  %Total%
Gui, Add, Button, x10 y%YVar% h25 w70 gEnd, Exit
Gui, Add, Button, x90 y%YVar% h25 w70 gOptionsSelect, Rerun
Gui, Show, , MsgBox Variable
Gui, -0x20000
Return

End:
ExitApp
Esc::ExitApp
^!r::Reload
Last edited by MarcusK35 on 31 Mar 2015, 09:12, edited 1 time in total.
garry
Posts: 1761
Joined: 22 Dec 2013, 12:50

Re: MsgBox Option Calculator

31 Mar 2015, 03:07

thank you , this is good idea , works fine
I use longtime the existing script from user 'Thalon'
;- msgboxcreatorx =
;- Thalon http://de.autohotkey.com/forum/viewtopic.php?t=534
;- digit http://de.autohotkey.com/forum/viewtopic.php?t=3797
;- r0lZ http://www.autohotkey.com/forum/topic76419.html

EDIT
realized, old links no more work but I can upload here the script

Code: Select all

;- Thalon http://de.autohotkey.com/forum/viewtopic.php?t=534
;- digit  http://de.autohotkey.com/forum/viewtopic.php?t=3797
;- r0lZ   http://www.autohotkey.com/forum/topic76419.html

;- script from user "Thalon"
;Tray-Menu
Menu, Tray, Add, Open, Open
Menu, Tray, Add, Reset Settings, Reset
Menu, Tray, Add, Close, GuiClose
Menu, Tray, Click, 1
Menu, Tray, Default, Open
Menu, Tray, NoStandard

;GUI
Gui, Add, Groupbox, x10 y10 w340 h125, Title && Text
Gui, Add, Text, xs+10 ys+20 section, Title:
Gui, Add, Edit, xs+30 ys-3 w290 vTitle gCreate_Msgbox_Command WantTab,
Gui, Add, Text, xs+0 ys+25 section, Text:
Gui, Add, Edit, xs+30 ys-3 r5 w290 vText gCreate_Msgbox_Command WantTab,

Gui, Add, Groupbox, x10 y145 h65 w340 section, Modality
Gui, Add, Radio, xs+10 ys+20 section Checked vModality1 gCreate_Msgbox_Command, Normal
Gui, Add, Radio, xs+70 ys+0 vModality2 gCreate_Msgbox_Command, Task Modal
Gui, Add, Radio, xs+160 ys+0 vModality3 gCreate_Msgbox_Command, System Modal (always on top)
Gui, Add, Radio, xs+0 ys+25 section vModality4 gCreate_Msgbox_Command, Always on top
Gui, Add, Radio, xs+160 ys+0 section vModality5 gCreate_Msgbox_Command, Default desktop

Gui, Add, Groupbox, x10 y220 w340 h155 section, Icons
Gui, Add, Picture, xs+20 ys+20 gSelect_NoIcon section icon1, %A_WinDir%\system32\user32.dll
Gui, Add, Picture, xs+125 ys+0 gSelect_ErrorIcon icon4 , %A_WinDir%\system32\user32.dll
Gui, Add, Picture, xs+240 ys+0 gSelect_Question icon3 , %A_WinDir%\system32\user32.dll
Gui, Add, Radio, xs-10 ys+40 section vIcon1 Checked gCreate_Msgbox_Command, No Icon
Gui, Add, Radio, xs+125 ys+0 vIcon2 gCreate_Msgbox_Command, Stop/Error
Gui, Add, Radio, xs+240 ys+0 vIcon3 gCreate_Msgbox_Command, Question
Gui, Add, Radio, xs+0 ys+70 section vIcon4 gCreate_Msgbox_Command, Exclamation
Gui, Add, Radio, xs+125 ys+0 vIcon5 gCreate_Msgbox_Command, Info
Gui, Add, Picture, xs+10 ys-40 gSelect_Exclamation section icon2, %A_WinDir%\system32\user32.dll
Gui, Add, Picture, xs+125 ys+0 gSelect_Info icon5 , %A_WinDir%\system32\user32.dll

Gui, Add, Groupbox, x10 y385 h95 w340 section, Buttons
Gui, Add, Radio, xs+10 ys+20 vButton_Selection1 section Checked gCreate_Msgbox_Command, OK
Gui, Add, Radio, xs+115 ys+0 vButton_Selection2 gCreate_Msgbox_Command, OK/Cancel
Gui, Add, Radio, xs+210 ys+0 vButton_Selection3 gCreate_Msgbox_Command, Abort/Retry/Ignore
Gui, Add, Radio, xs+0 ys+25 section vButton_Selection4 gCreate_Msgbox_Command, Yes/No/Cancel
Gui, Add, Radio, xs+115 ys+0 vButton_Selection5 gCreate_Msgbox_Command, Yes/No
Gui, Add, Radio, xs+210 ys+0 vButton_Selection6 gCreate_Msgbox_Command, Retry/Cancel
Gui, Add, Radio, xs+0 ys+25 section vButton_Selection7 gCreate_Msgbox_Command, Cancel/Try Again/Continue
Gui, Add, Checkbox, xs+210 ys+0 vButton_Selection_Help gCreate_Msgbox_Command, Help button

Gui, Add, Groupbox, x10 y490 h45 w230 section, Default-Button
Gui, Add, Radio, xs+10 ys+20 section Checked vDefault1 gCreate_Msgbox_Command, First
Gui, Add, Radio, xs+80 ys+0 vDefault2 gCreate_Msgbox_Command, Second
Gui, Add, Radio, xs+160 ys+0 vDefault3 gCreate_Msgbox_Command, Third

Gui, Add, Groupbox, x260 y490 h45 w90 section, Timeout
Gui, Add, Edit, xs+10 ys+17 w70 vTimeout gCreate_Msgbox_Command
Gui, Add, UpDown, Range-1-2147483, -1

Gui, Add, Groupbox, x10 y545 w230 h45 section, Allignment
Gui, Add, Checkbox, xs+10 ys+20 vAllignment1 section gCreate_Msgbox_Command, Right-justified
Gui, Add, Checkbox, xs+115 ys+0 vAllignment2 gCreate_Msgbox_Command, Right-to-left

Gui, Add, Groupbox, x10 y600 w340 h95 section, Result
Gui, Add, Edit, xs+10 ys+20 w320 r2 vMsgbox_Command,
Gui, Add, Button, xs+10 ys+60 h30 w40 Default vTest gTest, Test
Gui, Add, Button, xs+120 ys+60 h30 w100 gCopy_to_Clipboard, Copy to Clipboard
Gui, Add, Button, xs+290 ys+60 h30 w40 gReset, Reset
Gui, Show,x0 y0 w380 h700 , Create MessageBox
GoSub, Reset      ;Initalize GUI from Ini
return

Select_NoIcon:
GuiControl, , Icon1, 1
GoSub, Create_Msgbox_Command
return

Select_ErrorIcon:
GuiControl, , Icon2, 1
GoSub, Create_Msgbox_Command
return

Select_Question:
GuiControl, , Icon3, 1
GoSub, Create_Msgbox_Command
return

Select_Exclamation:
GuiControl, , Icon4, 1
GoSub, Create_Msgbox_Command
return

Select_Info:
GuiControl, , Icon5, 1
GoSub, Create_Msgbox_Command
return

Create_Msgbox_Command:
Gui, Submit, NoHide
;Get types of used buttons
Loop, 7
{
   if Button_Selection%A_Index% = 1
   {
      ButtonSelection := A_Index -1
      if Button_Selection_Help = 1
         ButtonSelection += 16384
      break
   }
}

;Get used Icon
Loop, 5
{
   if Icon%A_Index% = 1
   {
      if A_Index = 1
         Icon = 0
      else if A_Index = 2
         Icon = 16
      else if A_Index = 3
         Icon = 32
      else if A_Index = 4
         Icon = 48
      else if A_Index = 5
         Icon = 64
      break
   }
}

;Get Modality-State
Loop, 5
{
   if Modality%A_Index% = 1
   {
      if A_Index = 1
         Modality = 0
      else if A_Index = 2
         Modality = 8192
      else if A_Index = 3
         Modality = 4096
      else if A_Index = 4
         Modality = 262144
      else if A_Index = 5
         Modality = 131072
      break
   }
}

;Get Default-Button
Loop, 3
{
   if Default%A_Index% = 1
   {
      if A_Index = 1
         Default = 0
      else if A_Index = 2
         Default = 256
      else if A_Index = 3
         Default = 512
      break
   }
}

;Check Allignment
Allignment = 0
if Allignment1 = 1
   Allignment += 524288
if Allignment2 = 1
   Allignment += 1048576

Msgbox_Number := ButtonSelection + Icon + Modality + Default + Allignment   ;Generate type of messagebox

Escape_Characters(Title)
Escape_Characters(Text)

;Timeout "-1" = no timeout
if Timeout = -1
   Timeout =
else
{
   StringReplace, Timeout, Timeout, `,, .      ;Allows "," as decimal-point
   Timeout = , %Timeout%
}



;Create command and set it to Edit-Control
Msgbox_Command = msgbox, %Msgbox_Number%, %Title%, %Text%%Timeout%
GuiControl, , Msgbox_Command, %Msgbox_Command%
return


;Creates a Temp-File to show actual configuration
Test:
GoSub, Create_Msgbox_Command
GuiControl, Disable, Test
FileAppend, %Msgbox_Command%, MsgboxTemp.ahk
RunWait, MsgboxTemp.ahk
FileDelete, MsgboxTemp.ahk
GuiControl, Enable, Test
return


;Escapes Characters like ","
Escape_Characters(byref Var)
{
   StringReplace, Var, Var, `n, ``n, All      ;Translate line breaks in entered text
   StringReplace, Var, Var, `,, ```,, All      ;Escapes ","
   StringReplace, Var, Var, `;, ```;, All      ;Escapes ";"
}



Copy_to_Clipboard:
Clipboard = %Msgbox_Command%
IniRead, Reset_after_Clipboard, %A_ScriptDir%\Msgbox.ini, Clipboard, Reset after Clipboard, 0
if Reset_after_Clipboard = 1
   GoSub, Reset
return

GuiClose:
ExitApp

Open:
Gui, Show
return

Reset:
IfExist %A_ScriptDir%\Msgbox.ini
{
   IniRead, Title, %A_ScriptDir%\Msgbox.ini, Reset, Title, plk
   if Title = plk
      Title =
   IniRead, Text, %A_ScriptDir%\Msgbox.ini, Reset, Text, plk
   if Text = plk
      Text =
   IniRead, Modality, %A_ScriptDir%\Msgbox.ini, Reset, Modality, 1
   IniRead, Icon, %A_ScriptDir%\Msgbox.ini, Reset, Icon, 1
   IniRead, Button_Selection, %A_ScriptDir%\Msgbox.ini, Reset, Button, 1
   IniRead, Button_Selection_Help, %A_ScriptDir%\Msgbox.ini, Reset, Help Button, 0
   IniRead, Default, %A_ScriptDir%\Msgbox.ini, Reset, Default Button, 1
   IniRead, Timeout, %A_ScriptDir%\Msgbox.ini, Reset, Timeout, -1
   IniRead, Allignment1, %A_ScriptDir%\Msgbox.ini, Reset, Allignment_Right, 0
   IniRead, Allignment2, %A_ScriptDir%\Msgbox.ini, Reset, Allignment_RtL, 0
}
else
{
   Title =
   Text =
   Modality = 1
   Icon = 1
   Button_Selection = 1
   Button_Selection_Help = 0
   Default = 1
   Timeout = -1
   Allignment1 = 0
   Allignment2 = 0
}

GuiControl, , Title, %Title%
GuiControl, , Text, %Text%
GuiControl, , Modality%Modality%, 1
GuiControl, , Icon%Icon%, 1
GuiControl, , Button_Selection%Button_Selection%, 1
GuiControl, , Button_Selection_Help, %Button_Selection_Help%
GuiControl, , Default%Default%, 1
GuiControl, , Timeout, %Timeout%
GuiControl, , Allignment1, %Allignment1%
GuiControl, , Allignment2, %Allignment2%
return

GuiSize:
if A_EventInfo = 1
   Gui, Show, Hide
return
;============================== end script ==============================
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: MsgBox Option Calculator

31 Mar 2015, 06:37

very nice
John ... you working ?
MarcusK35
Posts: 4
Joined: 30 Mar 2015, 15:06

Re: MsgBox Option Calculator

31 Mar 2015, 09:18

I had a feeling there would be something more polished out there... Thanks for the code gary.
MarcusK35
Posts: 4
Joined: 30 Mar 2015, 15:06

Re: MsgBox Option Calculator

31 Mar 2015, 09:22

Question about the MsgBox command: What does System Modal (always on top) do, that Always on Top does not do?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: DuyMinh, Flipeador and 46 guests