Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Function] Custom Msgbox / Custom Buttons


  • Please log in to reply
20 replies to this topic
  • Guests
  • Last active:
  • Joined: --
have you seen this?
#singleinstance, force
i := MsgBoxV2("Question11"
      ,"Hi, what's up??"
      ,"All right, men|Boooring"
      ,"24")
Sleep 1000   

i := MsgBoxV2("Attention"
      ,"Other colors and fonts ar supportet, enjoy it...`n(Before you pressed button """ i """)"
      ,"Button 1|Button 2|Button 3|Button 4|Button 5|..."
      ,"78"
      ,"10000"
      ,"s12","Rockwell"
      ,"0xFF00FF|0x00FF00|0xFF0000")
Sleep 1000   
   
i := MsgBoxV2("Attention 2"
      ,"Also other window styles...`n`n`nThis window is always on top`n(Before you pressed button """ i """)"
      ,"Cool|Nice!|Whats up?|Well done"
      ,"3"
      ,"10000"
      ,"","",""
      ,"+toolwindow +alwaysontop +altsubmit")
	  
MsgBoxV2("Yeah..."
      ,"Before you pressed button """ i """.`nThe window returned buttonnumber instead of buttontext `nbecause you used +altsubmit."
      ,"All right, men|Booring")
return


MsgBoxV2(Title="",Text="",Buttons="",IconPath="",Timeout="",Font="",Schriftart="Arial",Colors="||",WindowStyles="",GuiNr = "")
{
Static Stat2,Stat1
Col1:="0xFFFFFF" ,Col2:="0x000000",Col3:="0x000000", Color1:="", Color2:="", Color3:=""
Loop, Parse, Colors,`|
Color%A_Index% := (A_Loopfield = "") ? Col%A_Index% : A_Loopfield
Loop 3
Color%A_Index% := (Color%A_Index% = "") ? Col%A_Index% : Color%A_Index%
if instr(WindowStyles,"+altsubmit")
{
AltSub := "1" 
Stringreplace,WindowStyles,WindowStyles,`+altsubmit
}
Gui, Color, %Color1%,%Color1%
Gui, Font, s9
Gui, Font, %Font%, %Schriftart%
X := 20 ,Y := 20
ifexist, %IconPath%
{
Gui, Add, Picture, x20 y20 w32 h32, %IconPath%
X := 70 ,Y := 30
} else
if IconPath is integer
{
Gui, Add, Picture, x20 y20 icon%IconPath% w32 h32, %A_WinDir%\system32\shell32.dll
X := 70 ,Y := 30
}
Gui, Add, Text, x%X% y%Y% c%Color2% vStat2, %Text%
GuicontrolGet, Stat2, Pos
X2 = 10
Y2 := (Stat2Y + Stat2H < 52) ? 82 : Stat2Y + Stat2H + 30
HMax = 0
Gui, Add, Text, vStat1 +border -background
Loop, Parse, Buttons,|,`|
{
Gui, Add, Button, x%X2% w100 Y%Y2% gExButton , %A_Loopfield%
ButT%A_Index% := A_Loopfield
Guicontrolget, Button%A_Index%,Pos
if (HMax < Button%A_Index%H)
HMax := Button%A_Index%H
ABut := A_Index
X2 += 110
}
Loop %ABut%
Guicontrol, Move, Button%A_Index%,h%HMax%
Gui, %WindowStyles%
Gui, Show, Autosize Center,%Title%
Guicontrol, Move, Stat1, % "X-1 Y" Y2 - 10 " W" 1400 " h" 41 + HMax
Guicontrol, -Background +hidden, Stat1
Guicontrol, show, Stat1
Gui, +LastFound
WinGet, G_id
if Timeout !=
if Timeout is integer
settimer, Timeout, %Timeout%
Winwait, ahk_id %G_id%
retval = 0
while winexist("ahk_id " G_id)
sleep 100
if !AltSub
return ButT%retval%
else
return retval
Timeout:
if Timeout =
return
GuiClose:
Gui, destroy
return
ExButton:
MouseGetPos,,,, Control
Stringreplace,retval,Control,Button
Gui, destroy
return
}


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

where should i add this in the following (original code) to make the window transparent?: WinSet, Transparent, 150

original code:

CMsgBox( title, text, buttons, icon="", owner=0 ) {
Global _CMsg_Result

GuiID := 9 ; If you change, also change the subroutines below

StringSplit Button, buttons, |

If( owner <> 0 ) {
Gui %owner%:+Disabled
Gui %GuiID%:+Owner%owner%
}

Gui %GuiID%:+Toolwindow +AlwaysOnTop

MyIcon := ( icon = "I" ) or ( icon = "" ) ? 222 : icon = "Q" ? 24 : icon = "E" ? 110 : icon

Gui %GuiID%:Add, Picture, Icon%MyIcon% , Shell32.dll
Gui %GuiID%:Add, Text, x+12 yp w180 r8 section , %text%

Loop %Button0%
Gui %GuiID%:Add, Button, % ( A_Index=1 ? "x+12 ys " : "xp y+3 " ) . ( InStr( Button%A_Index%, "*" ) ? "Default " : " " ) . "w100 gCMsgButton", % RegExReplace( Button%A_Index%, "\*" )

Gui %GuiID%:Show,,%title%

Loop
If( _CMsg_Result )
Break

If( owner <> 0 )
Gui %owner%:-Disabled

Gui %GuiID%:Destroy
Result := _CMsg_Result
_CMsg_Result := ""
Return Result
}

9GuiEscape:
9GuiClose:
_CMsg_Result := "Close"
Return

CMsgButton:
StringReplace _CMsg_Result, A_GuiControl, &,, All
Return


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

this is a modified version which implements a feature where message box closes after a certain wait time:

; http://www.autohotkey.com/board/topic/29570-function-custom-msgbox-custom-buttons/

CMsgBox( title, text, buttons, icon="", owner=0 ) {
  Global _CMsg_Result
  
  GuiID := 9 ; If you change, also change the subroutines below
  
  StringSplit Button, buttons, |
  
  If( owner <> 0 ) {
    Gui %owner%:+Disabled
    Gui %GuiID%:+Owner%owner%
  }
  
  Gui %GuiID%:+Toolwindow +AlwaysOnTop 
  WinSet, Transparent, 150 ; Optional
  
  MyIcon := ( icon = "I" ) or ( icon = "" ) ? 222 : icon = "Q" ? 24 : icon = "E" ? 110 : icon
  
  Gui %GuiID%:Add, Picture, Icon%MyIcon% , Shell32.dll
  Gui %GuiID%:Add, Text, x+12 yp w180 r8 section , %text%
  
  Loop %Button0% 
    Gui %GuiID%:Add, Button, % ( A_Index=1 ? "x+12 ys " : "xp y+3 " ) . ( InStr( Button%A_Index%, "*" ) ? "Default " : " " ) . "w100 gCMsgButton", % RegExReplace( Button%A_Index%, "\*" )

  Gui %GuiID%:Show,,%title%

Loop, 100 {
If (_CMsg_Result == "Yes")
GoTo LP
Else
If (_CMsg_Result == "No")
{
Send, ^p
GoTo LP
}
Else
If (_CMsg_Result == "Close")
GoTo LP
Sleep, 100
}
WinClose, %title%

LP:  
  Loop 
    If( _CMsg_Result )
      Break

  If( owner <> 0 )
    Gui %owner%:-Disabled
    
  Gui %GuiID%:Destroy
  Result := _CMsg_Result
  _CMsg_Result := ""
  Return Result
}

9GuiEscape:
9GuiClose:
  _CMsg_Result := "Close"
Return

CMsgButton:
  StringReplace _CMsg_Result, A_GuiControl, &,, All
Return

^p:: Pause


James
  • Members
  • 4 posts
  • Last active: Jun 29 2013 07:50 AM
  • Joined: 04 May 2013

3 nice program. work all for me.



Leperkawn
  • Members
  • 1 posts
  • Last active: Aug 28 2013 07:09 PM
  • Joined: 27 Aug 2013

Very cool, thanks OP for this function.



s0ulp0wer
  • Members
  • 3 posts
  • Last active: Aug 30 2015 12:16 AM
  • Joined: 16 Feb 2013

Hey there i have a question to the use of this function.
when i get the output how do i use it to test if/else statements?

question here: http://stackoverflow...ge-box-function
 

I've been trying to create a script that displays message boxes conditioned on the output from another customized message box with more than 3 options.

The custom functions are taken form this thread http://www.autohotke...-buttons/page-2

I've tried both the CMsgbox and the MsgBoxV2 functions, running into the same problem. The Message "IT WORKED!" testing with if(condition) will always appear regardless of whether pressing any of the Sym|&Go|&C options, and the message "worked" will never appear regardless of actually pressing C, In other words no specificity or sensitivity regarding variable testing.

!o::
var := MsgBoxV2("Question11","Hi, what's up??","Sym|Go|C","24")
Msgbox 4,, You Pressed %var%

if (%var% = C)
{
Msgbox 4,, IT WORKED!
}

IfEqual, %var%,C
{
Msgbox 4,, worked
}
return

!e::
var := CMsgbox( "s", "d", "*&Sym|&Go|&C","",1 )
Msgbox 4,, You Pressed %var%
if (%var% = C)
{
Msgbox 4,, IT WORKED!
}

IfEqual, %var%,C
{
Msgbox 4,, worked
}
return

I don't know if this is because I've misunderstood the if/Else testing in ahk, or if the output from these custom functions cannot be tested, or both. One solution would be to figure out what type of variable %var% is, but I've not been able to find a way to figure that out either.

Thanks for reading and hope you guys can help.

here are the custom message functions for testing