Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to print contents of a CListCtrl

Posted on 1998-04-24
5
Medium Priority
?
903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

722 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