Jump to content

Extended Message Box - New Version: 16 Feb 24


Melba23
 Share

Recommended Posts

  • Moderators

MKANET,

I'm curious if there is a way to use more than one font in the same message box

No, the UDF uses the same user-defined (or default if nothing is defined) font throughout - unless you set the $iStyle parameter in ExtMsgBoxSet to 4 in which case the buttons use the default font rather than the user-defined one. This enables you to have large fonts in the body of the ExtMsgBox and still have readable text in the buttons. ;)

You might also like to look at the post I have made in your other thread about fonts in ExtMsgBoxes. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 3 weeks later...

Melba,

Thank You for this, I was tired of the boring grey boxes! I have a question I am new to AutoIT and was wondering two things:

1.) Can you can the button bkcolor and font color in the extmsgbox I know you can change the colors in the guictrlcreatebutton.

2.)Also can you change the font color of msg Title, basically want to make the title Red.

Either Way thank you so much for this, keep up the amazing work!!! :D

Link to comment
Share on other sites

  • Moderators

morrison0586,

Glad you like it. :D

Unfortunately the answer to both your questions is: No!

1. - There is a bug deep in the AutoIt core code which means that colouring buttons brings all sorts of unpleasant side effects - so I am not going there. :)

2. - The colour of the title bar is set by the system - if you change it for the ExtMsgBox you change it for every other GUI, which is probably not what you want. :D

Sorry not to be more helpful - perhaps next time I can do something with your suggestions. :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 weeks later...

Hello, I'm back. :D

I used the old version of this awesome UDF and I made it to work with multiple monitors (I tested with 2). I updated to the newest version a couple of days ago and made the multi monitor changes again (28 Feb 12).

ExtMsgBox.au3

Edited by leomoon
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...
  • 1 month later...
  • 3 months later...
  • Moderators

[NEW VERSION] 30 May 13

Added: Three new user-defined options:

- 1. If the button text is set to " " (a single space) no buttons will be shown. If this option is chosen then the UDF sets an automatic timeout of 5 secs, unless the user has already set another timeout value.

- 2. Just to add to the "no button" option, you can now choose to disable the closure [X] and SysMenu "Close" command. So just add 64 to the $iStyle parameter in _ExtMsgBoxSet and the user has to wait for the EMB to time out!

- 3. Finally, I was asked if there could be an option to remove the icon from the titlebar. What I have done is to use the transparent icon from the normal AutoIt set when you add 32 to the _ExtMsgBoxSet $iStyle parameter. This gives a similar visual appearance and the SysMenu is still available on rightclick.

Changed: As guinness now insists (quite correctly) that we use the proper $MB_ICON* parameter when coding, I have decided to rename the UDF constants which determine the icon to use to prevent confusion. If you used them then this is a scriptbreaking change - but as the name has only changed to $EMB_ICON* it should not be too hard to amend your scripts. ;)

I hope you feel these new additions are useful. New UDF and examples below and in the zip. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...

Just tried this UDF - loving it!

Quick question/possible bug though...

I am a keyboard ninja and I hate mice.  So, when I have a dialog pop up and I press tab + spacebar, it returns the default button (in this case, the "No" button) regardless of which one has been selected.  When I do the same behavior with the enter key instead, it works fine.  Any idea what's going on here?

Thanks,

Overkill

Link to comment
Share on other sites

  • Moderators

Overkill,

 

Any idea what's going on here?

What is supposed to happen! :D

The UDF is set up as follows:

 

- Using a mouse will obviously fire the button under the mouse

- Pressing {ENTER} will fire the currently focused button

- Pressing {SPACE} will fire the default button (the one with a leading "&" added to its text). If there is no default button then pressing {SPACE} results in no button firing

It has been that way since I released the first version of the UDF several years ago. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 weeks later...

Just a quick suggestion for a change you might be interested in, making the maximum width user changeable by allowing the programmer to pass the function a new parameter.

; Function parameter added $EMBMaxWidth, default set to 370

Func _ExtMsgBox($vIcon, $vButton, $sTitle, $sText, $iTimeout = 0, $hWin = "", $iVPos = 0, $EMBMaxWidth = 370)

; changes to the following line
Local $iMsg_Width_max = $EMBMaxWidth, $iMsg_Width_min = 150, $iMsg_Width_abs = $iMsg_Width_max + 130
; add parameter check to insure that the maximum width will fit on the screen
If $iMsg_Width_max > @DesktopWidth - 50 Then $iMsg_Width_max = @DesktopWidth - 50 ; won't be larger than the desktop size

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

BrewManNH,

Funny you should post that - I am just working on the UDF as a result of this thread and that was the logical next step in the chain! :D

However, I was thinking of adding the parameter to the _ExtMsgBox_Set function. I will see how things turn out. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That would add a dreaded global to the function, can't have too many of those. :D

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That would add a dreaded global to the function, can't have too many of those. :D

Well there are other alternatives.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Hi,

I have developed a Beta version of the UDF with 2 new features:

 

- 1. The user can set the normal and absolute maximum widths of the EMB using 2 new parameters in _ExtMsgBoxSet. These values are used as follows:

- Normal max: The size to which an EMB will expand before the text need to wrap. Default and minimum of 370 pixels.

- Absolute max: If there is an unbroken character string (such as a path) longer than the normal max width, the EMB will try to expand in 10 pixel increments up to this value (default and minimum of 500 pixels) to try and accommodate the string. If the string will still not fit, the EMB returns an error and does not display.

- 2. The buttons will try to expand to accommodate the text required. All buttons are the same size and there is obviously a limit to the number of buttons that will fit into an EMB of a given width - increasing the width of the EMB as described above allows wider buttons with more text. Remember that you can use a larger font in the EMB body and still keep the default text for the buttons - this can also help if you require longer button text. However, if the button text is too long to fit in even the largest available button size, then the EMB returns an error and does not display.

Here is the Beta UDF and a short example script to show it working: <removed Beta code>

Comments welcome. :)

M23

P.S. And I added 2 more Global variables - but will anyone notice? ;)

Edited by Melba23
Removed Beta code

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

[NEW VERSION] 11 Aug 13

Added:

 

- 1. Buttons will now expand to fit the text within them as long as they will still fit within the EMB. Note that all buttons will be set to the same width, so a single long text will expand all buttons.

- 2. The user can now determine the max and absolute size of the EMB. The max size determines how far the EMB will expand to accommodate lines of text without wrapping - it also determines the max size for the buttons (see above). The absolute size is there to cater for very long unbroken strings (such as a path) which might be wider than the set max width - the EMB will expand incrementally to this value in an attempt to fit the string.

Thanks to jdicerch and BreManNH who asked for the changes. :thumbsup:

New UDF and Example 3 in first post. :)

M23

Edited by Melba23
Fixed tags

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...
  • Moderators

AlexVong,

If you set the $iWidth & $iWidth_Abs parameters in _ExtMsgBoxSet then you can expand the ExtMsgBox as far as your display will allow. If your text still wraps then there is not a lot else that you can do. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 months later...

Thanks a lot for sharing this. Also for me it will be used well. I´ve initially come across this looking for a way to apply the _MouseTrap() UDF function to a MessageBox - which I suppose is not possible with standard windows MsgBox´s, as with these there is no opportunity between creation and dissapearance to fetch the coordinates and apply _MouseTrap(ping)... ...unless using two scripts...

So anyway, could I perhaps ask for advice on this?

Would I modify the UDF for myself to WinGetPos right after the GUICreate, and then activate the MouseTrap?

Has anybody else done something similar before already?

So that the user can even move/drag the ExtMsgBox window around the screen - just not click anything outside it accidentally?

Edit: to elaborate just a little more:

the app I would like to use your UDF for uses lots of ControlSend (just to a Window, because that window has very "funny" controls), and so that window needs to be kept active and the mouse and keyboard need to be disabled while it is working, otherwise unwanted things would happen if something is pressed/clicked/activated.

During the process there are two or three querys for the user, where Option A or B or C is to selected. (the Timeout countdown thing in your UDF is wonderfull btw!).

I would like the user to be able to select an option, or to abort the script, at this point - but not do anything else that would disrupt something.

Therefore now the intention to somehow combine your ExtMsgBox with BlockInputEx and MouseTrap...

ReEdit: thinking through the question helped get me get an answer myself. Here´s how I customised it:

Func _ExtMsgBox($vIcon, $vButton, $sTitle, $sText, $iTimeOut = 0, $hWin = "", $iVPos = 0, $bMouseTrapToWin = FALSE)

    If $bMouseTrapToWin Then
        #include-once
        #include <Misc.au3>; for MouseTrap
    EndIf

    ; Set default sizes for message box
    Local $iMsg_Width_Max = $g_aEMB_Settings[6], $iMsg_Width_Min = 150, $iMsg_Width_Abs = $g_aEMB_Settings[7]
    Local $iMsg_Height_Min = 100
    Local $iButton_Width_Def = 80, $iButton_Width_Min = 50

    ; Declare local variables
    Local $iParent_Win = 0, $fCountdown = False, $cCheckbox, $aLabel_Size, $aRet, $iRet_Value, $iHpos
    Local $sButton_Text, $iButton_Width_Req, $iButton_Width, $iButton_Xpos

    ; Validate timeout value
    $iTimeOut = Int(Number($iTimeOut))
    ; Set automatic timeout if no buttons and no timeout set
    If $vButton == " " And $iTimeOut = 0 Then
        $iTimeOut = 5
    EndIf

    ; Check for icon
    Local $iIcon_Style = 0
    Local $iIcon_Reduction = 50
    Local $sDLL = "user32.dll"
    If StringIsDigit($vIcon) Then
        Switch $vIcon
            Case 0
                $iIcon_Reduction = 0
            Case 8
                $sDLL = "imageres.dll"
                $iIcon_Style = 78
            Case 16 ; Stop
                $iIcon_Style = -4
            Case 32 ; Query
                $iIcon_Style = -3
            Case 48 ; Exclam
                $iIcon_Style = -2
            Case 64 ; Info
                $iIcon_Style = -5
            Case 128 ; Countdown
                If $iTimeOut > 0 Then
                    $fCountdown = True
                Else
                    ContinueCase
                EndIf
            Case Else
                Return SetError(1, 0, -1)
        EndSwitch
    Else
        $sDLL = $vIcon
        $iIcon_Style = 0
    EndIf

    ; Check if two buttons are seeking focus
    StringRegExpReplace($vButton, "((?<!&)&)(?!&)", "*")
    If @extended > 1 Then
        Return SetError(2, 0, -1)
    EndIf

    ; Check if using constants or text
    If IsNumber($vButton) Then
        Switch $vButton
            Case 0
                $vButton = "OK"
            Case 1
                $vButton = "&OK|Cancel"
            Case 2
                $vButton = "&Abort|Retry|Ignore"
            Case 3
                $vButton = "&Yes|No|Cancel"
            Case 4
                $vButton = "&Yes|No"
            Case 5
                $vButton = "&Retry|Cancel"
            Case 6
                $vButton = "&Cancel|Try Again|Continue"
            Case Else
                Return SetError(3, 0, -1)
        EndSwitch
    EndIf

    ; Get required button size
    If $vButton <> " " Then
        ; Split button text into individual strings
        Local $aButton_Text = StringSplit($vButton, "|")
        ; Get absolute available width for each button
        Local $iButton_Width_Abs = Floor((($iMsg_Width_Max - 10) / $aButton_Text[0]) - 10)
        ; Error if below min button size
        If $iButton_Width_Abs < $iButton_Width_Min Then
            Return SetError(4, 0, -1)
        EndIf
        ; Determine required size of buttons to fit text
        Local $iButton_Width_Text = 0
        ; Loop through button text
        For $i = 1 To $aButton_Text[0]
            ; Remove a possible leading &
            $sButton_Text = StringRegExpReplace($aButton_Text[$i], "^&?(.*)$", "$1")
            ; Check on font to use
            If BitAND($g_aEMB_Settings[0], 4) Then
                $aRet = _StringSize($sButton_Text, $g_aEMB_Settings[10], Default, Default, $g_aEMB_Settings[11])
            Else
                $aRet = _StringSize($sButton_Text, $g_aEMB_Settings[4], Default, Default, $g_aEMB_Settings[5])
            EndIf
            If IsArray($aRet) And $aRet[2] + 10 > $iButton_Width_Text Then
                ; Find max button width required for text
                $iButton_Width_Text = $aRet[2] + 10
            EndIf
        Next
        ; Error if text would make required button width > absolute available
        If $iButton_Width_Text > $iButton_Width_Abs Then
            Return SetError(5, 0, -1)
        EndIf
        ; Determine button size to use - assume default
        $iButton_Width = $iButton_Width_Def
        ; If text requires wider then default
        If $iButton_Width_Text > $iButton_Width_Def Then
            ; Increase - cannot be > absolute
            $iButton_Width = $iButton_Width_Text
        EndIf
        ; If absolute < default
        If $iButton_Width_Abs < $iButton_Width_Def Then
            ; If text > min (text must be < abs)
            If $iButton_Width_Text > $iButton_Width_Min Then
                ; Set text width
                $iButton_Width = $iButton_Width_Text
            Else
                ; Set min width
                $iButton_Width = $iButton_Width_Min
            EndIf
        EndIf
        ; Determine GUI width required for all buttons at this width
        $iButton_Width_Req = (($iButton_Width + 10) * $aButton_Text[0]) + 10
    Else
        $iButton_Width_Req = 0
    EndIf

    ; Set tab expansion flag if required
    Local $iExpTab = Default
    If BitAND($g_aEMB_Settings[0], 8) Then
        $iExpTab = 1
    EndIf

    ; Get message label size
    While 1
        Local $aLabel_Pos = _StringSize($sText, $g_aEMB_Settings[4], Default, $iExpTab, $g_aEMB_Settings[5], $iMsg_Width_Max - 20 - $iIcon_Reduction)
        If @error Then
            If $iMsg_Width_Max >= $iMsg_Width_Abs Then
                Return SetError(6, 0, -1)
            Else
                $iMsg_Width_Max += 10
            EndIf
        Else
            ExitLoop
        EndIf
    WEnd
    ; Reset text to wrapped version
    $sText = $aLabel_Pos[0]
    ; Set label size
    Local $iLabel_Width = $aLabel_Pos[2]
    Local $iLabel_Height = $aLabel_Pos[3]

    ; Set GUI size
    Local $iMsg_Width = $iLabel_Width + 20 + $iIcon_Reduction
    ; Increase width to fit buttons if needed
    If $iButton_Width_Req > $iMsg_Width Then $iMsg_Width = $iButton_Width_Req
    If $iMsg_Width < $iMsg_Width_Min Then
        $iMsg_Width = $iMsg_Width_Min
        $iLabel_Width = $iMsg_Width_Min - 20
    EndIf
    Local $iMsg_Height = $iLabel_Height + 35
    ; Increase height if buttons present
    If $vButton <> " " Then
        $iMsg_Height += 30
    EndIf
    ; Increase height if checkbox required
    If BitAND($g_aEMB_Settings[0], 16) Then
        $iMsg_Height += 40
    EndIf
    If $iMsg_Height < $iMsg_Height_Min Then $iMsg_Height = $iMsg_Height_Min

    ; If only single line, lower label to to centre text on icon
    Local $iLabel_Vert = 20
    If StringInStr($sText, @CRLF) = 0 Then $iLabel_Vert = 27

    ; Check for taskbar button style required
    If Mod($g_aEMB_Settings[0], 2) = 1 Then ; Hide taskbar button so create as child
        If IsHWnd($hWin) Then
            $iParent_Win = $hWin ; Make child of that window
        Else
            $iParent_Win = WinGetHandle(AutoItWinGetTitle()) ; Make child of AutoIt window
        EndIf
    EndIf

    ; Determine EMB location
    If $hWin = "" Then
        ; No handle or position passed so centre on screen
        $iHpos = (@DesktopWidth - $iMsg_Width) / 2
        $iVPos = (@DesktopHeight - $iMsg_Height) / 2
    Else
        If IsHWnd($hWin) Then
            ; Get parent GUI pos if visible
            If BitAND(WinGetState($hWin), 2) Then
                ; Set EMB to centre on parent
                Local $aPos = WinGetPos($hWin)
                $iHpos = ($aPos[2] - $iMsg_Width) / 2 + $aPos[0] - 3
                $iVPos = ($aPos[3] - $iMsg_Height) / 2 + $aPos[1] - 20
            Else
                ; Set EMB to centre om screen
                $iHpos = (@DesktopWidth - $iMsg_Width) / 2
                $iVPos = (@DesktopHeight - $iMsg_Height) / 2
            EndIf
        Else
            ; Assume parameter is horizontal coord
            $iHpos = $hWin ; $iVpos already set
        EndIf
    EndIf

    ; Now check to make sure GUI is visible on screen
    ; First horizontally
    If $iHpos < 10 Then $iHpos = 10
    If $iHpos + $iMsg_Width > @DesktopWidth - 20 Then $iHpos = @DesktopWidth - 20 - $iMsg_Width
    ; Then vertically
    If $iVPos < 10 Then $iVPos = 10
    If $iVPos + $iMsg_Height > @DesktopHeight - 60 Then $iVPos = @DesktopHeight - 60 - $iMsg_Height

    ; Remove TOPMOST extended style if required
    Local $iExtStyle = 0x00000008 ; $WS_TOPMOST
    If BitAND($g_aEMB_Settings[0], 2) Then $iExtStyle = -1

    ; Create GUI with $WS_POPUPWINDOW, $WS_CAPTION style and required extended style
    Local $hMsgGUI = GUICreate($sTitle, $iMsg_Width, $iMsg_Height, $iHpos, $iVPos, BitOR(0x80880000, 0x00C00000), $iExtStyle, $iParent_Win)
    If @error Then
        Return SetError(7, 0, -1)
    EndIf

    ; Check if titlebar icon hidden - actually uses transparent icon from AutoIt executable
    If BitAND($g_aEMB_Settings[0], 32) Then
        If @Compiled Then
            GUISetIcon(@ScriptName, -2, $hMsgGUI)
        Else
            GUISetIcon(@AutoItExe, -2, $hMsgGUI)
        EndIf
    EndIf
    If $g_aEMB_Settings[2] <> Default Then GUISetBkColor($g_aEMB_Settings[2])

    ; Check if user closure permitted
    If BitAND($g_aEMB_Settings[0], 64) Then
        $aRet = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $hMsgGUI, "int", 0)
        Local $hSysMenu = $aRet[0]
        DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", 0xF060, "int", 0) ; $SC_CLOSE
        DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hMsgGUI)
    EndIf

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($g_aEMB_Settings[1], 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($g_aEMB_Settings[1], 2) = 2 Then
        $iLabel_Style = 2 ; $SS_RIGHT
    EndIf

    ; Create label
    GUICtrlCreateLabel($sText, 10 + $iIcon_Reduction, $iLabel_Vert, $iLabel_Width, $iLabel_Height, $iLabel_Style)
    GUICtrlSetFont(-1, $g_aEMB_Settings[4], Default, Default, $g_aEMB_Settings[5])
    If $g_aEMB_Settings[3] <> Default Then GUICtrlSetColor(-1, $g_aEMB_Settings[3])

    ; Create checkbox if required
    If BitAND($g_aEMB_Settings[0], 16) Then
        Local $sAgain = " Do not show again"
        Local $iY = $iLabel_Vert + $iLabel_Height + 10
        ; Create checkbox
        $cCheckbox = GUICtrlCreateCheckbox("", 10 + $iIcon_Reduction, $iY, 20, 20)
        ; Write text in separate checkbox label
        Local $cCheckLabel = GUICtrlCreateLabel($sAgain, 20, 20, 20, 20)
        GUICtrlSetColor($cCheckLabel, $g_aEMB_Settings[3])
        GUICtrlSetBkColor($cCheckLabel, $g_aEMB_Settings[2])
        ; Set font if required and size checkbox label text
        If BitAND($g_aEMB_Settings[0], 4) Then
            $aLabel_Size = _StringSize($sAgain)
        Else
            $aLabel_Size = _StringSize($sAgain, $g_aEMB_Settings[4], 400, 0, $g_aEMB_Settings[5])
            GUICtrlSetFont($cCheckLabel, $g_aEMB_Settings[4], 400, 0, $g_aEMB_Settings[5])
        EndIf
        ; Move and resize checkbox label to fit
        $iY = ($iY + 10) - ($aLabel_Size[3] - 4) / 2
        ControlMove($hMsgGUI, "", $cCheckLabel, 30 + $iIcon_Reduction, $iY, $iMsg_Width - (30 + $iIcon_Reduction), $aLabel_Size[3])
    EndIf

    ; Create icon or countdown timer
    If $fCountdown = True Then
        Local $cCountdown_Label = GUICtrlCreateLabel(StringFormat("%2s", $iTimeOut), 10, 20, 32, 32)
        GUICtrlSetFont(-1, 18, Default, Default, $g_aEMB_Settings[5])
        GUICtrlSetColor(-1, $g_aEMB_Settings[3])
    Else
        If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 20)
    EndIf

    ; Create buttons
    Local $cAccel_Key = 9999 ; Placeholder to prevent firing if no buttons
    If $vButton <> " " Then

        ; Create dummy control for Accel key
        $cAccel_Key = GUICtrlCreateDummy()
        ; Set Space key as Accel key
        Local $aAccel_Key[1][2] = [["{SPACE}", $cAccel_Key]]
        GUISetAccelerators($aAccel_Key)

        ; Calculate button horizontal start
        If $aButton_Text[0] = 1 Then
            If BitAND($g_aEMB_Settings[1], 4) = 4 Then
                ; Single centred button
                $iButton_Xpos = ($iMsg_Width - $iButton_Width) / 2
            Else
                ; Single offset button
                $iButton_Xpos = $iMsg_Width - $iButton_Width - 10
            EndIf
        Else
            ; Multiple centred buttons
            $iButton_Xpos = ($iMsg_Width - ($iButton_Width_Req - 20)) / 2
        EndIf
        ; Set default button code
        Local $iDefButton_Code = 0
        ; Set default button style
        Local $iDef_Button_Style = 0
        ; Work through button list
        For $i = 0 To $aButton_Text[0] - 1
            Local $iButton_Text = $aButton_Text[$i + 1]
            ; Set default button
            If $aButton_Text[0] = 1 Then ; Only 1 button
                $iDef_Button_Style = 0x0001
            ElseIf StringLeft($iButton_Text, 1) = "&" Then ; Look for &
                $iDef_Button_Style = 0x0001
                $aButton_Text[$i + 1] = StringTrimLeft($iButton_Text, 1)
                ; Set default button code for Accel key return
                $iDefButton_Code = $i + 1
            EndIf
            ; Draw button
            GUICtrlCreateButton($aButton_Text[$i + 1], $iButton_Xpos + ($i * ($iButton_Width + 10)), $iMsg_Height - 35, $iButton_Width, 25, $iDef_Button_Style)
            ; Set font if required
            If Not BitAND($g_aEMB_Settings[0], 4) Then GUICtrlSetFont(-1, $g_aEMB_Settings[4], 400, 0, $g_aEMB_Settings[5])
            ; Reset default style parameter
            $iDef_Button_Style = 0
        Next
    EndIf

    If $bMouseTrapToWin Then
    $aWinPos = WinGetPos($hMsgGUI)
    _MouseTrap($aWinPos[0],$aWinPos[1],$aWinPos[0]+$aWinPos[2],$aWinPos[1]+$aWinPos[3])
    EndIf

    ; Show GUI
    GUISetState(@SW_SHOW, $hMsgGUI)

    ; Begin timeout counter
    Local $iTimeout_Begin = TimerInit()
    Local $iCounter = 0

    ; Declare GUIGetMsg return array here and not in loop
    Local $aMsg

    ; Set MessageLoop mode
    Local $iOrgMode = Opt('GUIOnEventMode', 0)

    While 1
        $aMsg = GUIGetMsg(1)

        If $aMsg[1] = $hMsgGUI Then
            Select
                Case $aMsg[0] = -3 ; $GUI_EVENT_CLOSE
                    $iRet_Value = 0
                    ExitLoop
                Case $aMsg[0] = $cAccel_Key
                    ; Accel key pressed so return default button code
                    If $iDefButton_Code Then
                        $iRet_Value = $iDefButton_Code
                        ExitLoop
                    EndIf
                Case $aMsg[0] > $cAccel_Key
                    ; Button handle minus Accel key handle will give button index
                    $iRet_Value = $aMsg[0] - $cAccel_Key
                    ExitLoop
            EndSelect
        EndIf

        ; Timeout if required
        If TimerDiff($iTimeout_Begin) / 1000 >= $iTimeOut And $iTimeOut > 0 Then
            $iRet_Value = 9
            ExitLoop
        EndIf

        ; Show countdown if required
        If $fCountdown = True Then
            Local $iTimeRun = Int(TimerDiff($iTimeout_Begin) / 1000)
            If $iTimeRun <> $iCounter Then
                $iCounter = $iTimeRun
                GUICtrlSetData($cCountdown_Label, StringFormat("%2s", $iTimeOut - $iCounter))
            EndIf
        EndIf

        If $bMouseTrapToWin Then
        $aWinPos = WinGetPos($hMsgGUI)
        _MouseTrap($aWinPos[0],$aWinPos[1],$aWinPos[0]+$aWinPos[2],$aWinPos[1]+$aWinPos[3])
        EndIf
    WEnd

    ; Reset original mode
    Opt('GUIOnEventMode', $iOrgMode)

    If GUICtrlRead($cCheckbox) = 1 Then
        ; Negate the return value
        $iRet_Value *= -1
    EndIf

    GUIDelete($hMsgGUI)

    If $bMouseTrapToWin Then
    _MouseTrap()
    EndIf

    Return $iRet_Value

EndFunc   ;==>_ExtMsgBox

(this isn´t standalone code - it works when overwriting the _ExtMsgBox function in a copy of the UDF)

For me it even works if the ExtMsgBox is dragged around, since I tried "re-trapping" the mouse with every GUIGetMsg cycle, although this is maybe a performance factor. Now I guess I can do what I wanted like this, combined with unblocking (with BlockInputEx) mouse-movement and mouse-clicking before the user query, and reblocking that after.

If this is at all usefull to anybode then of course all credit still goes fully to Melba23. I´d be delighted if this optional parameter would even be integrated into the "official" UDF. Also of course I´m still open to hearing of a better way to do this.

Edited by guestscripter
Link to comment
Share on other sites

  • Melba23 changed the title to Extended Message Box - New Version: 16 Feb 24
  • Jon unfeatured this topic

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...