Click here to Skip to main content
15,887,585 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Secure ,Portable char array functions ? Pin
Luc Pattyn17-Nov-10 17:18
sitebuilderLuc Pattyn17-Nov-10 17:18 
AnswerRe: Secure ,Portable char array functions ? PinPopular
Alain Rist17-Nov-10 20:22
Alain Rist17-Nov-10 20:22 
GeneralRe: Secure ,Portable char array functions ? Pin
VC_RYK17-Nov-10 20:50
VC_RYK17-Nov-10 20:50 
AnswerRe: Secure ,Portable char array functions ? Pin
David Crow18-Nov-10 4:01
David Crow18-Nov-10 4:01 
QuestionRobocode in C++ Pin
Moak17-Nov-10 16:10
Moak17-Nov-10 16:10 
AnswerRe: Robocode in C++ Pin
Chris Losinger18-Nov-10 2:58
professionalChris Losinger18-Nov-10 2:58 
AnswerRe: Robocode in C++ Pin
«_Superman_»18-Nov-10 5:30
professional«_Superman_»18-Nov-10 5:30 
QuestionDisplaying as much text as possible PinPopular
Code-o-mat17-Nov-10 5:15
Code-o-mat17-Nov-10 5:15 
Hello folks!

Am looking for a way to do this: i have a rectangle that specifies the available space for some text. I want to display as much as possible of this text. What i mean is, if the text fits nicely in the rectangle, it should be displayed as usual, centered with wordbreaks as needed (DrawText with DT_WORDBREAK | DT_CENTER). However, when the specified rectangle is too small, the text doesn't fit into it even with wordbreaks (e.g. there are a few long words) then i'd like the text to e.g wrap around at positions where the long words would "hang out" of the rectangle.
First i tried DT_CALCRECT with DrawText to check if the text fits, if yes then i simply draw it with DrawText and go on, if not, then i tokenized the string using space as separator/delimiter. Then i iterated trough the words and checked the widths of the words and if they were too wide then i'd find the character inside the word which would hang out of the rectange and inserted a space. After this, i used DrawText again with DT_WORDBREAK to display the string. This works reasonably well but not well enough because it produces things like this:
(the text is "This is somewhat longer" and there's space for 3 lines)
---------
|This is|
|somewha|
|   t   | <- a whole word is lost ("longer")
---------
I guess one alternative i can go for is wrapping the whole string
---------
|This is|
|somewha|
|t longe| <- i see more of "longer" here
---------
but am not sure if doing this is the only/best way, and also i don't know how to wrap text aside of writing it character by character myself checking before each letter if it would hang out or not and "linefeeding" as needed + handling spaces specially (something like not display them if they are at a linebreak position). I have a faint memory from the good old times that something like DT_WORDWRAP or somesuch existed but i see no trace of it now so it's either gone or it never had existed at all and i have a few bit errors in my memory.
Any suggestions before i go into implementing the char-by-char thing? There should be a better way (i don't wish to go into dynamically selecting font sizes, let us assume the font is fixed)...

P.S: Am using GDI (CDC::DrawText and friends...)
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <

AnswerRe: Displaying as much text as possible Pin
Peter_in_278017-Nov-10 19:07
professionalPeter_in_278017-Nov-10 19:07 
GeneralRe: Displaying as much text as possible Pin
Code-o-mat17-Nov-10 22:05
Code-o-mat17-Nov-10 22:05 
AnswerRe: Displaying as much text as possible Pin
Richard MacCutchan18-Nov-10 1:28
mveRichard MacCutchan18-Nov-10 1:28 
AnswerRe: Displaying as much text as possible Pin
Luc Pattyn18-Nov-10 1:56
sitebuilderLuc Pattyn18-Nov-10 1:56 
GeneralRe: Displaying as much text as possible Pin
Code-o-mat18-Nov-10 2:00
Code-o-mat18-Nov-10 2:00 
Questionboost ::asio:async_read_until usage/question from a newbie boost user Pin
Alan Kurlansky17-Nov-10 3:17
Alan Kurlansky17-Nov-10 3:17 
Questionfont size Pin
john563217-Nov-10 2:33
john563217-Nov-10 2:33 
AnswerRe: font size Pin
Richard MacCutchan17-Nov-10 2:46
mveRichard MacCutchan17-Nov-10 2:46 
GeneralRe: font size Pin
john563217-Nov-10 2:52
john563217-Nov-10 2:52 
QuestionRe: font size Pin
David Crow17-Nov-10 3:11
David Crow17-Nov-10 3:11 
AnswerRe: font size [modified] Pin
Richard MacCutchan17-Nov-10 9:06
mveRichard MacCutchan17-Nov-10 9:06 
QuestionPlease tell me whats wrong with function? Pin
Le@rner17-Nov-10 0:42
Le@rner17-Nov-10 0:42 
AnswerRe: Please tell me whats wrong with function? Pin
Stephen Hewitt17-Nov-10 0:55
Stephen Hewitt17-Nov-10 0:55 
AnswerRe: Please tell me whats wrong with function? PinPopular
Cedric Moonen17-Nov-10 0:57
Cedric Moonen17-Nov-10 0:57 
GeneralRe: Please tell me whats wrong with function? Pin
Le@rner17-Nov-10 1:00
Le@rner17-Nov-10 1:00 
GeneralRe: Please tell me whats wrong with function? Pin
Cedric Moonen17-Nov-10 1:06
Cedric Moonen17-Nov-10 1:06 
QuestionRe: Please tell me whats wrong with function? Pin
CPallini17-Nov-10 1:21
mveCPallini17-Nov-10 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.