Solved

How to print contents of a CListCtrl

Posted on 1998-04-24
5
831 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now