AutoHotkey Community

It is currently May 27th, 2012, 9:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: June 1st, 2008, 5:32 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
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:
Image

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



Last edited by Icarus on December 13th, 2011, 6:52 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2008, 4:38 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 12:09 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Cool, thx.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 11:05 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
Thanks, this is great!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2008, 9:27 pm 
Offline

Joined: November 21st, 2007, 10:27 pm
Posts: 239
Location: 0x01101110
This is great.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 8:44 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
I was inspired so I made [Function] Custom Input box / Password box


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 9:59 am 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
try out this too )

_________________
Crypt|QMsgBox|PUM|Quick Cliq|WinClipboard


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 6:01 am 
Offline

Joined: December 13th, 2011, 5:53 am
Posts: 1
Location: New York
Cool, thx. it is great!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 5:02 pm 
Offline

Joined: January 15th, 2008, 1:46 pm
Posts: 28
Thanks @AmourSpirit for replying to a 3 years old thread. I'd have never found it. I love it.

Since I'm on dual screen I hate it when GUIs appear on the wrong screen. I've added some little code, so the GUI message box appears on the monitor with the mouse cursor.

I'm sure it can be done better, but it works for me. :)
WinGetPos wouldn't bring me results unless the GUI is shown and I wanted to avoid flickering. So I made this with transparency.


Replace

Code:
   Gui,%GuiID%:Show,,%title%


with

Code:
   DetectHiddenWindows,On
   Gui,%GuiID%:+LastFound
   hwnd:=WinExist()
   WinSet,Transparent,0,ahk_id %hwnd%
   Gui,%GuiID%:Show,,%title%
   WinGetPos,X,,,,ahk_id %hwnd%
   WinMove,ahk_id %hwnd%,,% DualDisplay(hwnd,x)
   WinSet,Transparent,OFF,ahk_id %hwnd%


and add following function in your script.

Code:
DualDisplay(hwnd,x){
   sysget, m1, monitor, 1
   sysget, m2, monitor, 2
   Coordmode, Mouse, Screen
   MouseGetPos, m_x
   m_l := (m_x > m1right) ? m1right : ((m_x > m2right) ? m2right : "")
   Return % (m_l = "") ? x : ((x < m_l) ? x + m_l : x)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 5:33 pm 
Online

Joined: December 2nd, 2011, 4:41 pm
Posts: 57
thats very useful (:

_________________
http://www.autohotkey.net/~iBob35555VR << help me creating better graphics! :P post suggestions in "Leave a comment". Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 6:53 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
Updated screenshot.

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Cmsgbox not working
PostPosted: December 20th, 2011, 1:12 pm 
Offline

Joined: December 20th, 2011, 12:51 pm
Posts: 1
Location: Taiwan
Do I need to have a special plug-in to make the CMsgBox work? or QMsgBox? I'm trying to make message boxes that pop up. I just tried copying the code into Notepad++. This will be my first attempt at any kind of scripting besides my T-89 calculator in high school and a little VB at my job. Thank you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2011, 2:56 pm 
Offline

Joined: January 15th, 2008, 1:46 pm
Posts: 28
Hi Ryanmm50,

you'll need an installation of Autohotkey to make the script work.

This will probably help you: http://www.autohotkey.com/docs/Tutorial.htm

Have fun! :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Wonderful
PostPosted: January 1st, 2012, 2:49 am 
Offline

Joined: April 22nd, 2011, 2:59 pm
Posts: 45
Thank you for sharing. Icarus.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2012, 9:41 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
Code:
DualDisplay(hwnd,x){
   sysget, m1, monitor, 1
   sysget, m2, monitor, 2
   Coordmode, Mouse, Screen
   MouseGetPos, m_x
   m_l := (m_x > m1right) ? m1right : ((m_x > m2right) ? m2right : "")
   Return % (m_l = "") ? x : ((x < m_l) ? x + m_l : x)
}
[/quote]


hmm.. do you use hwnd in the function ?

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Rajat, SKAN and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group