?
Solved

Drawtext

Posted on 2013-12-16
2
Medium Priority
?
211 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:Knut Hunstad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 8

Author Comment

by:Knut Hunstad
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:
Knut Hunstad 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

765 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