I won't argue about the edit control. But I'm personally not a fan of using
a listbox for this either.
I've written some stuff kind of like the output window in Visual Studio. I
guess it depends on exactly what your needs are.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
It may be that the choice of an edit control for this purpose is the wrong
choice. For
example, for logging information, a listbox is much more suitable. See,
for example, my
logging listbox control on my MVP Tips site. I spent a couple years
trying to get edit
controls to work well, and the problem you point out is just the simplest
of the problems
you will have to face. Consider not using it at all.
I've used this technique to handle output from embedded HVAC controllers,
mass
spectrographs, and liquid CO2 analyzers.
If you need to support copy, just use one of the multiselect list boxes
and limit them to
copying entire lines. It works just fine.
Is the desire to use a bitmap based on a desire to control the behavior of
the appearance
of the edit control, or is there a deep reason for it?
You can download my Logging Listbox control from my MVP Tips site, and
feel free to steal
whatever features you want from it. It has other advantages, such as if
you scroll back
it won't keep grabbing the position away from you when new material
arrives.
joe
On Wed, 30 Aug 2006 13:12:01 -0700, Roger
<Roger@discussions.microsoft.com> wrote:
"Jonathan Wood" wrote:
Wouldn't it make more sense to duplicate the font and have an owner draw
window that draws the font, and then replace that by the control? Why
would
you go to the trouble to create a bitmap?
Either way, you can select the font (probably
GetStockObject(DEFAULT_GUI_FONT)) into a DC then call GetTextMetrics.
The
height of each row will either be tmHeight, or tmHeight +
tmExternalLeading.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Roger" <Roger@discussions.microsoft.com> wrote in message
news:29074554-E30F-4D9C-93CF-0042AEEF8F1C@microsoft.com...
How would I calculate the line spacing that a CEdit control will use
to
draw
text?
What I want to do is draw text into a bitmap and then replace the
bitmap
with an edit control that looks exactly the same.
Okay, getting the TEXTMETRICS works for the vertical size, but now I see
that there is a horizontal offset that does not seem to be constant when
the
font varies and does not seem to correpond to one of the entries in
TEXTMETRIC. Any ideas on how to figure out the horizontal offset?
As far as the owner-draw solution:
I originally just tried to use an edit control (read only) to display the
text. However, my text may be updated frequently (tens of times/sec-it
comes
from an attached instrument) and I found that every time I called
SetWindowText it would scroll to the beginning. I tried various things
but
found that bitblt'ing the bitmap as I mentioned gave me the "smoothest"
look
when the text changes a lot. It worked fine until now that I am trying to
allow changing the font programmatically. Previously I just set the font
and
hard-coded the offsets I had found experimentally (admittedly not a good
solution). Do you think the owner-draw window would be a better solution?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm