Solved

How to print contents of a CListCtrl

Posted on 1998-04-24
5
845 Views
Last Modified: 2012-06-27
I have been able to get the contents of a CListCtrl to print to the printer and to the preview screen, but the font that it is using is so small, it is unreadable. I tried setting the font for the CListCtrl before printing ( in the onprint meathod). I does make the text larger, but then the area where the text prints is clipped. It seems I can only print to the top one fifth of the page if the application is at maximized before printing. If I shrink the size of the app before printing, the size of the print area also shrinks. Seems like I need to somehow tell the CListCtrl to use the whole print page. How do I do that? Not sure what all I need to set up before I print. Do you have any examples of printing a CListCtrl from a SDI application? Thanks
0
Comment
Question by:kmenzel
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1164041
goto www.codeguru.com

They have a list control code section.

That has (I believe) articlts and code on how to print a list control

0
 

Author Comment

by:kmenzel
ID: 1164042
I used the code from codeguru.com. It prints the CListCtrl ok, but when I look at the print preview, all I see is really tiny text (not readable) that takes up just the top 1/8 th of the screen.

I figured out that if I change the DPI from 300 to 75, the text becomes readable and covers the page in the print preview window. Changing the DPI seems to have no effect on the actual printout though.

How do I make the print preview window look like what will actually be printed? If nothing else, I would just like to have the text visiable and cover the entire print preview window.
0
 
LVL 3

Accepted Solution

by:
danny_pav earned 100 total points
ID: 1164043
What you need to do is change your font during printing.  During the OnDraw, you need to ask the device context hwo wide it is using CDC::GetDeviceCaps().  Then you need to get the text sizes using GetTextMetrics.  Using the sizes, you will be able to see how many characters will fit across the screen.  Because you will be able to fit eight times as many characters as you need, the print out will be 8 times too small.

Now to adjust the font, loop through several font sizes.  Use the logfont structure, and loop, incrementing the lfHeight member. Do something like this:

LOGFONT lf;
lf.lfHeight = minimum_value;
BOOL bOK = TRUE;
do
{
  <create font based on lf>
  <select font while saving old>
  <get font width, compare to desired width>
  <if font correct width, then use it>
  <if font too wide, use last ok value, bOK = FALSE>
  <set last ok value to lf.lfHeight>
  <lf.lfHeight gets incremented>
}
while (bOK);

Danny Pav


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1164044
Hey . I told you where to get all that printing code and I didn't get any points.  Then you ask another question (about the font) and someone else gets them.

Could you please put up a question so that I can get the points for directing you to the code that solved 90% of your problem?

0
 

Author Comment

by:kmenzel
ID: 1164045
Sure. I do appreciate you directing me to the codeguru site. It helped. My biggest problem was in the fonts. I actually had something working, just unreadable fonts in the preview.

Thanks again.
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question