Jump to content

Extended Message Box - New Version: 16 Feb 24


Melba23
 Share

Recommended Posts

  • Moderators

jcbrief,

The trouble with expanding tabs into spaces is that it only works properly with monospaced fonts - as soon as you expand tabs into spaces with proportional fonts, you mess up the standard "indent" that tabs give you. Look at the results of the following script - with Consolas we get nicely arranged text once expanded, with Arial the text is all visible, but the horizontal alignment has been affected as the spaces are not the same width as the tab itself:

#include <ExtMsgBox.au3>

$sMsg = "       |       |       |" & @CRLF & _
         @TAB & "1"        & @TAB & "1"        & @TAB & "1" & @CRLF & _
         @TAB & " 2"       & @TAB & "22"       & @TAB & "2" & @CRLF & _
         @TAB & "  3"      & @TAB & "333"      & @TAB & "3" & @CRLF & _
         @TAB & "   4"     & @TAB & "4444"     & @TAB & "4" & @CRLF & _
         @TAB & "    5"    & @TAB & "55555"    & @TAB & "5" & @CRLF & _
         @TAB & "     6"   & @TAB & "666666"   & @TAB & "6" & @CRLF & _
         @TAB & "      7"  & @TAB & "7777777"  & @TAB & "7" & @CRLF & _
         @TAB & "       8" & @TAB & "88888888" & @TAB & "8"

_ExtMsgBoxSet(5, 0, -1, -1, 12, "Consolas")
_ExtMsgBox(0, "Default Font", "Test 2", $sMsg)
$sExpMsg = _Expand_Tabs($sMsg)
_ExtMsgBox(0, "Default Font", "Test 2", $sExpMsg)

_ExtMsgBoxSet(5, 0, -1, -1, 12, "Arial")
_ExtMsgBox(0, "Default Font", "Test 2", $sMsg)
$sExpMsg = _Expand_Tabs($sMsg)
_ExtMsgBox(0, "Default Font", "Test 2", $sExpMsg)

Func _Expand_Tabs($sText, $iSize = 8, $iJust = 0)

    Local $sExpText = "", $sLine, $iLinePos

    ; Convert all newlines to @CRLF
    If StringInStr($sText, @CRLF) = 0 Then
        StringRegExpReplace($sText, "[\x0a|\x0d]", @CRLF)
    EndIf
    ; Split into lines
    Local $asLines = StringSplit($sText, @CRLF, 1)
    ; For each line
    For $i = 1 To $asLines[0]
        $sLine = $asLines[$i]
        ; If there are characters
        If StringLen($sLine) > 0 Then
            $iLinePos = 1
            Do
                ; Look for tabs
                If StringMid($sLine, $iLinePos, 1) = Chr(0x09) Then
                    ; Determine the number of spaces needed to expand the tab
                    $sSpaces = ""
                    For $j = 1 To $iSize - Mod($iLinePos - 1, $iSize) - 1
                        $sSpaces &= " "
                    Next
                    ; Recreate the line
                    $sLine = StringMid($sLine, 1, $iLinePos - 1) & $sSpaces & StringMid($sLine, $iLinePos + 1)
                EndIf
                ; look at the next character until we get to the end of the line
                $iLinePos += 1
            Until $iLinePos > StringLen($sLine)
        EndIf
        ; Add the line to the expanded text
        $sExpText &= $sLine
        ; Add the @CRLF except for the final line
        If $i < $asLines[0] Then
            $sExpText &= @CRLF
        EndIf
    Next

    ; Return the expanded text
    Return $sExpText

EndFunc

I realised that tabs would cause a problem when I wrote the UDF, but I was unable to solve it then and remain as baffled now. :)

Sorry I cannot be more help - I will continue to think about the problem. At least you seem to have a solution which satisifies you. :mellow:

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

Wouldn't it be possible to convert any @TAB to a set number of SPACE characters prior to sending the string to the StringSize function? I'm guessing a RegEx would work for that, but I don't know the syntax for that. :mellow:

Just let it be known that any @TABs will be converted to x # of spaces.

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,

Wouldn't it be possible to convert any @TAB to a set number of SPACE characters

Of course, but the problem remains that the vertical alignment given by the tab character now no longer functions - which is probably why it was used in the first place. The function I posted above just finesses that idea by calculating the number of spaces inserted so that you do retain the alignment for monospaced fonts. :)

The problem is that the "GetTextExtentPoint32" call to GDI32.dll used to get the size of a line of text does not know about expanding tabs (and why should it?) and appears to regard Chr(0x09) as a single character thus returning a false, shorter value for the line length. If the line subsequently needs to wrap once the tabs are expanded, then the vertical size value calculated by the UDF is wrong and the final line(s) of text will not be shown as the ExtMsgBox will be too short. :)

When I have felt the need to use tabs in the displayed text, I always made sure there was a longish line without tabs to set the width of the ExtMsgBox so that the shorter lines with tabs would always have enough room to expand. Not really a solution, but an acceptable workaround as far as I was concerned. :mellow:

M23

Edit: I have had an idea. If we replace the @TAB by several characters (say "XXXXXXXX") within the StringSize UDF and then do the measuring, the size will always be at least the size of the biggest expanded tab. The ExtMsgBox may then be a bit too big if the tabs do not take up all the room, but it will at least show all the text. I will work on it and see what I can come up with. :)

Edited by Melba23

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

jcbrief,

Here is a modified version of the StringSize UDF which allow tabs to be expanded to size the line correctly for ExtMsgBox use. I have placed all of the necessary code in this script as it needed a few tweaks to the EMB code as well to enable the tab expansion code to be switched on/off in the examples. :)

Please have a play with it and see if it does what you want: :mellow:

#Region
; #GLOBAL CONSTANTS# =================================================================================================
Global Const $MB_ICONSTOP   = 16 ; Stop-sign icon
Global Const $MB_ICONQUERY  = 32 ; Question-mark icon
Global Const $MB_ICONEXCLAM = 48 ; Exclamation-point icon
Global Const $MB_ICONINFO   = 64 ; Icon consisting of an 'i' in a circle

; #GLOBAL VARIABLES# =================================================================================================
; Default settings
Global $aEMB_FontData = _GetDefaultEMBFont()
Global $iDef_EMB_Font_Size = $aEMB_FontData[0]
Global $sDef_EMB_Font_Name = $aEMB_FontData[1]
$aEMB_FontData = 0
Global $iDef_EMB_BkCol = DllCall("User32.dll", "int", "GetSysColor", "int", 15) ; $COLOR_3DFACE = 15
$iDef_EMB_BkCol = BitAND(BitShift(String(Binary($iDef_EMB_BkCol[0])), 8), 0xFFFFFF)
Global $iDef_EMB_Col   = DllCall("User32.dll", "int", "GetSysColor", "int", 8) ; $COLOR_WINDOWTEXT = 8
$iDef_EMB_Col = BitAND(BitShift(String(Binary($iDef_EMB_Col[0])), 8), 0xFFFFFF)
; Current settings
Global $iEMB_Style = 0
Global $iEMB_Just  = 0
Global $iEMB_BkCol = $iDef_EMB_BkCol
Global $iEMB_Col   = $iDef_EMB_Col
Global $sEMB_Font_Name = $sDef_EMB_Font_Name
Global $iEMB_Font_Size = $iDef_EMB_Font_Size
#Endregion

#Region

; Start with no tabs to show it works
$sMsg = "No tabs:" & @CRLF & _
        "        An artificially extended pretty long Line 1 to push the limits of the EMB" & @CRLF & _
        "        Line 2"
_ExtMsgBox(0, "OK", "No Tab", $sMsg)

; Now add tabs and show it does not
$sMsg = "Non-exp tabs:" & @CRLF & _
        @TAB & "An artificially extended pretty long Line 1 to push the limits of the EMB" & @CRLF & _
        @TAB & "Line 2"
$aRet = _StringSize($sMsg)
_ExtMsgBox(0, "OK", "Non-Exp Tab", $sMsg)

; Allow tabs to be expanded and it works again!
_ExtMsgBoxSet(10)
$sMsg = "Exp tabs:" & @CRLF & _
        @TAB & "An artificially extended pretty long Line 1 to push the limits of the EMB" & @CRLF & _
        @TAB & "Line 2"
$aRet = _StringSize($sMsg, Default, Default, 1)
_ExtMsgBox(0, "OK", "Exp Tab", $sMsg)

; A very complex tabbed message
$sMsg_2 = "|" & @TAB & "|" & @TAB & "|" & @TAB & "|" & @TAB & "|" & @TAB & "|" & @CRLF & _
         @TAB & "1"        & @TAB & "1"        & @TAB & "1" & @CRLF & _
         @TAB & " 2"       & @TAB & "22"       & @TAB & "2" & @CRLF & _
         @TAB & "  3"      & @TAB & "333"      & @TAB & "3" & @CRLF & _
         @TAB & "   4"     & @TAB & "4444"     & @TAB & "4" & @CRLF & _
         @TAB & "    5"    & @TAB & "55555"    & @TAB & "5" & @CRLF & _
         @TAB & "     6"   & @TAB & "666666"   & @TAB & "6" & @CRLF & _
         @TAB & "      7"  & @TAB & "7777777"  & @TAB & "7" & @CRLF & _
         @TAB & "       8" & @TAB & "88888888" & @TAB & "8"

; No tab expansion with proportional font
_ExtMsgBoxSet(Default)
_ExtMsgBox(0, "OK", "Non-Exp Tab", $sMsg_2)
; Tab expansion with proportional font
_ExtMsgBoxSet(10)
_ExtMsgBox(0, "OK", "Exp Tab", $sMsg_2)
; No tab expansion with mono font
_ExtMsgBoxSet(0, 0, Default, Default, Default, "Courier New")
_ExtMsgBox(0, "OK", "Exp Tab", $sMsg_2)
; Tab expansion with mono font
_ExtMsgBoxSet(10)
_ExtMsgBox(0, "OK", "Exp Tab", $sMsg_2)

#Endregion

Func _StringSize($sText, $iSize = 8.5, $iWeight = 400, $iAttrib = 0, $sName = "", $iMaxWidth = 0, $hWnd = 0)

    ; Attrib + 1 = expand tabs

    ; Set parameters passed as Default
    If $iSize = Default Then $iSize = 8.5
    If $iWeight = Default Then $iWeight = 400
    If $iAttrib = Default Then $iAttrib = 0
    If $sName = "" Or $sName = Default Then $sName = _StringSize_DefaultFontName()

    ; Check parameters are correct type
    If Not IsString($sText) Then Return SetError(1, 1, 0)
    If Not IsNumber($iSize) Then Return SetError(1, 2, 0)
    If Not IsInt($iWeight) Then Return SetError(1, 3, 0)
    If Not IsInt($iAttrib) Then Return SetError(1, 4, 0)
    If Not IsString($sName) Then Return SetError(1, 5, 0)
    If Not IsNumber($iMaxWidth) Then Return SetError(1, 6, 0)
    If Not IsHwnd($hWnd) And $hWnd <> 0 Then Return SetError(1, 7, 0)

    Local $aRet, $hDC, $hFont, $hLabel = 0, $hLabel_Handle

    ; If GUI handle was passed
    If IsHWnd($hWnd) Then
        ; Create label outside GUI borders
        $hLabel = GUICtrlCreateLabel("", -10, -10, 10, 10)
        $hLabel_Handle = GUICtrlGetHandle(-1)
        GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sName)
        ; Create DC
        $aRet = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hLabel_Handle)
        If @error Or $aRet[0] = 0 Then
            GUICtrlDelete($hLabel)
            Return SetError(2, 1, 0)
        EndIf
        $hDC = $aRet[0]
        $aRet = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hLabel_Handle, "int", 0x0031, "wparam", 0, "lparam", 0) ; $WM_GetFont
        If @error Or $aRet[0] = 0 Then
            GUICtrlDelete($hLabel)
            Return SetError(2, _StringSize_Error_Close(2, $hDC), 0)
        EndIf
        $hFont = $aRet[0]
    Else
        ; Get default DC
        $aRet = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd)
        If @error Or $aRet[0] = 0 Then Return SetError(2, 1, 0)
        $hDC = $aRet[0]
        ; Create required font
        $aRet = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", 90) ; $LOGPIXELSY
        If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(3, $hDC), 0)
        Local $iInfo = $aRet[0]
        $aRet = DllCall("gdi32.dll", "handle", "CreateFontW", "int", -$iInfo * $iSize / 72, "int", 0, "int", 0, "int", 0, _
            "int", $iWeight, "dword", BitAND($iAttrib, 2), "dword", BitAND($iAttrib, 4), "dword", BitAND($iAttrib, 8), "dword", 0, "dword", 0, _
            "dword", 0, "dword", 5, "dword", 0, "wstr", $sName)
        If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(4, $hDC), 0)
        $hFont = $aRet[0]
    EndIf

    ; Select font and store previous font
    $aRet = DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hFont)
    If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(5, $hDC, $hFont, $hLabel), 0)
    Local $hPrevFont = $aRet[0]

    ; Declare variables
    Local $avSize_Info[4], $iLine_Length, $iLine_Height = 0, $iLine_Count = 0, $iLine_Width = 0, $iWrap_Count, $iLast_Word, $sTest_Line
    ; Declare and fill Size structure
    Local $tSize = DllStructCreate("int X;int Y")
    DllStructSetData($tSize, "X", 0)
    DllStructSetData($tSize, "Y", 0)

    ; Ensure EoL is @CRLF and break text into lines
    If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[\x0a|\x0d]", @CRLF)
    Local $asLines = StringSplit($sText, @CRLF, 1)

    ; For each line
    For $i = 1 To $asLines[0]
        ; Expand any tabs if required
        If BitAND($iAttrib, 1) Then
            $asLines[$i] = StringReplace($asLines[$i], @TAB, " XXXXXXXX")
        EndIf
        ; Size line
        $iLine_Length = StringLen($asLines[$i])
        DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $asLines[$i], "int", $iLine_Length, "ptr", DllStructGetPtr($tSize))
        If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0)
        If DllStructGetData($tSize, "X") > $iLine_Width Then $iLine_Width = DllStructGetData($tSize, "X")
        If DllStructGetData($tSize, "Y") > $iLine_Height Then $iLine_Height = DllStructGetData($tSize, "Y")
    Next

    ; Check if $iMaxWidth has been both set and exceeded
    If $iMaxWidth <> 0 And $iLine_Width > $iMaxWidth Then ; Wrapping required

        ; For each Line
        For $j = 1 To $asLines[0]
            ; Size line unwrapped
            $iLine_Length = StringLen($asLines[$j])
            DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $asLines[$j], "int", $iLine_Length, "ptr", DllStructGetPtr($tSize))
            If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0)
            ; Check wrap status
            If DllStructGetData($tSize, "X") < $iMaxWidth - 4 Then
                ; No wrap needed so count line and store
                $iLine_Count += 1
                $avSize_Info[0] &= $asLines[$j] & @CRLF
            Else
                ; Wrap needed so zero counter for wrapped lines
                $iWrap_Count = 0
                ; Build line to max width
                While 1
                    ; Zero line width
                    $iLine_Width = 0
                    ; Initialise pointer for end of word
                    $iLast_Word = 0
                    ; Add characters until EOL or maximum width reached
                    For $i = 1 To StringLen($asLines[$j])
                        ; Is this just past a word ending?
                        If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1
                        ; Increase line by one character
                        $sTest_Line = StringMid($asLines[$j], 1, $i)
                        ; Get line length
                        $iLine_Length = StringLen($sTest_Line)
                        DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sTest_Line, "int", $iLine_Length, "ptr", DllStructGetPtr($tSize))
                        If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0)
                        $iLine_Width = DllStructGetData($tSize, "X")
                        ; If too long exit the loop
                        If $iLine_Width >= $iMaxWidth - 4 Then ExitLoop
                    Next
                    ; End of the line of text?
                    If $i > StringLen($asLines[$j]) Then
                        ; Yes, so add final line to count
                        $iWrap_Count += 1
                        ; Store line
                        $avSize_Info[0] &= $sTest_Line & @CRLF
                        ExitLoop
                    Else
                        ; No, but add line just completed to count
                        $iWrap_Count += 1
                        ; Check at least 1 word completed or return error
                        If $iLast_Word = 0 Then Return SetError(3, _StringSize_Error_Close(0, $hDC, $hFont, $hLabel), 0)
                        ; Store line up to end of last word
                        $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF
                        ; Strip string to point reached
                        $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word)
                        ; Trim leading whitespace
                        $asLines[$j] = StringStripWS($asLines[$j], 1)
                        ; Repeat with remaining characters in line
                    EndIf
                WEnd
                ; Add the number of wrapped lines to the count
                $iLine_Count += $iWrap_Count
            EndIf
        Next

        ; Clear any tab expansions
        If BitAND($iAttrib, 1) Then
            $avSize_Info[0] = StringRegExpReplace($avSize_Info[0], "\x20?XXXXXXXX", @TAB)
        EndIf

        ; Complete return array
        $avSize_Info[1] = $iLine_Height
        $avSize_Info[2] = $iMaxWidth
        ; Convert lines to pixels and add drop margin
        $avSize_Info[3] = ($iLine_Count * $iLine_Height) + 4
    Else ; No wrapping required
        ; Create return array (add drop margin to height)
        Local $avSize_Info[4] = [$sText, $iLine_Height, $iLine_Width, ($asLines[0] * $iLine_Height) + 4]
    EndIf

    ; Clear up
    DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hPrevFont)
    DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hFont)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "handle", $hDC)
    If $hLabel Then GUICtrlDelete($hLabel)

    Return $avSize_Info

EndFunc ;==>_StringSize

Func _StringSize_Error_Close($iExtCode, $hDC = 0, $hFont = 0, $hLabel = 0)

    If $hFont <> 0 Then DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hFont)
    If $hDC <> 0 Then DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "handle", $hDC)
    If $hLabel Then GUICtrlDelete($hLabel)

    Return $iExtCode

EndFunc ;=>_StringSize_Error_Close

Func _StringSize_DefaultFontName()

    ; Get default system font data
    Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
    DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
    Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 13))
    If IsString(DllStructGetData($tLOGFONT, 14)) Then
        Return DllStructGetData($tLOGFONT, 14)
    Else
        Return "Tahoma"
    EndIf

EndFunc ;=>_StringSize_DefaultFontName

Func _ExtMsgBoxSet($iStyle = 0, $iJust = 0, $iBkCol = -1, $iCol = -1, $iFont_Size = -1, $sFont_Name = "")

    ; $iStyle +8 = expand tabs

    ; Set global EMB variables to required values
    Switch $iStyle
        Case Default
            $iEMB_Style = 0 ; Button on TaskBar and $WS_EX_TOPMOST
            $iEMB_Just = 0 ; $SS_LEFT
            $iEMB_BkCol = $iDef_EMB_BkCol
            $iEMB_Col = $iDef_EMB_Col
            $sEMB_Font_Name = $sDef_EMB_Font_Name
            $iEMB_Font_Size = $iDef_EMB_Font_Size
            Return
        Case 0 To 15
            $iEMB_Style = $iStyle
        Case Else
            Return SetError(1, 1, 0)
    EndSwitch

    Switch $iJust
        Case 0, 1, 2, 4, 5, 6
            $iEMB_Just = $iJust
        Case Else
            Return SetError(1, 2, 0)
    EndSwitch

    Switch $iBkCol
        Case Default
            $iEMB_BkCol = $iDef_EMB_BkCol
        Case -1
            ; Do nothing
        Case 0 To 0xFFFFFF
            $iEMB_BkCol = $iBkCol
        Case Else
            Return SetError(1, 3, 0)
    EndSwitch

    Switch $iCol
        Case Default
            $iEMB_Col = $iDef_EMB_Col
        Case -1
            ; Do nothing
        Case 0 To 0xFFFFFF
            $iEMB_Col = $iCol
        Case Else
            Return SetError(1, 4, 0)
    EndSwitch

    Switch $iFont_Size
        Case Default
            $iEMB_Font_Size = $iDef_EMB_Font_Size
        Case 8 To 72
            $iEMB_Font_Size = Int($iFont_Size)
        Case -1
            ; Do nothing
        Case Else
            Return SetError(1, 5, 0)
    EndSwitch

    Switch $sFont_Name
        Case Default
            $sEMB_Font_Name = $sDef_EMB_Font_Name
        Case ""
            ; Do nothing
        Case Else
            If IsString($sFont_Name) Then
                $sEMB_Font_Name = $sFont_Name
            Else
                Return SetError(1, 6, 0)
            EndIf
    EndSwitch

    Return 1

EndFunc

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

    Local $iParent_Win = 0, $fCountdown = False

    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    ; Set default sizes for message box
    Local $iMsg_Width_max = 370, $iMsg_Width_min = 150, $iMsg_Width_abs = 500
    Local $iMsg_Height_min = 100
    Local $iButton_Width_max = 80, $iButton_Width_min = 50

    ; Declare local variables
    Local $iButton_Width_Req, $iButton_Width, $iButton_Xpos, $iRet_Value, $iHpos

    ;; 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
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                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
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        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
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(3, 0, -1)
        EndSwitch
    EndIf

    Local $iEMB_Attrib = Default
    If BitAnd($iEMB_Style, 8) Then
        $iEMB_Attrib = 1
    EndIf

    ; Get message label size
    While 1
        Local $aLabel_Pos = _StringSize($sText, $iEMB_Font_Size, Default, $iEMB_Attrib, $sEMB_Font_Name, $iMsg_Width_max - 20 - $iIcon_Reduction)
        If @error Then
            If $iMsg_Width_max = $iMsg_Width_abs Then
                $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(5, 0, -1)
            Else
                $iMsg_Width_max += 10
            EndIf
        Else
            ExitLoop
        EndIf
    WEnd

    ; Reset text to wrapped version
    $sText = $aLabel_Pos[0]

    ; Get individual button text
    Local $aButtons = StringSplit($vButton, "|")
    ; Get minimum GUI width needed for buttons
    Local $iMsg_Width_Button = ($iButton_Width_max + 10) * $aButtons[0] + 10
    ; If shorter than min width
    If $iMsg_Width_Button < $iMsg_Width_min Then
        ; Set buttons to max size and leave box min width unchanged
        $iButton_Width = $iButton_Width_max
    Else
        ; Check button width needed to fit within max box width
        $iButton_Width_Req = ($iMsg_Width_max - (($aButtons[0] + 1) * 10)) / $aButtons[0]
        ; Button width less than min button width permitted
        If $iButton_Width_Req < $iButton_Width_min Then
            $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
            Return SetError(4, 0, -1)
            ; Buttons only need resizing to fit
        ElseIf $iButton_Width_Req < $iButton_Width_max Then
            ; Set box to max width and set button size as required
            $iMsg_Width_Button = $iMsg_Width_max
            $iButton_Width = $iButton_Width_Req
            ; Buttons can be max size
        Else
            ; Set box min width to fit buttons
            $iButton_Width = $iButton_Width_max
            $iMsg_Width_min = $iMsg_Width_Button
        EndIf
    EndIf
    ; Determine final button width required
    $iButton_Width_Req = Int((($iButton_Width + 10) * $aButtons[0]) + 10)

    ; 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 + 65
    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 BitAND($iEMB_Style, 2) 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($iEMB_Style, 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
        $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
        Return SetError(6, 0, -1)
    EndIf
    If $iEMB_BkCol <> Default Then GUISetBkColor($iEMB_BkCol)

    ; Set centring parameter
    Local $iLabel_Style = 0 ; $SS_LEFT
    If BitAND($iEMB_Just, 1) = 1 Then
        $iLabel_Style = 1 ; $SS_CENTER
    ElseIf BitAND($iEMB_Just, 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, $iEMB_Font_Size, Default, Default, $sEMB_Font_Name)
    If $iEMB_Col <> Default Then GUICtrlSetColor(-1, $iEMB_Col)

    ; Create icon or countdown timer
    If $fCountdown = True Then
        Local $hCountdown_Label = GUICtrlCreateLabel(StringFormat("%2s", $iTimeout), 10, 20, 32, 32)
        GUICtrlSetFont(-1, 18, Default, Default, $sEMB_Font_Name)
        GUICtrlSetColor(-1, $iEMB_Col)
    Else
        If $iIcon_Reduction Then GUICtrlCreateIcon($sDLL, $iIcon_Style, 10, 20)
    EndIf

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

    ; Create buttons
    ; Calculate button horizontal start
    If $aButtons[0] = 1 Then
        If BitAND($iEMB_Just, 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 = 10 + ($iMsg_Width - $iMsg_Width_Button) / 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 $aButtons[0] - 1
        Local $iButton_Text = $aButtons[$i + 1]
        ; Set default button
        If $aButtons[0] = 1 Then ; Only 1 button
            $iDef_Button_Style = 0x0001
        ElseIf StringLeft($iButton_Text, 1) = "&" Then ; Look for &
            $iDef_Button_Style = 0x0001
            $aButtons[$i + 1] = StringTrimLeft($iButton_Text, 1)
            ; Set default button code for Accel key return
            $iDefButton_Code = $i + 1
        EndIf
        ; Draw button
        GUICtrlCreateButton($aButtons[$i + 1], $iButton_Xpos + ($i * ($iButton_Width + 10)), $iMsg_Height - 35, $iButton_Width, 25, $iDef_Button_Style)
        ; Set font if required
        If Not BitAnd($iEMB_Style, 4) Then GUICtrlSetFont(-1, $iEMB_Font_Size, 400, 0, $sEMB_Font_Name)
        ; Reset default style parameter
        $iDef_Button_Style = 0
    Next

    ; Show GUI
    GUISetState(@SW_SHOW, $hMsgGUI)

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

    ; Much faster to declare GUIGetMsg return array here and not in loop
    Local $aMsg

    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] = $hAccel_Key
                    ; Accel key pressed so return default button code
                    If $iDefButton_Code Then
                        $iRet_Value = $iDefButton_Code
                        ExitLoop
                    EndIf
                Case $aMsg[0] > $hAccel_Key
                    ; Button handle minus Accel key handle will give button index
                    $iRet_Value = $aMsg[0] - $hAccel_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($hCountdown_Label, StringFormat("%2s", $iTimeout - $iCounter))
            EndIf
        EndIf

    WEnd

    $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)

    GUIDelete($hMsgGUI)

    Return $iRet_Value

EndFunc   ;==>_ExtMsgBox

Func _GetDefaultEMBFont()

    ; Fill array with standard default data
    Local $aDefFontData[2] = [9, "Tahoma"]

    ; Get AutoIt GUI handle
    Local $hWnd = WinGetHandle(AutoItWinGetTitle())
    ; Open Theme DLL
    Local $hThemeDLL = DllOpen("uxtheme.dll")
    ; Get default theme handle
    Local $hTheme = DllCall($hThemeDLL, 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', "Static")
    If @error Then Return $aDefFontData
    $hTheme = $hTheme[0]
    ; Create LOGFONT structure
    Local $tFont = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;wchar[32]")
    Local $pFont = DllStructGetPtr($tFont)
    ; Get MsgBox font from theme
    DllCall($hThemeDLL, 'long', 'GetThemeSysFont', 'HANDLE', $hTheme, 'int', 805, 'ptr', $pFont) ; TMT_MSGBOXFONT
    If @error Then Return $aDefFontData
    ; Get default DC
    Local $hDC = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd)
    If @error Then Return $aDefFontData
    $hDC = $hDC[0]
    ; Get font vertical size
    Local $iPixel_Y = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", 90) ; LOGPIXELSY
    If Not @error Then
        $iPixel_Y = $iPixel_Y[0]
        ; Calculate point size
        $aDefFontData[0] = -Round(((1 * DllStructGetData($tFont, 1)) * 72 / $iPixel_Y), 1)
    EndIf
    ; Close DC
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDC)
    ; Extract font data from LOGFONT structure
    $aDefFontData[1] = DllStructGetData($tFont, 14)

    Return $aDefFontData

EndFunc ;=>_GetDefaultEMBFont

As mentioned above, for the moment I have added code to tell both UDFs whether or not to expand any tabs by using additional elements to the passed parameters. If all goes well, the additional code would be added directly to the StringSize UDF and the whole thing would become transparent to the user. The additional code is not a huge overhead but I will keep working to make it as small as possible. :)

And if anyone else wants to comment on the tab expansion problem and/or this proposed solution, please feel free! :)

M23

Edit: Typnig!

Edited by Melba23

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

First I want to apologize for not getting back to you earlier. Since my post was on the bottom of a page I never saw anything after it (duh new page, sigh). I've been checking for days and didn't see your reply. sorry.

I will be trying what you have said. I was mainly wanting to let you know things I had found. I knew Tabs could be a problem with non-fixed size fonts, but couldn't figure out an approach to it.

I've been using your EMB and have really appreciate all the work you have put into it. It has saved me lots of time in one of the projects I'm working on.

If you don't mind helping me understand some things. I have some questions re: what I've seen in your code.

I've noticed for my system: (WinXP Window size 1024/768) that the default font is iDef_EMB_Font_Size=[8.3] sDef_EMB_Font_Name=[Tahoma]. Having a size of 8.3 seems a bit odd. Could you point me in a direction to explain how your Func _GetDefaultEMBFont() works ?. More specifically

If Not @error Then
        $iPixel_Y = $iPixel_Y[0]
        ; Calculate point size
        $aDefFontData[0] = -Round(((1 * DllStructGetData($tFont, 1)) * 72 / $iPixel_Y), 1)
EndIf

From playing around the default font size seems to be 8.5. At least when I have my code using 8.3 it will come out as 8. But 8.5 will look the same as in yours. I'm not trying to be picky, just trying to understand this.

I notice this in your your "ExtMsgBox Example", "Test 2", "Default Font" Button.

Thank,

Joe

Link to comment
Share on other sites

  • Moderators

jcbrief,

explain how your Func _GetDefaultEMBFont() works

It was a long time ago, but I think I can remember the gist. :)

The LOGPIXELSY call to gdi32.dll returns the vertical size of the font in pixels. We need to convert that to a point size and the formula I used to do this was one I found on t'InterWeb. I did wonder about the 1 * DllStructGetData($tFont, 1) element at the time, but as it seemed to work I left it in! I get 9/Segoe UI for the font on my Vista system, which matched the normal values on a standard MsgBox. I know AutoIt uses 8.5/Tahoma as a default font which matches your result.

I take it from your comments that you would prefer the result to be 8.5 rather then 8.3 - if Windows were Flooring the value (I seem to remember it only uses full and half-point fonts) this could well be the reason you get smaller fonts. Try amending the formula to read:

$aDefFontData[0] = Int(2 * (.25 - DllStructGetData($tFont, 1) * 72 / $iPixel_Y)) / 2

That will force the value to the nearest .5 and so you should get the 8.5 you want while I still get my 9. :mellow:

Let me know how this change works for you - as well as the tab-expansion suggestion above. If all goes well, I will look into changing the UDF code at the next release. :)

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

M23

Re:

$aDefFontData[0] = Int(2 * (.25 - DllStructGetData($tFont, 1) * 72 / $iPixel_Y)) / 2

I will try it. thanks.

Its not that I prefer 8.5 vs 8.3, but I an playing with a modification of your EMB that also has CheckBoxes and RadioButtons. I noticed the difference in the default font size and tracked it to this size difference.

I will search online for this. I was more wondering where the 72 came from. Again I like to understand things. My display uses 96 DPI, so not that. Oh, well will look.

Thanks,

Joe

Link to comment
Share on other sites

  • Moderators

jcbrief,

That page looks familiar! :)

What is font attribute 1??.

That is the extra code I mentioned which is used to turn the tab-expansion on and off - I added the following remark at the start of the StringSize code:

; Attrib + 1 = expand tabs

as a reminder to me. There is a similar line:

; $iStyle +8 = expand tabs

at the start fo the _ExtMsgBoxSet code for the same reason.

As I stated above I was intending to remove this additonal code if I decided to make tab-expansion standard behaviour - but as it stands it is not script-breaking and I might well leave it in. We will see! :mellow:

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

M23

I'm now looking at the changes you have made to _StringSize(), I should have looked there before asking. I see you have made many changes there.

I do things slowly, and I see I will have to take my time looking at _StringSize() new vs old. I didn't get into it before, just used it.

I have learned so much by getting into your code :mellow: .

Thanks,

Joe

Link to comment
Share on other sites

  • Moderators

jcbrief,

Do not get too hung up on any StringSize code changes - we started this journey looking at ExtMsgBox and tabs! :)

Besides that code is beta-standard and not on general release yet. :)

What do you think of the tab expansion implementation included in that script? Does it satisfy your requirements? :mellow:

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

M23

RE: "Tab Expansion implementation", It seems to take care of the window size problems. With what I'm doing it seems to work fine.

I looked into your "_StringSize()" and saw how you took care of it. I noticed how you change tabs to " XXXXXXXX", then restore tabs later. I tried to figure out how to use a tab conversion, and got lost in being able to wrap lines with that expansion.

Thanks,

Joe

Link to comment
Share on other sites

  • Moderators

jcbrief,

Glad you like it :mellow:

I will be releasing new versions of ExtMsgBox and StringSize with the new code during the week - keep your eyes open. :)

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

M23

I have been thinking on the tabs "ExtMsgBox" and "StringSize".

Sorry I do things slowly. My comment is I do things at sub-turtle speeds, while others do things at warp speed.

I'm wondering if you have the Tab Expansion inside ExtMsgBox on the string for Label that is passed to it. That way your StringSize will see the full line and use its wrap functions correctly, and return the correct box size even if strings are wrapped.

Joe

Link to comment
Share on other sites

  • Moderators

[NEW VERSION] 16 Aug 11

Tab characters were not properly expanded and so the EMB could be too small to hold all the text. Now by adding 8 to the $iStyle parameter in _ExtMsgBoxSet, the tabs will be expanded and the EMB better sized. As the tabs are expanded to a fixed value of "XXXXXXXX", the EMB may now be slightly too wide, but at least all the text will be visible.

All of the work is done by the StringSize UDF - a new version of which has been uploaded today.

This a non-scriptbreaking change - if you do not want to expand tabs you need change nothing in your scripts. :)

New ExtMsgBox UDF, a new example to show the tab expansion and new zipfile in first post. :mellow:

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

  • 2 weeks later...
  • 3 months later...
  • Moderators

WPA-Fan,

I think I can see a way to do this. The UDF would return negative values if the checkbox were checked - you would then have to set a flag in your script to prevent the UDF being called again. ;)

Let me have a play around today to see what I can come up with. :)

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

  • Moderators

WPA-Fan,

Easier than I thought. :)

Try this and see what you think:

Please try and break it and/or make any suggestions as to how it might be improved. If all goes well I will release a new version in a few days. ;)

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

  • 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...