Re: printing list control items in the same format as they appear in list control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: printing list control items in the same format as they appear in list control
    ... manikandan. ... there are numerous problems with this approach. ... > are using a fixed-width font (but since you are not setting the font ... > where s is the current contents of the item in the list control. ...
    (microsoft.public.vc.mfc)
  • Re: how to display
    ... I use the MS Gothic font. ... Tom ... >> By setting the font of List Control, ... >> Is there any way that i can see character of all languages in my List ...
    (microsoft.public.vc.mfc)
  • Re: Font in list control
    ... will contains 20 hex characters. ... not displaying in a standard way. ... So i think i need to set any font. ... If you want to set the font for all of list control, ...
    (microsoft.public.vc.mfc)
  • Changing row height in a CListCtrl
    ... slider. ... we're doing that by changing the font height. ... Is there perhaps another way to change the row height of a list control, ... Van Gennep - Media Automation Consulting bv ...
    (microsoft.public.vc.mfc)
  • Re: 2006 County Championship statistics - analysis by origin - format test
    ... figures untouched but adjusted the spacing of the summaries. ... Viewed in a proportional-width font (e.g. ... to be displayed in a fixed-width font, i.e. all of the characters, including ...
    (uk.sport.cricket)