Drawing labels

 What is the best way to draw labels of text and work with
 them ? I need to implement some operations such displaying, ,selecting and draggin a label with the mouse  whenever I have to.

Any ideas ?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

e6694811Author Commented:
Adjusted points to 65
in general:
1. Using windows to do this.
a) create MFC window class for displaying label text. This window must be selfadjusted according label text and its font.
b) window style: WS_CHILD|WS_VISIBLE|WS_BORDERc) Handle mouse activity with this window  for label selection and dragging actions.

2. drawing lables without windows
a) define CObject derived class for labels (say CLabelsObject)
b) define some methods (Draw, Move. Select and so on) for class. for class data you can define label rectangle, text and optionally text font and color
c) in the docs define array of this objects
d) in the view walk trough doc labels array and draw each one.
c) in the View mouse click handler define in which label mouse being (walk throug labels array and call PtInRect) if found call CLabelsObject.Select();
d) dragging support is same: use View OnMouseMove handler. To eliminate flickering you can use two dynamic bitmaps( for current label location backround and for label)
e6694811Author Commented:

 Hi ,migel.

 I like your second solution but there is (still) a little problem:
the size of the label rectangle  depends on the font ,the size of the font and the length of the screen.In other words ,I won't
use a label rectangle with a fixed size to store and display
the label.

In order to get the width and heigth  of a line of text using the current font I can call "GetTextExtent()"
function.This function is needed ,for example ,to verify
whether a label is selected or not.

 But take a look at the following remarks I found im the
documentation online:

" Since some devices do not place characters in regular cell arrays (that is, they carry out kerning), the sum of the extents of the characters in a string may not be equal to the extent of the string."

 In my case ,the  width of the line of text is larger tha it should


Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

usually Windows diaplay device calc TextExtents accuaretely but for some fonts we can got wrong results. The best way will be using DrawText with DT_CALCRECT parameter
e6694811Author Commented:

 It seems Ok ,but will it work for all the cases ?
I use DrawText without any problem. May be Microsoft know?
e6694811Author Commented:

 So no problem ...send an answer..
Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.