Re: DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height
- From: Wolfram Roesler <wr@xxxxxxx>
- Date: Mon, 28 Nov 2005 10:03:00 +0100
"David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote in
news:a9Hhf.24108$dO2.4974@xxxxxxxxxxxxxxxxxxxxxxxxxx:
> It seems fine.
Yes, and it works most of the time here, too; it only seems to
fail for some long strings. I should add that I'm using this to
print a rather narrow column of text, about the width of ten 'M's
in my font, and some words in my text are wider than that so they
exceed the column width.
> Could you post actual call with data of the text
> that's not printing properly? Also, how is your DC initialized (what
> font is selected into it, etc.)?
I'm doing this in the OnPrint handler function, using the pDC
passed into OnPrint by the MFC framework. The proper font has
already been selected into the DC. Apart from some looping
through the list of the strings I'm printing, and from one call
to pDC->SetBkMode(TRANSPARENT) needed because I'm printing
every other line with a gray background, I'm doing nothing
much more than shown in my previous message. The actual code
is, as usual, too long to be posted in full, but here are
the relevant lines directly from my source. This makes use
of the CGridCtrl class found on CodeGuru and CodeProject (so
there's a "CGridCtrl &Grd" in my class, plus some more members
as you'll see). You'll be able to understand what's going on
even if you're not familiar with the grid control, however.
// Print the contents of the indicated grid cell at y-position
// yPos. Returns height of output. If DoOutput==false, only
// compute height, put print nothing.
int GridPrintStateTyp::PrintCell(CDC *pDC,int Line,int Col,int yPos,bool
DoOutput) const
{
CString const Str = Grd.GetItemText(Line,Col);
if (Str.IsEmpty())
return 0;
pDC->SelectObject(Line < Grd.GetFixedRowCount()
? HdrFnt
: LstFnt);
int const xPos = ColVec[Col].xPos + MSiz.cx;
int const xSize = ColVec[Col].xSize;
COLORREF const Color = Grd.GetItemFgColour(Line,Col);
pDC->SetTextColor(Color);
UINT const Fmt = Grd.GetItemFormat(Line,Col)
| DT_NOPREFIX | DT_WORDBREAK | DT_NOCLIP;
pDC->SetTextAlign(TA_LEFT | TA_TOP | TA_NOUPDATECP);
CRect Area(0,0,xSize,0);
int const Ret = pDC->DrawText(Str,Area,DT_CALCRECT | Fmt);
if (DoOutput)
{
CRect DArea(xPos,yPos,xPos+xSize,yPos+Area.Height());
int const h = pDC->DrawText(Str,DArea,Fmt);
// Sometimes, we get h > Ret.
}
return Ret;
}
I found a Usenet posting from 1999 which described the same symptoms, but
has no solution either. Have a loot at: http://tinyurl.com/8wdks
So I unstand that, at least, it's not me who's getting something wrong
here, am I? Did anyone else ever encounter that problem?
Thanks for your help
W. Rösler
.
- References:
- DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height
- From: Wolfram Roesler
- Re: DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height
- From: David Ching
- DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height
- Prev by Date: Re: How to find Latest n files from a directory using VC++
- Next by Date: Re: Newbie Q - For Loop Continues
- Previous by thread: Re: DrawText with DT_WORDBREAK: DT_CALCRECT computes too small a height
- Next by thread: visual studio 2005, released version - nmake
- Index(es):
Relevant Pages
|