Re: CListBox horizontal scroll
I keep forgetting about CClientDC, it's a nice wrapper class for
GetDC()/ReleaseDC.
I like Save/RestoreDC, but it is exactly the same number of lines if you are
only selecting one thing into the DC.
Honestly you don't know when the CFont object is going to be destroyed. It
is just good practice to unselect an object out of the DC, or use
Save/RestoreDC.
AliR.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:ap3jh59b8i66kgn9376s0qdh7ju5k7ovev@4ax.com...
Why something as clumsy as GetDC?
On Fri, 4 Dec 2009 09:58:00 -0600, "AliR" <AliR@online.nospam> wrote:
GetTextExtent is the way to calculate width of a string with a specific
font.
//get a DC
CDC *pDC = GetDC();
//select the listbox font into the dc
CFont *pOldFont = pDC->SelectObject(GetFont());
//calculate the extent
CSize size = pDC->GetTextExtent(Text);
//set everything back and release the dc.
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
CClientDC dc(myctrl);
dc.Selectojbect(GetFont());
CSize size = dc.GetTextExtent(text);
Note that since the font is not being destroyed, it doesn't matter if it
is selected into
the DC, but if you want to reset, SaveDC/RestoreDC is easier to use.
I haven't written GetDC in years. It's like GetDlgItem; used rarely, and
only in very
exotic circumstances.
joe
AliR.
"Guido Franzke" <guidof73@yahoo.de> wrote in message
news:exP56gPdKHA.5568@TK2MSFTNGP02.phx.gbl...
Ok I find SetHorizontalExtent:
if (maxwidth < str.GetLength()) maxwidth=str.GetLength();
...
m_lstBox.SetHorizontalExtent(maxwidth*8);
The function wants pixels. So with Arial font, the maxwidth is too big.
Is
there an easy way to calculate the width in pixel?
Thanks,
Guido
"Guido Franzke" <guidof73@yahoo.de> schrieb im Newsbeitrag
news:ODUKOFPdKHA.1648@TK2MSFTNGP05.phx.gbl...
Hello NG,
I have a normal CListBox in my dialog. I insert text with AddString.
The
string is longer than the area to show the listbox. But I cannot
horizontal
scroll the text.
I changed the properties: horizontal scrollbar = true, vertical
scrollbar
=
true, deactivate no scrolling = true.
But I cannot horizontal scroll.
I use MSVC Developer 2003, Version 7.1.3088 and Windows XP.
Can you help me?
Thanks,
Guido
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm