Udostępnij za pośrednictwem


The SS_PATHELLIPSIS, SS_ENDELLIPSIS and SS_WORDELLIPSIS styles force static controls to disable word wrap.

I didn’t find this in the documentation for the static standard window so I figured I’d put it out in my blog in the hopes that someone else won’t get stuck on this problem.

The Windows “static” control has a number of styles that control how the control draws text.  They can be extremely useful when controlling how the control lays out text.

I recently had to write code that draws the name of an audio endpoint into a relatively size constrained static text control.  No problem, right[1]?

Speakers

Well what happens if the name of the endpoint is somewhat longer? No problem, the SS_CENTER style will wrap the words.

Headset Microphone

But sometimes the endpoint name is longer than “Headset Microphone”.  In fact the user can set the endpoint name to anything they want.

Long Headset M

Uck, that looks ugly.

Fortunately the static control has an option SS_WORDELLIPSIS that looks like it should be perfect for me:

“Windows NT or later: Truncates any word that does not fit in the rectangle and adds ellipses.”

That sounds exactly like what I want.  But when I added SS_WORDELLIPSIS, I got:

Long He...

 

 

Hold on, that’s not right, what happened to the rest of my text?

After a bit of digging, I finally figured out what was going on (by trial an error removing all the various static control styles I specified).

 

It turns out that this behavior is by design, even though I couldn’t find any documentation of it.  If you specify any of the ellipsis styles for the static control, the control becomes a single line control.  The only way I’ve found to fix this is to make the static control an owner draw control and use the DrawThemeText (or DrawText) API specifying the DT_WORDBREAK | DT_ENDELLIPSIS option.

I’ve filed a documentation bug to ensure that this gets fixed sometime in the near future.

[1] I’ve approximated what was going on in my UI with HTML tables, this is a rough approximation to show more-or-less what was going on.

ETA: Thanks to Drew and Lindseth for reviewing this.

Edit: Fixed word wrap in edit control.

Comments

  • Anonymous
    August 14, 2008
    PingBack from http://hubsfunnywallpaper.cn/?p=736

  • Anonymous
    August 14, 2008
    With my font size, the last example wraps :-) Maybe static images would be better?

  • Anonymous
    August 14, 2008
    Norman, I could have but that would have been a LOT more work for questionable benefit..  The key thing here is the doc bug in the static control documentation.

  • Anonymous
    August 14, 2008
    I also think static images would be better, because the other Norman and I surely aren't the only two who are seeing different images than you expected.  Even though I already learned that the ellipsis styles are almost always bad ideas (like non-resizable borders on windows), it still took some effort to figure out to ignore your examples and just read your text. Surely it's only a little bit of effort to capture 4 screenshots and put them in your article.  Compare that to the 110 screenshots I grabbed recently.

  • Anonymous
    August 15, 2008
    I will also call myself Norman to ask for screenshots or a better approximation of what's going on, maybe by using non-breaking spaces;