AndyS01

ExtMsgBox wrong width with fixed font

3 posts in this topic

When I set ExtMsgBox to use fixed font, the width is calculated incorrectly, so text wraps.

my code:

#include <_ExtMsgBox.au3>
#include <Array.au3>

    _ExtMsgBoxSet(0, 0, -1, -1, 10, "courier new") ; Set _ExtMsgBox formatting

ShowAbout()

Func ShowAbout()
    Local $ar[1] = [0]

    _ArrayAdd($ar, "Program to bla bla bla.")
    _ArrayAdd($ar, "")
    _ArrayAdd($ar, "usage: " & "[-switch>] [<datafile>.csv]")
    _ArrayAdd($ar, "")
    _ArrayAdd($ar, "<-switch>:")
    _ArrayAdd($ar, "-h ....... Display this help information")
    _ArrayAdd($ar, "-nb ...... Do not create backup files.")
    _ArrayAdd($ar, "-regdel... Delete program relative registry items before")
    _ArrayAdd($ar, "           running (debug mode only)")
    _ArrayAdd($ar, "-ro ...... Do not modify the input file.")
    _ArrayAdd($ar, "-tail .... Launch 'Tail' to tail the debug output file")
    _ArrayAdd($ar, "")
    _ArrayAdd($ar, "Copyright 2011-2016, Andy Scharmer")
    _ExtMsgBox(8, "OK", "About", _ArrayToString($ar, @CRLF, 1))
    Return
EndFunc   ;==>ShowAbout

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

AndyS01,

As explained in the UDF function headers, the normal max width of the ExtMsgBox is 370 pixels - as you have not altered this in the _ExtMsgBoxSet call, that is the width you get and so as the text is too wide to fit, it wraps. You need to increase the max width of the ExtMsgBox to fit the text. I did it this way:

#include <ExtMsgBox.au3>

ShowAbout()

Func ShowAbout()

    ; Create the string in a more logical manner
    Local $sString
    $sString &= "Program to bla bla bla." & @CRLF
    $sString &= @CRLF
    $sString &= "usage: " & "[-switch>] [<datafile>.csv]"
    $sString &= @CRLF
    $sString &= "<-switch>:" & @CRLF
    $sString &= "-h ....... Display this help information" & @CRLF
    $sString &= "-nb ...... Do not create backup files." & @CRLF
    $sString &= "-regdel... Delete program relative registry items before" & @CRLF
    $sString &= "           running (debug mode only)" & @CRLF
    $sString &= "-ro ...... Do not modify the input file." & @CRLF
    $sString &= "-tail .... Launch 'Tail' to tail the debug output file" & @CRLF
    $sString &= @CRLF
    $sString &= "Copyright 2011-2016, Andy Scharmer" & @CRLF

    ; Size the string
    $aRet = _StringSize($sString, 10, Default, Default, "Courier New")

    ; Now set the ExtMsgBox to a width which will accommodate the widest line
    _ExtMsgBoxSet(0, 0, -1, -1, 10, "Courier New", $aRet[2] + 70) ; 70 = 50 for the icon + 2 borders of 10

    ; And it fits!!!
    _ExtMsgBox(8, "OK", "About", $sString)

EndFunc   ;==>ShowAbout

In fact you can increase the ExtMsgBox width to any value larger than the string width + 70 and the UDF will adjust the width to fit. All clear?

M23

Edited by Melba23
Additional info

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Works like a champ!  Thank you

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Mbee
      By Mbee
      Honored Melba23, I once again beseech you for your assistance, please!
      I'm trying to use your wondrous StringSize() sorta in reverse: Given a font, size, weight, etc, what's the max # of characters that will fit in a given pixel width?  Of course I realize that except for mono-spaced fonts, the result will depend on a specific string itself. but I've tried to compromize by submitting a string consisting of a number of the widest character I can think of, the capital "M" (at least for ANSI Latin alphabets).
      Here's a simple app I wrote to try it..
      #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <Misc.au3> #include <String.au3> #include <StringConstants.au3> #include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <StructureConstants.au3> #include <FontConstants.au3> #include <WinAPI.au3> #include "StringSize.au3" Opt("MustDeclareVars", 0) Const $Cmy_DefaultPathFontName="Franklin Gothic Medium Cond", $Cmy_DefaultPathFontSize="9", $Cmy_DefaultPathFontWeight="400" Const $Cmy_DefaultPathFontAttrib="0" Const $Cmy_NicknameFontName="Lucida Console", $Cmy_NicknameFontSize="11", $Cmy_NicknameFontWeight="400" Const $Cmy_NicknameFontAttrib="2" Const $Cmy_SlotPathFontCode = 1, $Cmy_SlotNicknameFontCode = 2, $Cmy_MaxBtnPathTxtLen = 90, $Cmy_MaxBtnNickTxtLen = 38 Local $ResultAra[4], $MaxLenResults[4], $ErrFound Local $FontInfo[4][6] = [ [ "Pathnames in Nickname Slots", 9, 400, 0, "Franklin Gothic Medium Cond", 305], _ [ "Nicknames in Nickname Slots", 11, 400, 2, "Lucida Console", 305], _ [ "Pathname under Picture", 11, 400, 0, "Gentium Book Basic", 730], _ [ "Notify String", 11, 700, 0, "High Tower Text", 500] ] $ErrFound = False ; For $i = 0 To 3 $MaxPixelLenSoFar = 0 $MaxCharLenSoFar = 1 $TestStrSoFar = "M" $GotMaxChars = False While (Not $GotMaxChars) And (Not $ErrFound) $ResultAra = _StringSize($TestStrSoFar, $FontInfo[$i][1], $FontInfo[$i][2], $FontInfo[$i][3], $FontInfo[$i][4], $FontInfo[$i][5]) If @error = 0 Then $RequiredPixelWidth = $ResultAra[2] If $RequiredPixelWidth < $FontInfo[$i][5] Then ; If we've still got room... $TestStrSoFar &= "M" $MaxCharLenSoFar += 1 Else $ResultAra[$i] = $MaxCharLenSoFar $GotMaxChars = True EndIf Else MsgBox($MB_OK, "StringSizeMaxTest Error", "Error: _StringSize() @error Returned: " & @error) $ErrFound = True Exit EndIf WEnd Next ; For $i = 0 To 3 MsgBox($MB_OK, "StringSizeMaxTest Results", "Max # chars for " & $FontInfo[$i][0] & " == " & $ResultAra[$i] ) Next ; MsgBox($MB_OK, "StringSizeMaxTest Results", "Press OK when ready") Exit What happens is the app always reports error 3: "GetDeviceCaps failure", from StringSize(). What's that all about?
      Thanks!