tags:

views:

18

answers:

1

Using a CDC & CDC::DrawText(Ex), I want to render a string with a sub-string in bold

e.g:

void renderText(CDC *pDC,CString &str,int boldStart,int boldEnd)
{
...
}
  • example: renderText(pDC,"Test String",0,3) -> Test String
  • example: renderText(pDC,"Test String",5,-1) -> Test String

I assume I'll make 3 CDC::DrawText calls, but how do I know the positions to draw each string?

+1  A: 

Use CDC::GetTextExtent to get the number of pixels each piece of the string will take up, and adjust the points you pass into CDC::DrawText accordingly.

Tarydon
Thanks a lot, exactly what I needed.
John