I create an ordinary treeview (no TVS_EDITLABELS) (does have
checkboxes to left of each item) and an ordinary window. I notice the
treeview item text is smaller than the ordinary window text, which is
fine.
I'd like to size the treeview width at runtime, based on the longest
string to be displayed as a treeview item, and taking into account the
indent width and checkbox width.
However, when I use GetTextExtentPoint32 to measure a string, it
reports the same width whether the device context is from a treeview
or ordinary window. For example, a 45 character string is reported as
extent width of 312 in either case, although the displayed size
(window text; treeview item) differs. So the treeview ends up too
wide.
Should GetTextExtentPoint32 correctly measure treeview item text, and
I'm doing something wrong? Or do I need to do something else? Maybe
fill the treeview with items, measure each item with TVM_GETITEMRECT
(just measuring the text), and then resize the treeview width?
I'm sorry I don't have a compilable code example. It's all embedded
within a large application. Here are the two cases in skeletal format.
// Measure string for ordinary window
hdc = GetDC (hwnd);
GetTextExtentPoint32 (hdc, string, chars, &size);
ReleaseDC (hwnd, hdc);
// Measure string for treeview
hdc = GetDC (htree);
GetTextExtentPoint32 (hdc, string, chars, &size);
ReleaseDC (htree, hdc);
The code is all C. I compile under windows 2000 using: gcc 3.4.2
(mingw-special)
Thanks,
Daniel Goldman