Solved

Drawtext

Posted on 2013-12-16
2
205 Views
Last Modified: 2013-12-16
Hi!

What precisely should Drawtext with DT_CALCRECT return? Specifications say that it returns the rectangle needed for the text, but it doesn't!

I have a fixed width font where I run DrawText/DT_CALCRECT for both the string "9" and the string "99". They return a width of 9 and 18. By drawing vertical lines I can clearly see that I need to add 7 to move a vertical line one character and 14 to move it 2 characters. So why does Drawtext return 9??? GetTextExtent and GetTextMetrics all return 9 for the character width as well.

I run this from within a routine that is called during drawing of a control, so the DC has the correct font selected already (I think).

Thanks for any help!

P.S.: This is a simplified version of my question http://www.experts-exchange.com/Microsoft/Development/Q_28317440.html, since I got no response to that so far.
0
Comment
Question by:khun
  • 2
2 Comments
 
LVL 8

Author Comment

by:khun
ID: 39721250
Oh, yes, I forgot: the space needed for the text "9" is actually only 6 and for "99" it's 13, since there is a space between each character...
0
 
LVL 8

Accepted Solution

by:
khun earned 0 total points
ID: 39721351
I found the problem. I was using this with a Stingray CGXEditControl, in it's GetCellRect. What happened was that GetDC within GetCellRect did not return the same DC as the on in Draw!

So now I calculate the necessary width in Draw() and use it in GetCellRect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now