locked
Max. no. of characters in a message box line is less in Windows7 when compared with XP RRS feed

  • Question

  • Hi,

    I have noticed in Windows7, the maximum no. of characters which could be
    displayed in a messagebox line is 85 characters where in XP it was 131
    characters.

    Following is a summary when compared this with OSes,
    OS - Max. no. of characters per messagebox line.
    XP - 131
    Vista, Windows 7 - 85
    Windows2008 Server x32 and x64 - 81

    Following is a code in VB to run in Vista simulate the problem which spans
    into 3 lines, where it was expected in 2 lines.
    MsgBox ("**Maximum number of characters per messagebox line in Windows Vista
    is 85 characters.**"+CHR(13)+CHR(10)+"Expected 2nd line")

    How could this display message alignment problem be fixed?
    Is there a setting Vista and higher which preserves the messagebox
    functionality of XP?
    Please could someone advice.
    Friday, November 27, 2009 12:45 PM

All replies

  • Hi MPDamian,

    You can, of course, set the font size for message box text.  This seems to have some bearing on where it will break lines.

    1.  Right-click the desktop, choose Personalize.
    2.  At the bottom-center of the Personalization dialog, choose Window Color.
    3.  In the Window Color and Appearance dialog, choose Advanced appearance settings...
    4.  In the Item field, choose Message Box.
    5.  Change the Font and Size parameters.

    That said, though sometimes the line breaks in different places, I can't seem to get 131 characters in a MessageBox with any of the fonts I've tried.  Apparently the dialog units are being set by the choice of font.


    Edit:  I found information from someone named Raymond Chen at Microsoft:

    http://social.msdn.microsoft.com/Forums/en/windowsuidevelopment/thread/20ec772b-5686-4482-b530-f4c8522caab7

    These seem to be the pertinent excerpts (emphasis mine):

    "There is a new rule zero which is "Make the message box 278 DLUs wide if possible." (I suspect that this rule was added to make message boxes more visually appealing when given one very long line of text -- a very common scenario.) That new rule is causing your message box go to narrow. The new algorithm replaces the old algorithm; you can't get the old algorithm back."

    "It came from the design team who determined that the old algorithm did not age well given that it was written when the really cool kids had 1024x768 screens. Nowadays when screens are regularly 1600+ pixels wide, the algorithm of "Up to 60% of the screen width" results in absurdly wide message boxes. The designers decided that lines of text longer than 278 DLUs are hard to read. It's the designers' jobs to make these sorts of visual design decisions. If you don't want some black-turtleneck-wearing designer in Redmond deciding where the line breaks go, then don't use MessageBox. You don't have to convert every single MessageBox to a dialog. You can write a MessageBoxWithLineBreaksWhereISaySo function that does the layout (the DT_CALCRECT flag will be useful here), and just call that instead of MessageBox."


    -Noel
    Saturday, November 28, 2009 4:39 AM
  • Hi Noel,

    Thanks.

    The default font of the messagebox in XP is "Tahoma", 8 and after setting this in Windows7, still the the additional line breaks appear. Changing the resolution of the screen also has no effect. Anyhow the max. no. characters which could be shown in a messagebox line in Windows7 is 85.

    The other post was also interesting.
    Is it possible to give some code samples on how the customise the windows messagebox so that it would be possible set the required width of the messagebox to be as per XP behaviour, so that we need not change all the places in our applications where messageboxes are used?

    Please advice.

    Monday, November 30, 2009 7:19 AM