How to print contents of a CListCtrl

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
kmenzelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RONSLOWCommented:
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
kmenzelAuthor Commented:
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
danny_pavCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RONSLOWCommented:
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
kmenzelAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.