Solved

How to print contents of a CListCtrl

Posted on 1998-04-24
5
860 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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