Sign in to follow this  
Followers 0
JohnBailey

Best UDF for having an advanced Msg/Dialog Box

11 posts in this topic

Desire:

I want to have the msgbox/dialogbox show and not display in the taskbar, but rather be a child of the original gui.

Question:

What is the best solution

I've found a few

#297198

http://www.autoitscript.com/forum/index.php?showtopic=29454

http://www.autoitscript.com/forum/index.php?showtopic=30758

If need be, I will post an example script.


A decision is a powerful thing

Share this post


Link to post
Share on other sites



found another:

#232040

and no replies :)


A decision is a powerful thing

Share this post


Link to post
Share on other sites

I expanded one of the simple ones, but it has no timer and I looked on msdn and found nothing there either

_Dialog_MsgBox(0, "Timer", "This Window will close in 5 seconds", "",5)
;===============================================================================
;
; Function Name:    _Dialog_MsgBox()
; Description:    
; Parameter(s):  
;                   $flag           -  number   - Optional: The flag indicates the type of message box and the possible button combinations.
;                                                           0 = (Default) OK button
;                                                           [Button-related Result]
;                                                           1 = OK and Cancel
;                                                           2 = Abort, Retry, and Ignore
;                                                           3 = Yes, No, and Cancel
;                                                           4 = Yes and No
;                                                           5 = Retry and Cancel
;                                                           6 = Cancel, Try Again, Continue (Note: Only valid on Windows 2000/XP and above)
;                                                           [Icon-related Result]
;                                                           16 = Stop-sign icon
;                                                           32 = Question-mark icon
;                                                           48 = Exclamation-point icon 
;                                                           64 = Information-sign icon consisting of an 'i' in a circle 
;                                                           For the rest see the AutoIt Help Document for MsgBox
;
;                   $title          - string    - Optional: The title of the message box.
;                   $text           - string    - Optional: The text of the message box.
;                   $parent         - var       - Optional: The Parent Window to "attach to".
;
; Requirement(s):   
; Return Value(s):  On Success  - Returns 1 
;                  On Failure   - Returns 0 and sets @ERROR
;                   @ERROR      - 0 = 
;                               - 1 = 
;                               - 2 = 
;                               - 3 = 
;                   @Extended   - 
; CallTip:
; Note(s):          http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/messagebox.asp
;                   MsgBox(flag, "title", "text", [, timeout])
;
; Author(s):        user52 (http://www.autoitscript.com/forum/index.php?showtopic=35999&view=findpost&p=297198)
;
;===============================================================================
Func _Dialog_MsgBox($flag=0, $title="", $text="", $parent="",$timeout=-1)
    DllCall("user32.dll", _    ; dll mother
            "int", "MessageBox", _; dll function
            "hwnd", $parent, _  ; maingui to bind msgbox to (if any)
            "str", $text , _      ; msgbox text
            "str", $title, _      ; msgbox title
            "int", $flag)        ; msgbox type
    If $timeout <> -1 Then
        Local $_begin = TimerInit()
        Local $_dif = TimerDiff($_begin)
        Local $timeoutCalc = $timeout * 1000
        While $_dif < $timeoutCalc
            ConsoleWrite($timeoutCalc&@LF)
            $_dif = TimerDiff($_begin)
        WEnd
        Local $_wincloseResult = WinClose($title,$text)
        ConsoleWrite($_wincloseResult&@LF)
    EndIf
EndFunc

A decision is a powerful thing

Share this post


Link to post
Share on other sites

The timer does not work on the above, because the DLL pauses the script.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

I think the best solution would be to make a gui similar to a message box; making it competely customizable.

Share this post


Link to post
Share on other sites

Similar to

;===============================================================================
;
; Function Name:    _Dialog_MessageGUI()
; Parameter(s):  $P_title       - The Title of the message
;              $P_Text          - Text of the message
;              $P_parent    - The Window handle of the Parent GUI.
;              $P_flag          - 0: will display "OK" button only.
;                            4: Will display "Yes" and "No" buttons.
;                            10: Will display "OK" and "Cancel" with InputBox
;              $P_dis   - If = 1 then the Parent GUI will be disabled
;              $P_timeOut  - Time out value in ms.
; Return Value(s):  On "Time Out": @error = 1 and return = -1
;                  If "Yes" clicked returns 6
;              If "No" or "Cancel" returns 7 and sets @error=1
;              If Input Box and pressed "OK" will return a string with value of the inputbox.
;
;
; Found: http://www.autoitscript.com/forum/index.php?showtopic=29454&view=findpost&p=209854
;===============================================================================
Func _Dialog_MessageGUI($P_title, $P_Text, $P_parent, $P_flag = 0, $P_dis = 1, $P_timeOut = 0)
    GUISetState(@SW_SHOW, $P_parent)
    GUISetState(@SW_RESTORE, $P_parent);;restoring the GUI.
    $L_mode_backup = Opt("GUIOnEventMode", 0)
    Local Const $L_char_width = 5, $L_button_width = 70, $L_button_hight = 23, $L_char_hight = 15
    Local $L_get_win_pos, $L_MSG_BAD = -123, $L_input = -124, $L_temp_read, $L_input_Width, $L_line_count, $L_TEMP_char_perLine
    Local $L_lable_width, $L_lable_hight, $L_temp, $L_get_win_pos, $L_temp_time, $L_first_button_left, $L_second_button_left
    $L_line_count = StringSplit($P_Text, @LF, 1)
    Dim $L_char_perLine[$L_line_count[0] + 1]
    If $P_dis = 1 Then
        GUISetState(@SW_DISABLE, $P_parent)
    ElseIf $P_dis = 2 Then
        GUISetState(@SW_DISABLE, $P_parent)
        GUISetState(@SW_HIDE, $P_parent)
    EndIf
   
    Select
        Case $L_line_count[0] > 1
            $L_char_perLine[0] = $L_line_count[0]
            For $L_a = 1 To $L_line_count[0]
                $L_TEMP_char_perLine = StringSplit($L_line_count[$L_a], '')
                $L_char_perLine[$L_a] = $L_TEMP_char_perLine[0]
            Next
        Case $L_line_count[0] = 1
            $L_char_perLine = StringSplit($P_Text, "")
            $L_char_perLine[1] = $L_char_perLine[0]
            $L_char_perLine[0] = 1
    EndSelect
   
   ;;Calculating the lable width...and Lable hight..
    Select
        Case $L_char_perLine[0] = 1
            $L_lable_hight = $L_char_hight
            $L_lable_width = ($L_char_perLine[1] * $L_char_width)
        Case $L_char_perLine[0] > 1
            $L_temp = $L_char_perLine[1]
            For $L_a = 2 To $L_char_perLine[0]
                If $L_temp < $L_char_perLine[$L_a] Then
                    $L_temp = $L_char_perLine[$L_a]
                EndIf
            Next
           ;setting the width
            $L_lable_width = ($L_temp * $L_char_width)
           ;setting the hight
            $L_lable_hight = ($L_char_hight * $L_char_perLine[0])
    EndSelect
   ;;Calculating the GUI width...
    Select
        Case $P_flag = 0; The OK button and the LABLE
            $L_GUI_Width = $L_lable_width + 30
            $L_GUI_hight = $L_lable_hight + 85
           
        Case $P_flag = 4 ; TWO BUTTONS and the LABLE
            $L_GUI_hight = $L_lable_hight + 85
            $L_GUI_Width = $L_lable_width + 30
           
        Case $P_flag = 10; TWO BUTTONS , INPUT and the LABLE
            $L_GUI_Width = $L_lable_width + 30
            $L_GUI_hight = $L_lable_hight + 85 + 30
    EndSelect
   
   ;;Calculating buffer space between yes and no buttons
    $L_first_button_left = (($L_GUI_Width / 4) - ($L_button_width / 2)) + ($L_GUI_Width / 10)
    If $L_first_button_left < 5 Then
        $L_first_button_left = 5
    EndIf
   
    $L_second_button_left = ((($L_GUI_Width / 4) * 3) - ($L_button_width / 2)) - ($L_GUI_Width / 10)
    If ($L_second_button_left) < ($L_first_button_left + $L_button_width + 4) Then
        $L_second_button_left = ($L_first_button_left + $L_button_width + 4)
    EndIf
   
    If ($L_second_button_left - $L_first_button_left) > 150 Then
        $L_buf_adjus = ($L_second_button_left - $L_first_button_left) / 4
        $L_first_button_left = $L_first_button_left + $L_buf_adjus
        $L_second_button_left = $L_second_button_left - $L_buf_adjus
    EndIf
   
    If $L_second_button_left + $L_button_width + 5 > $L_GUI_Width Then
        $L_GUI_Width = $L_second_button_left + $L_button_width + 10
    EndIf
   
    $L_get_win_pos = WinGetPos($P_parent)
    $L_MSG_GUI = GUICreate($P_title, $L_GUI_Width, $L_GUI_hight , ($L_get_win_pos[0] + ($L_get_win_pos[2] / 2)) - ($L_GUI_Width / 2) , ($L_get_win_pos[1] + ($L_get_win_pos[3] / 2)) - ($L_GUI_hight / 2), 0x00000001, -1, $P_parent)
    $L_MSG_lable = GUICtrlCreateLabel($P_Text, 10, 10, $L_lable_width + 10, $L_lable_hight)
   ;GUICtrlSetBkColor( -1 , 0x00ff00 )
    Select
        Case $P_flag = 0
            $L_MSG_GOOD = GUICtrlCreateButton( "  OK   " , (($L_GUI_Width / 2)) - ($L_button_width / 2) , ($L_GUI_hight - 30) - ($L_button_hight + 10), $L_button_width, $L_button_hight)
        Case $P_flag = 4
            $L_MSG_GOOD = GUICtrlCreateButton( "  Yes   ", $L_first_button_left , ($L_GUI_hight - 30) - ($L_button_hight + 10), $L_button_width, $L_button_hight)
            $L_MSG_BAD = GUICtrlCreateButton( "  No   ", $L_second_button_left , ($L_GUI_hight - 30) - ($L_button_hight + 10), $L_button_width, $L_button_hight)
        Case $P_flag = 10
            $L_MSG_GOOD = GUICtrlCreateButton( "  OK   ", $L_first_button_left, ($L_GUI_hight - 30) - ($L_button_hight + 10), $L_button_width, $L_button_hight)
            $L_MSG_BAD = GUICtrlCreateButton( "  Cancel   ", $L_second_button_left , ($L_GUI_hight - 30) - ($L_button_hight + 10), $L_button_width, $L_button_hight)
    EndSelect
    If $P_flag = 10 Then
        If $L_GUI_Width > 400 Then
            $L_input_Width = 340
        Else
            $L_input_Width = $L_GUI_Width - 50
        EndIf
       
        $L_input = GUICtrlCreateInput("" , (($L_GUI_Width / 2) - ($L_input_Width / 2)) , ($L_GUI_hight - ($L_button_hight + 10 + 60)), $L_input_Width, 20)
    EndIf
   
    GUISetState(@SW_SHOW, $L_MSG_GUI)
    If $P_timeOut <> 0 Then
        $L_temp_time = TimerInit()
    EndIf
    While 1
        If $P_timeOut <> 0 Then
            If (TimerDiff($L_temp_time) = $P_timeOut) or (TimerDiff($L_temp_time) > $P_timeOut) Then
                GUIDelete($L_MSG_GUI)
                If $P_dis = 2 Then
                    GUISetState(@SW_SHOW, $P_parent)
                    GUISetState(@SW_ENABLE, $P_parent)
                ElseIf $P_dis = 1 Then
                    GUISetState(@SW_ENABLE, $P_parent)
                EndIf
                Opt("GUIOnEventMode", $L_mode_backup)
                GUISetState(@SW_RESTORE, $P_parent)
                Return -1
            EndIf
        EndIf
       
        $L_MSG_MSG = GUIGetMsg(1)
        Select
            Case ($L_MSG_MSG[0] = $L_MSG_GOOD) And ($L_MSG_MSG[1] == $L_MSG_GUI) And ($P_flag <> 10)
                GUIDelete($L_MSG_GUI)
                If $P_dis = 2 Then
                    GUISetState(@SW_SHOW, $P_parent)
                    GUISetState(@SW_ENABLE, $P_parent)
                ElseIf $P_dis = 1 Then
                    GUISetState(@SW_ENABLE, $P_parent)
                EndIf
                Opt("GUIOnEventMode", $L_mode_backup)
                GUISetState(@SW_RESTORE, $P_parent)
                If $P_flag = 0 Then Return 0
                If $P_flag = 4 Then Return 6
               
            Case ($L_MSG_MSG[0] = $L_MSG_BAD) And ($L_MSG_MSG[1] == $L_MSG_GUI) And ($P_flag <> 0)
                GUIDelete($L_MSG_GUI)
                If $P_dis = 2 Then
                    GUISetState(@SW_SHOW, $P_parent)
                    GUISetState(@SW_ENABLE, $P_parent)
                ElseIf $P_dis = 1 Then
                    GUISetState(@SW_ENABLE, $P_parent)
                EndIf
                Opt("GUIOnEventMode", $L_mode_backup)
                GUISetState(@SW_RESTORE, $P_parent)
                SetError(1)
                Return 7
               
            Case ($L_MSG_MSG[0] = $L_MSG_GOOD) And ($L_MSG_MSG[1] == $L_MSG_GUI) And ($P_flag = 10)
                $L_temp_read = GUICtrlRead($L_input)
                GUIDelete($L_MSG_GUI)
                If $P_dis = 2 Then
                    GUISetState(@SW_SHOW, $P_parent)
                    GUISetState(@SW_ENABLE, $P_parent)
                ElseIf $P_dis = 1 Then
                    GUISetState(@SW_ENABLE, $P_parent)
                EndIf
                Opt("GUIOnEventMode", $L_mode_backup)
                GUISetState(@SW_RESTORE, $P_parent)
                Return $L_temp_read
        EndSelect
    WEnd
    GUISetState(@SW_ENABLE, $P_parent)
    GUISetState(@SW_RESTORE, $P_parent)
    Opt("GUIOnEventMode", $L_mode_backup)
EndFunc

Or is that exactly what you recommend?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Try this, i use it in many of my scripts...

#Include <GuiConstants.au3>

$Title = "My Custom MsgBox"
$Promt = "Are you sure?"
$CheckBoxText = "Don't show again"

$hWnd = WinGetHandle("")

$Ask = _GuiMsgBox(32, 2, $Title, $Promt, 330, 120, $CheckBoxText, 10, $hWnd, "OK", "Cancel")

$CheckBitAnd = BitAND($Ask, 8)

$Var = "Pressed "
Select
    Case $Ask - $CheckBitAnd = 1
        $Var &= "'OK'"
    Case $Ask - $CheckBitAnd = 6
        $Var &= "'Yes' or 'OK'"
    Case $Ask - $CheckBitAnd = 7
        $Var &= "'No' or 'Cancel'"
EndSelect

If $CheckBitAnd = 8 Then $Var &= @LF & "And CheckBox <" & $CheckBoxText & "> was Checked"

MsgBox(64, "Message", "Returned values:" & @LF & @LF & $Var)

Func _GuiMsgBox($IcoType,$Butt_Num,$Title,$Text,$Width,$Height,$CB_Text=-1,$Timer=-1,$hWnd=0,$B1Text=-1,$B2Text=-1,$ExStyle=-1)
    Local $Yes, $No, $OK, $CheckBox=-1, $Gui_MsgBox, $GuiHeight = $Height
    Local $TitleType = $WS_CAPTION+$WS_POPUP, $Gui_Msg, $ReturnVal = 0
    Local $DefButton = $OK, $DefButtonText = $B1Text, $Counter
    
    Switch $IcoType
        Case 16
            $IcoType = 103
        Case 32
            $IcoType = 102
        Case 48
            $IcoType = 101
        Case 64
            $IcoType = 104
        Case Else
            $IcoType = 102
    EndSwitch
    
    Local $Old_Opt_GOEM = Opt('GuiOnEventMode', 0)
    Local $Old_Opt_GCOE = Opt('GUICloseOnESC', 0)
    
    If $hWnd <> 0 Then WinSetState($hWnd, "", @SW_DISABLE)
    If $Butt_Num = 1 Then $TitleType += $WS_SYSMENU
    If $CB_Text <> -1 Then $GuiHeight += 25
    
    If $B1Text = -1 Then $B1Text = 'OK'
    If $B2Text = -1 Then $B2Text = 'Cancel'
    
    $Gui_MsgBox = GuiCreate($Title, $Width, $GuiHeight, -1, -1, $TitleType, $ExStyle, $hWnd)
    
    GUICtrlCreateIcon('user32.dll', $IcoType, 10, 10)
    GUICtrlCreateLabel($Text, 70, 15, $Width-80, $Height-50)
    
    Select
        Case $Butt_Num = 2
            $Yes = GUICtrlCreateButton($B1Text, ($Width/2)-90, $Height-35, 70, 20)
            $DefButton = $Yes
            
            $No = GUICtrlCreateButton($B2Text, ($Width/2)+20, $Height-35, 70, 20)
            
            GUICtrlSetState($No, $GUI_ONTOP)
            GUICtrlSetState($Yes, $GUI_ONTOP+$GUI_DEFBUTTON)
        Case Else
            $OK = GUICtrlCreateButton($B1Text, ($Width-70)/2, $Height-35, 70, 20)
            GUICtrlSetState($OK, $GUI_DEFBUTTON+$GUI_ONTOP)
            $DefButton = $OK
    EndSelect
    
    If $CB_Text <> -1 Then $CheckBox = GUICtrlCreateCheckbox($CB_Text, 15, $Height-10)
    GuiSetState(@SW_SHOW, $Gui_MsgBox)
    
    If $Timer > 0 Then
        $Counter = $Timer
        $Timer = TimerInit()
        $DefButtonText = GUICtrlRead($DefButton)
        GUICtrlSetData($DefButton, $DefButtonText & ' (' & $Counter & ')')
    EndIf
    
    While 1
        $Gui_Msg = GUIGetMsg()
        
        If $Timer > 0 And TimerDiff($Timer) >= 1000 Then
            $Timer = TimerInit()
            $Counter -= 1
            GUICtrlSetData($DefButton, $DefButtonText & ' (' & $Counter & ')')
            If $Counter < 0 Then $Gui_Msg = $DefButton
        EndIf
        
        Select
            Case $Butt_Num = 2 And $Gui_Msg = $Yes
                $ReturnVal = 6
                ExitLoop
            Case $Butt_Num = 2 And $Gui_Msg = $No
                $ReturnVal = 7
                ExitLoop
            Case $Gui_Msg = -3 Or ($Gui_Msg = $OK And $Butt_Num <> 2)
                $ReturnVal = 1
                ExitLoop
        EndSelect
    Wend
    
    If GUICtrlRead($CheckBox) = 1 Then $ReturnVal += 8
    
    If $hWnd <> 0 Then WinSetState($hWnd, "", @SW_ENABLE)
    GUIDelete($Gui_MsgBox)
    Opt('GuiOnEventMode', $Old_Opt_GOEM)
    Opt('GUICloseOnESC', $Old_Opt_GCOE)
    Return $ReturnVal
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Try this, i use it in many of my scripts...

PERFECT!!!


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Try this, i use it in many of my scripts...

THANK YOU! <_<

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  
Followers 0