Jump to content
Sign in to follow this  
_Kurt

A GUI Msgbox Replacement

Recommended Posts

_Kurt

Posted Image

I was tired using Msgbox's when users interact with my GUIs, so I decided to write a quick little function to replace my usage of Msgbox's in GUIs.

Why use it instead of a Msgbox?

- does not allow GUI interaction until a msgbox answer is received

- nice looking faded background (see pic)

- customizable msgbox (using your own GUICtrlCreate's).. add inputs, etc.

- a "floating" msgbox (does not display window in taskbar)

Really it's nothing special, but I've been using it so often and I really think it's a step up from a standard Msgbox.

#include <WindowsConstants.au3>

Global Const $GUI_EVENT_CLOSE = -3

$GUI = GUICreate("")
$button1 = GUICtrlCreateButton("Click Me!!",10,10,200,100)
$button2 = GUICtrlCreateButton("No, Click Me!!!!",10,200,200,100)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button1 or $msg = $button2
            $Child = _GUIChild_Create($GUI, 200, 80) ; create the child GUI with 200 width / 100 height
            GUICtrlCreateLabel("Are you sure you want to click on that button?",10,10,200,40) ;create labels/controls
            $yes = GUICtrlCreateButton("Yes",10,50,80)
            $no = GUICtrlCreateButton("No",110,50,80)
            While 1                 ;standard GUI loop
                $xmsg = GUIGetMsg() ;retrieve events
                Select
                    Case $xmsg = $yes or $xmsg = $no ;whether the user presses yes or no.. we still exit the loop
                        ExitLoop
                EndSelect
            WEnd
            _GUIChild_Delete($Child) ; deletes child GUI & returns focus to the original GUI
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

; _GUIChild_Create - creates the faded background & creates the "floating toolbar" child GUI
;     Parameters..
;       $i_handle -> the window title OR handle of your GUI
;       $i_width  -> the designated width of the Child GUI
;       $i_height -> the designated height of the Child GUI
;       $i_transparence -> (OPTIONAL) the transparency of the background
;     Return value..
;       On Success -> an array to be used with the _GUIChild_Delete function
;       On Failure -> 0
Func _GUIChild_Create($i_handle, $i_width, $i_height, $i_transparency=60)
    Local $checkHWND = $i_handle
    If NOT IsHWnd($checkHWND) Then $checkHWND = WinGetHandle($i_handle)
    If NOT IsHWnd($checkHWND) Then Return 0
    Local $pos
    Local $ret[3]
    $pos = WinGetPos($checkHWND)
    $ret[0] = GUICreate("",$pos[2],$pos[3],$pos[0],$pos[1], $WS_POPUP+$WS_DISABLED, $WS_EX_TOOLWINDOW, $checkHWND)
    GUICtrlCreateLabel("",0,0,$pos[2],$pos[3])
    GUICtrlSetBkColor(-1,0x000000)
    WinSetTrans($ret[0],"",$i_transparency)
    $ret[1] = GUICreate("",$i_width,$i_height,($pos[2]/2)+$pos[0]-($i_width/2),($pos[3]/2)+$pos[1]-($i_height/2), $WS_POPUP+$WS_BORDER, $WS_EX_TOOLWINDOW, $checkHWND)
    GUISetState(@SW_DISABLE, $checkHWND)
    GUISetState(@SW_SHOW, $ret[0])
    GUISetState(@SW_SHOW, $ret[1])
    $ret[2] = $checkHWND
    Return $ret
EndFunc

; _GUIChild_Delete - deletes the child GUI & returns focus to the original GUI
;     Parameters..
;       $ret -> what _GUIChild_Create returned
;     Return value..
;       On Success -> 1
;       On Failure -> 0
Func _GUIChild_Delete(ByRef $ret)
    If NOT IsArray($ret) Then Return 0
    GUISetState(@SW_ENABLE,$ret[2])
    GUIDelete($ret[0])
    GUIDelete($ret[1])
    GUISwitch($ret[2])
    Return 1
EndFunc

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites
Andreik

It`s a beautiful script but is more easy with MsgBox(). ;)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.