Re: printing list control items in the same format as they appear in list control
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 17 Aug 2005 23:53:28 -0400
Well, there are numerous problems with this approach. For example, it presumes that you
are using a fixed-width font (but since you are not setting the font explicitly, you are
almost certainly working with a variable-pitch font, so concepts like %25s are completely
meaningless). In fact, the whole use of things like %-35s looks like you are working on a
model 33 Teletype. Forget all of these techniques. They are obsolete, and will not work.
You have to do TextOut() operations at an appropriate x,y position to make any of this
work. Pick up a value, do a TextOut. Pick up another value, Do another TextOut. And so
on. I have no idea what m_reportlist is, but whatever it is, this is pretty meaningless
stuff. It won't work, and unless you start printing in a fixed-pitch font, it is never
going to be possible to make it work. In fact, this whole routine is largely a waste of
time and effort. It appears to be preparing a linked list of lines to print, but of course
they can never print meaningfully (and I see nothing that handles little details like
putting the headings on a second page...). Why not just do the formatting directly from
the list control in the actual print routine?
What I would do in this loop is figure out the column widths required for each column, so
I knew where to put those x coordinates. So I'd have an array which has an element for
each column. The elements start out at 0. As you iterate through the list here, pick up
the string, and, having created a DC and selected into it the font you plan to use, do
widths[i] = max(widths[i], dc.GetTextExtent(s).cx);
where s is the current contents of the item in the list control. Repeat this for each
line of your listcontrol. When you are done, you have the maximimum widths of each
column.
Then, to give column spacing, add a spacing factor, e.g.,
widths[i] += dc.GetTextExtent(CString(_T(" "))).cx;
now you can do the formatting you need.
joe
On Wed, 17 Aug 2005 12:23:23 +0530, "Manikandan" <leomani001@xxxxxxxxxxx> wrote:
>hi all,
>
>I am using the following code to print the content of the list control iems
>but the problem is when I print they are not aligned in the same format as
>they appear in the list control.
>can any one correct where I'm erring.
>
>
>BOOL CSortlistView::OnPreparePrinting(CPrintInfo* pInfo)
>
>{
>
>m_reportlist.RemoveAll( ) ;
>
>CString str, temp ;
>
>str.Format ( "%25s %25s %25s", " Filename", " Size ", " Date " ) ;
>
>m_reportlist.AddTail ( str ) ;
>
>int listcount = GetListCtrl( ).GetItemCount( ) ;
>
>for ( int i = 0 ; i < listcount ; i++ )
>
>{
>
>str.Format ( "%2d. ", i ) ;
>
>for ( int j = 0 ; j < 3 ; j++ )
>
>{
>
>temp.Format ( "%-35s", GetListCtrl( ).GetItemText ( i, j ) ) ;
>
>//str += " ";
>
>str += temp ;
>
>temp.Empty();
>
>}
>
>m_reportlist.AddTail ( str ) ;
>
>}
>
>return DoPreparePrinting(pInfo);
>
>
>//return CListView::OnPreparePrinting(pInfo);
>
>}
>
>thanks and regards
>
>manikandan
>
>
>
>
>
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- References:
- Prev by Date: Re: What is the most elegant way to convert string from unicode to ANSI?
- Next by Date: Re: how to stop a thread early in the process of closing a window
- Previous by thread: printing list control items in the same format as they appear in list control
- Next by thread: Re: printing list control items in the same format as they appear in list control
- Index(es):
Relevant Pages
|