A customer had a dialog box with two large text controls. Something like this:
IDD_DIALOG_WELCOME DIALOGEX 0, 0, 305, 280 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU FONT 8, "MS Shell Dlg", 400, 0, 0x0 BEGIN ICON IDI_MAIN, -1, 0, 0 LTEXT "Contoso Deluxe 2.0", 10, 0, 300, 24 LTEXT "Check out all the new stuff in this version.", -1, 13, 17, 290, 20 ICON IDI_WHATSNEW_EFFECTS, -1, 13, 45 LTEXT "New effects", -1, 43, 45, 270, 20 LTEXT "The super-blaster effect now blasts twice as \ much as the old blaster. Blast away with all your might!", -1, 43, 60, 225, 50 ICON IDI_WHATSNEW_STYLES, -1, 13, 115 LTEXT "New styles", -1, 43, 115, 240, 20 CONTROL "", IDC_WHATSNEW_STYLES_PLACEMENT, "Static", SS_OWNERDRAW, 43, 131, 225, 87 END
The “super-blaster” text is rather long, but at least it fits under 255 characters, which is the limit for static text controls. The text that goes into the IDC_WHATSNEW_STYLES_PLACEMENT
control is longer than 255 characters, so the dialog creates a RichEdit control at runtime, places it where the IDC_WHATSNEW_STYLES_PLACEMENT
control goes, and fills the RichEdit with the required text.
The problem the customer had was that no matter how hard they tried, they couldn’t get the RichEdit control to look the same as the static text control. In particular, they couldn’t get the line spacing to match up, which results in an ugly inconsistency within the dialog box.
Their question was “How do I get this RichEdit control to look just like a static control?”
This is another case of an XY problem. The customer has a problem X: “I have some text that is too long to go into a static control.” And the customer has an idea for a solution Y: “I know! I’ll use a RichEdit control instead of a static control, and then I’ll make the RichEdit control visually indistinguishable from a static control.” The customer then asks for help with Y, when their real problem is X.
Fortunately, since the customer explained their entire scenario, we got to see what X is, and the solution to X doesn’t involve a RichEdit control at all.
What the customer can do is change the last control to a plain text control:
LTEXT "", IDC_WHATSNEW_STYLES_TEXT, 43, 131, 225, 87
And then instead of creating a RichEdit control at runtime, positioning it, and filling it with text, they simply fill the IDC_WHATSNEW_STYLES_TEXT
with the text.
The 255-character limit the customer observed is a limit of the resource compiler, not a limit of the static text control itself. The static text control will take as much text as you give it.
0 comments