Moderators Melba23 Posted May 31, 2021 Author Moderators Posted May 31, 2021 JockoDundee, Adding a final "portemanteau" parameter to the function is never going to happen. Given the number of optional parameters that would need to be added to the calling line to arrive at this point, I do not see this as "simplifying" the operation for new users - and experienced ones such as yourself should be able to cope with the UDF as it is currently exists. I think the single "BitOR" parameter for the buttons (and icon) is as far as I am prepared to go. mike 1950r, For me there is no such difference in colouring between the standard MsgBox and an ExtMsgBox - I see a single unified background colour. Anyway, there are already several colour options in the UDF and I am not going to add any more. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mike1950r Posted May 31, 2021 Posted May 31, 2021 3 hours ago, Melba23 said: For me there is no such difference in colouring between the standard MsgBox and an ExtMsgBox Here are two screenshots, 1st of ext msgbox 2nd of the system msgbox, just to show the difference in the background. cheers mike
Moderators Melba23 Posted May 31, 2021 Author Moderators Posted May 31, 2021 mike1950r. I believed you - but that must be something in your system settings. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mike1950r Posted May 31, 2021 Posted May 31, 2021 Melba, was looking my settings. Nothing special, windows 7 64 bit, design windows classic. cheers mike
Moderators Melba23 Posted May 31, 2021 Author Moderators Posted May 31, 2021 (edited) mike1950r, Same here - must be a graphics card thing. Anyway, what you see is what you get with the UDF - I am not adding any further colour options, sorry. M23 P.S And I intend to move this whole thread to the main EMB thread soon, so do not be surprised if it apparently vanishes! Edited May 31, 2021 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JockoDundee Posted June 1, 2021 Posted June 1, 2021 9 hours ago, Melba23 said: Same here - must be a graphics card thing. But MsgBox on your computer is still whitish, no? Code hard, but don’t hard code...
matwachich Posted June 23, 2021 Posted June 23, 2021 Hi! Just a little feature suggestion: Because we can choose the text of the buttons, it would be nice to be able to stack the buttons vertically to fit some long text. Being able to set horizontal alignment is also nice. Thanks
Moderators Melba23 Posted June 24, 2021 Author Moderators Posted June 24, 2021 matwachich, Sorry, but no. The UDF is a replacement for the standard MsgBox with small(ish) button texts. But if you want vertically-stacked buttons, feel free to plunder the code of the UDF to write your own version. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
CarlD Posted September 26, 2021 Posted September 26, 2021 (edited) Eleven years in, let me add my high praise for this UDF -- and for the helpful and dignified way in which @Melba23 has presided over this thread for all that time! I've been aware of _ExtMsgBox for some years, but, regretfully, have not tried it until today. It's wonderful! I tried searching the thread for an answer to this question, but didn't find one -- so here goes. In the all of 7 hours that I've played with the UDF, I've found that text centers properly in the message box when $vIcon = 0 (no icon); but when I opt for one of the icons, the text seems to be pushed off-center, to the right, by the icon's pixel-width. It's easy to compensate for this by padding the message text with blank space, but I wonder if there's a more elegant solution or -- more likely -- if I'm missing something. Thanks in advance! Edited September 26, 2021 by CarlD
Moderators Melba23 Posted September 27, 2021 Author Moderators Posted September 27, 2021 (edited) CarlD, Glad you find the UDF useful. The text is indeed displaced to the right when an icon is used - just as in the standard MS MsgBox dialog. Here is a short script to show this: #include <MsgBoxConstants.au3> #include "ExtMsgBox.au3" MsgBox($MB_SYSTEMMODAL, "No icon", "Here is a bit of longish text to display!") MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "With icon", "Here is a bit of longish text to display!") _ExtMsgBox(0, "OK", "With icon", "Here is a bit of longish text to display!") _ExtMsgBox($MB_ICONINFORMATION, "OK", "With icon", "Here is a bit of longish text to display!") As you can see (I hope!) both the standard and UDF dialogs widen and shift the text to the right when there is an icon displayed. So if you really, really want the text to be absolutely centered in the dialog when an icon is used, you need to pad the text as you mention, although it will take a degree of experimentation in sizing the additional blank space to get it perfect. Personally i would just leave it as it is - MS seem happy to do so! M23 Edited September 27, 2021 by Melba23 Speeling! CarlD 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
CarlD Posted September 27, 2021 Posted September 27, 2021 11 hours ago, Melba23 said: both the standard and UDF dialogs widen and shift the text to the right when there is an icon displayed. Yes, I see that in your example, and thanks for confirming. I don't think I'd even notice the shift with left- or right-justified text, but with centered text it throws the balance off, to my eye. In any case it's a trifle, easily addressed (pad the text, or just ignore). Thanks again for a super UDF!
matwachich Posted November 5, 2021 Posted November 5, 2021 Just a little suggestion: Do not show again checkbox should not be part of the configuration, but a parameter of _ExtMsgBox (to set it on a per-msgbox basis, not globaly on the application) Cheers Note: I know it's big work... not really a request, just a suggestion
Moderators Melba23 Posted November 5, 2021 Author Moderators Posted November 5, 2021 matwachich, Thanks for the suggestion, but I will not be amending the code. You can very easily set/cancel the relevant parameter using _ExtMsgBoxSet before/after creating the ExtMsgBox which required the checkbox so I see no need to change the current method. Sorry about that. M23 matwachich 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Decibel Posted November 10, 2021 Posted November 10, 2021 (edited) I love this UDF, and your coding style and naming convention for variables. The _ExtMsgBox parameter of $bMain = True was the clincher for me. The countdown timer from $vIcon = 128 was the gravy. I made a tweak to it to allow for specifying a title bar icon file so that the _ExtMsgBox can match the parent window's icon. I had to do it in a manual sort of way because trying to get the icon out of the parent window was a bit much to do for running out of SciTE and running from a compiled exe. This did not require my exe to carry the ico file alongside it for distribution to other PCs. Overview of _ExtMsgBox changes: 1. Appended to the function comments, parameters section: ; $sTitlebarIconFile -> "" (default) = Use the generic AutoIt icon ; File path to the icon file to use 2. Appended the new optional parameter to the Func line: Func _ExtMsgBox($vIcon, $vButton, $sTitle, $sText, $iTimeOut = 0, $hWin = "", $iVPos = 0, $bMain = True, $sTitlebarIconFile = "") 3. Added this after the GUICreate line: If $sTitlebarIconFile <> "" And FileExists($sTitlebarIconFile) = True Then GUISetIcon($sTitlebarIconFile) ; will change icon EndIf Modified function in its entirety: expandcollapse popup; #FUNCTION# ========================================================================================================= ; Name...........: _ExtMsgBox ; Description ...: Generates user defined message boxes centred on a GUI, the desktop, or at defined coordinates ; Syntax.........: _ExtMsgBox ($vIcon, $vButton, $sTitle, $sText, [$iTimeout, [$hWin, [$iVPos, [$bMain = True]]]]) ; Parameters ....: $vIcon -> Icon to use: ; 0 - No icon ; 8 - UAC ; 16 - Stop ) ; 32 - Query ) or equivalent $MB/$EMB_ICON constant ; 48 - Exclamation ) ; 64 - Information ) ; 128 - Countdown digits if $iTimeout set ; Any other numeric value returns Error 1 ; If set to the name of an ico or exe file, the main icon within will be displayed ; If another icon from the file is required, add a trailing "|" followed by the icon index ; If set to the name of an image file, that image will be displayed ; $vButton -> Button text separated with "|" character. " " = no buttons. ; Putting a user-defined character (default = "~") before the text indicates button to be focused ; Two focused buttons returns Error 2. A single button is always focused ; Use of standard Windows keyboard shortcut by adding "&" before the button text is still available ; Note UDF focused button character must be placed first, e.g. "~&Yes|&No" ; Can also use $MB_ button numeric constants to define buttons: 0 = "OK", 1 = "~OK|Cancel", ; 2 = "~Abort|Retry|Ignore", 3 = "~Yes|No|Cancel", 4 = "~Yes|No", 5 = "~Retry|Cancel", ; 6 = "~Cancel|Try Again|Continue". Other values return Error 3 ; Default max width of 370 gives 1-4 buttons @ width 80, 5 @ width 60, 6 @ width 50 ; Min button width set at 50, so unless default widths changed 7 buttons will return Error 4 ; $sTitle -> The title of the message box. ; Procrustean truncation if too long to fit ; $sText -> The text to be displayed. Long lines will wrap. The box depth is adjusted to fit. ; If unbroken character strings in $sText too long for set max width, ; EMB expands to set absolute width. Error 6 if still not able to fit ; $iTimeout -> Timeout delay before EMB closes. 0 = no timeout (Default). ; If no buttons and no timeout set, timeout automatically set to 5 ; If timeout value negative, reset to 0 ; $hWin -> Handle of the GUI in which EMB is centred ; If GUI hidden or no handle passed - EMB centred in desktop (Default) ; If not valid window handle, interpreted as horizontal coordinate for EMB location ; $iVPos -> Vertical coordinate for EMB location ; Only valid if $hWin parameter interpreted as horizontal coordinate (Default = 0) ; $bMain -> True (default) = Adjust dialog position to ensure dialog positioned on main screen ; False = Dialog positioned at user-defined coords, which can be on other screens ; $sTitlebarIconFile -> "" (default) = Use the generic AutoIt icon ; File path to the icon file to use ; Requirement(s).: v3.2.12.1 or higher ; Return values .: Success: Returns 1-based index of the button pressed, counting from the LEFT. ; Returns 0 if closed by a "CloseGUI" event (i.e. click [X] or press Escape) ; Returns 9 if timed out ; If "Not again" checkbox is present and checked, return value is negated ; Failure: Returns -1 and sets @error as follows: ; 1 - Icon parameter error ; 2 - Multiple default button error ; 3 - Button constant error ; 4 - Too many buttons to fit in max available EMB width ; 5 - Button text too long for max available button width ; 6 - StringSize error ; 7 - GUI creation error ; Remarks .......; If $bMain set EMB adjusted to appear on main screen closest to required position ; Author ........: Melba23, based on some original code by photonbuddy & YellowLab ; Example........; Yes ;===================================================================================================================== Func _ExtMsgBox($vIcon, $vButton, $sTitle, $sText, $iTimeOut = 0, $hWin = "", $iVPos = 0, $bMain = True, $sTitlebarIconFile = "") ; 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, $iButton_Xpos ; Validate timeout value $iTimeOut = Int(Number($iTimeOut)) If $iTimeOut < 0 Then $iTimeOut = 0 EndIf ; 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 = 36 Local $sDLL = "user32.dll" Local $sImg = "" ; Cancel numeric countdown if no timeout If $iTimeOut = 0 And $vIcon = 128 Then $vIcon = 0 EndIf 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 EndIf Case Else Return SetError(1, 0, -1) EndSwitch Else If StringInStr($vIcon, "|") Then $iIcon_Style = StringRegExpReplace($vIcon, "(.*)\|", "") $sDLL = StringRegExpReplace($vIcon, "\|.*$", "") Else Switch StringLower(StringRight($vIcon, 3)) Case "exe", "ico" $sDLL = $vIcon Case "bmp", "jpg", "gif", "png" $sImg = $vIcon EndSwitch EndIf EndIf ; Check if two buttons are seeking focus Local $sFocus_Char = $g_aEMB_Settings[13] StringReplace($vButton, $sFocus_Char, "") 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 = $sFocus_Char & "OK|Cancel" Case 2 $vButton = $sFocus_Char & "Abort|Retry|Ignore" Case 3 $vButton = $sFocus_Char & "Yes|No|Cancel" Case 4 $vButton = $sFocus_Char & "Yes|No" Case 5 $vButton = $sFocus_Char & "Retry|Cancel" Case 6 $vButton = $sFocus_Char & "Cancel|Try Again|Continue" Case Else Return SetError(3, 0, -1) EndSwitch EndIf ; Set default values Local $aButton_Text[1] = [0] Local $iButton_Width_Req = 0 ; Get required button size If $vButton <> " " Then ; Split button text into individual strings $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 focus character $sButton_Text = StringRegExpReplace($aButton_Text[$i], "^" & $sFocus_Char & "?(.*)$", "$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 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 ; Check if title sets width Local $iDialog_Width = $iMsg_Width ; Size title Local $aTitleSize = _StringSize($sTitle, $g_aEMB_Settings[10], Default, Default, $g_aEMB_Settings[11]) ; Check if title wider than text If $aTitleSize[2] > ($iMsg_Width - 70) Then ; Assume icon reduction of 50 regardless of icon setting ; Adjust dialog width up to absolute dialog width value $iDialog_Width = ( ($aTitleSize[2] < ($g_aEMB_Settings[7] - $g_aEMB_Settings[12])) ? ($aTitleSize[2] + $g_aEMB_Settings[12]) : ($g_aEMB_Settings[7]) ) 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 - $iDialog_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] - $iDialog_Width) / 2 + $aPos[0] - 3 $iVPos = ($aPos[3] - $iMsg_Height) / 2 + $aPos[1] - 20 Else ; Set EMB to centre om screen $iHpos = (@DesktopWidth - $iDialog_Width) / 2 $iVPos = (@DesktopHeight - $iMsg_Height) / 2 EndIf Else ; Assume parameter is horizontal coord $iHpos = $hWin ; $iVpos already set EndIf EndIf ; If dialog is to appear on main display If $bMain Then ; Dialog is visible horizontally If $iHpos < 10 Then $iHpos = 10 If $iHpos + $iDialog_Width > @DesktopWidth - 20 Then $iHpos = @DesktopWidth - 20 - $iDialog_Width ; Then vertically If $iVPos < 10 Then $iVPos = 10 If $iVPos + $iMsg_Height > @DesktopHeight - 60 Then $iVPos = @DesktopHeight - 60 - $iMsg_Height EndIf ; 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, $iDialog_Width, $iMsg_Height, $iHpos, $iVPos, BitOR(0x80880000, 0x00C00000), $iExtStyle, $iParent_Win) If @error Then Return SetError(7, 0, -1) EndIf If $sTitlebarIconFile <> "" And FileExists($sTitlebarIconFile) = True Then GUISetIcon($sTitlebarIconFile) ; will change icon 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, image 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 Switch StringLower(StringRight($sImg, 3)) Case "bmp", "jpg", "gif" GUICtrlCreatePic($sImg, 4, 4, 32, 32) Case "png" __EMB_ShowPNG($sImg) Case Else GUICtrlCreateIcon($sDLL, $iIcon_Style, 4, 4) EndSwitch EndIf EndIf ; Create buttons Local $aButtonCID[$aButton_Text[0] + 1] = [9999] ; Placeholder prevent problems if no buttons If $vButton <> " " Then ; 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 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) = $sFocus_Char Then ; Look for focus character $iDef_Button_Style = 0x0001 $aButton_Text[$i + 1] = StringTrimLeft($iButton_Text, 1) EndIf ; Draw button $aButtonCID[$i + 1] = GUICtrlCreateButton($aButton_Text[$i + 1], $iButton_Xpos + ($i * ($iButton_Width + 10)), $iMsg_Height - 35, $iButton_Width, 25, $iDef_Button_Style) ; Set focus if default If $iDef_Button_Style Then GUICtrlSetState($aButtonCID[$i + 1], 256) ; $GUI_FOCUS EndIf ; 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 ; 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 Else ; Check for other buttons For $i = 1 To UBound($aButtonCID) - 1 If $aMsg[0] = $aButtonCID[$i] Then $iRet_Value = $i ; No point in looking further ExitLoop 2 EndIf Next 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 WEnd ; Reset original mode Opt('GUIOnEventMode', $iOrgMode) If GUICtrlRead($cCheckbox) = 1 Then ; Negate the return value $iRet_Value *= -1 EndIf GUIDelete($hMsgGUI) Return $iRet_Value EndFunc ;==>_ExtMsgBox Example Usage: Local $hwnd = WinActivate("My Test App") _ExtMsgBoxSet( _ 1, _ ;No Taskbar Button, and makes it modal to the parent window $SS_LEFT, _ ;text justification -1, _ ;colour for the message box background. Default = system colour -1, _ ;colour for the message box text. Default = system colour -1, _ ;font size in points to use for the message box. Default = system font size -1, _ ;font to use for the message box. Default = system font Default, _ ;Normal max width for EMB. Default/min = 370 pixels - max = @DesktopWidth - 20 Default, _ ;Absolute max width for EMB. Default/min = 370 pixels - max = @DesktopWidth - 20 "~") ;Character to define focused button. Default = "~" Local $sMsg = "Auto closing in 10 seconds." & @CRLF & "Do you want to leave it open?" $iMsgboxResult = _ExtMsgBox( _ 128, _ ;makes it have a countdown timer label instead of an icon "~Yes|No", _ ;buttons do display, with Yes as default focus WinGetTitle($hwnd), _ ;title for msgbox $sMsg, _ ;text to put on msgbox 10, _ ;timeout that will be counted down $hwnd, _ ;window to center over Default, _ ;has to be Default or 0 since we are passing in a hwnd above False, _ ;center on hwnd regardless of which monitor it is on "MyTest.ico") ;title bar icon path If $iMsgboxResult = 2 Or $iMsgboxResult = 9 Then ;2 = 2nd button "No", 9 = timed out Exit EndIf Edited November 10, 2021 by Decibel
Moderators Melba23 Posted November 11, 2021 Author Moderators Posted November 11, 2021 Decibel, Thank you for that - I will take a look at the code and see how easy it would be to incorporate that functionality into the UDF. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted November 18, 2021 Author Moderators Posted November 18, 2021 (edited) Decibel, My take on your suggestion: Set a global icon for all ExtMsgBoxes with _ExtMsgBoxSet, with the possibility to override this for specific dialogs: And an example script to show it working: expandcollapse popup#include <GUIConstantsEx.au3> #include "ExtMsgBox_Icon.au3" Global $aAutoItFolder = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1)) $hTest_GUI = GUICreate("EMB Test", 200, 120) $cButton1 = GUICtrlCreateButton("Test 1", 20, 20, 60, 30) $cButton2 = GUICtrlCreateButton("Test 2", 120, 20, 60, 30) $cButton3 = GUICtrlCreateButton("Test 3", 20, 70, 60, 30) $cButton4 = GUICtrlCreateButton("Test 4", 120, 70, 60, 30) GUISetState(@SW_SHOW, $hTest_GUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton1 ; Default BLUE Autoit titlebar icon _ExtMsgBoxSet(Default) _ExtMsgBox(0, "OK", "Test 1", "Basic EMB" & @CRLF & @CRLF & "Blue AutoIt titlebar icon" , 0, $hTest_GUI) _ExtMsgBoxSet(Default) Case $cButton2 ; NO titlebar icon _ExtMsgBoxSet(32) _ExtMsgBox(0, "OK", "Test 2", "No titlebar icon" , 0, $hTest_GUI) _ExtMsgBoxSet(Default) Case $cButton3 ; Global YELLOW AutoIt titlebar icon _ExtMsgBoxSet(0, -1, -1, -1, -1, -1, -1, -1, -1, $aAutoItFolder & "Icons\MyAutoIt3_Yellow.ico") _ExtMsgBox(0, "OK", "Test 3", "Global Yellow AutoIt titlebar icon" , 0, $hTest_GUI) _ExtMsgBoxSet(Default) Case $cButton4 ; Override global setting with RED AutoIt titlebar icon _ExtMsgBoxSet(0, -1, -1, -1, -1, -1, -1, -1, -1, $aAutoItFolder & "Icons\MyAutoIt3_Yellow.ico") _ExtMsgBox(0 & ";" & $aAutoItFolder & "Icons\MyAutoIt3_Red.ico", "OK", "Test 4", "Override Red AutoIt titlebar icon" , 0, $hTest_GUI) _ExtMsgBoxSet(Default) EndSwitch WEnd Let me know what you think - and of course other opinions are always welcome too. M23 Edited February 8, 2022 by Melba23 Removed Beta code 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Decibel Posted November 18, 2021 Posted November 18, 2021 @Melba23, I'm totally facepalming right now. Of course _ExtMsgBoxSet is where it should live so that setting persists in all subsequent _ExtMsgBox calls. Nicely done. I didn't fully understand how to leverage _ExtMsgBoxSet that first night and pry barred a fix into _ExtMsgBox. Always learning.
Moderators Melba23 Posted November 18, 2021 Author Moderators Posted November 18, 2021 Decibel, Glad you like it - I will release a new version soon. M23 Decibel 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted November 19, 2021 Author Moderators Posted November 19, 2021 [NEW VERSION] 19 Nov 21 Added: The ability to set a specific icon on the dialog titlebar - either globally via a new parameter in _ExtMsgBoxSet or locally via the $vIcon parameter of _ExtMsgBox. New UDF and examples in the first post. M23 Decibel and Exit 2 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zehir Posted November 16, 2022 Posted November 16, 2022 (edited) Thanks for this great UDF it is super useful 👍 However I have a problem with the max width of a word. If it's wider than the GUI it won't break the word into multiple lines, but return an error instead... I am very scared of using it with unknow text variables, so I can't use it to make functions that use it. Am I doing something wrong? Edit : Also it would be very convenient if the buttons could have different sizes, so if we have a button with a long text the GUI doesn't have to be enormous to fit 4 buttons, and we could have more buttons. Thanks Edited November 16, 2022 by Zehir
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now