 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Icarus
Joined: 24 Nov 2005 Posts: 449
|
Posted: Sun Jun 01, 2008 5:32 pm Post subject: [Function] Custom Msgbox / Custom Buttons |
|
|
Hello everybody,
I am guessing there are some scripts like this lying around, but I needed my own dialog, with custom buttons.
So, a quick function for your enjoyment, to do this:
| Code: | ;-------------------------------------------------------------------------------
; Custom Msgbox
; Filename: cmsgbox.ahk
; Author : Danny Ben Shitrit (aka Icarus)
;-------------------------------------------------------------------------------
; Copy this script or include it in your script (without the tester on top).
;
; Usage:
; Answer := CMsgBox( title, text, buttons, icon="", owner=0 )
; Where:
; title = The title of the message box.
; text = The text to display.
; buttons = Pipe-separated list of buttons. Putting an asterisk in front of
; a button will make it the default.
; icon = If blank, we will use an info icon.
; If a number, we will take this icon from Shell32.dll
; If a letter ("I", "E" or "Q") we will use some predefined icons
; from Shell32.dll (Info, Error or Question).
; owner = If 0, this will be a standalone dialog. If you want this dialog
; to be owned by another GUI, place its number here.
;
;-------------------------------------------------------------------------------
; --- TESTER BEGIN - comment out the entire section when including -------------
#SingleInstance Force
; • Simple example
Pressed := CMsgbox( "Hello World", "Are you sure you want to say hello to the world?`n`nWarning! This operation is irreversible.", "&Yes|*Not &Sure|&Not at All|&HELP!", "E" )
Msgbox 32,,"%pressed%" was pressed
; • Custom icon
Pressed := CMsgbox( "Where Is It?", "Do you want to find the holy grail?`n`n(Custom icons from Shell32.dll)", "*&Yes Please|&Not Today|Not &Ever", "23" )
Msgbox 32,,"%pressed%" was pressed
; • Example for msgbox that is owned by our own GUI
Gui Add, Text ,w200, This is my GUI and I'll cry if I want to.
Gui Add, Button,wp , Cry
Gui Show, x200 y200
Pressed := CMsgbox( "Owned", "I am owned by GUI 1", "*&Ok|&Whatever","",1 )
Msgbox 32,,"%pressed%" was pressed
Return
; --- TESTER END ---------------------------------------------------------------
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
|
|
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 361 Location: Texas, USA
|
Posted: Mon Jun 02, 2008 4:38 am Post subject: |
|
|
I like it. No need for it right now but I can see using this sometime in the future. Thanks for sharing.
And yes, you are at least the 4th person to write one of these. The others include Areilius, jonny, and Roland. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Jun 03, 2008 12:09 am Post subject: |
|
|
Cool, thx. _________________
 |
|
| Back to top |
|
 |
twhyman
Joined: 07 Dec 2005 Posts: 218
|
Posted: Tue Jun 03, 2008 11:05 am Post subject: |
|
|
| Thanks, this is great! |
|
| Back to top |
|
 |
Deller
Joined: 21 Nov 2007 Posts: 209 Location: 0x01101110
|
Posted: Tue Jun 03, 2008 9:27 pm Post subject: |
|
|
| This is great. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|