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

x
?
Solved

Printing long Document

Posted on 1999-06-23
28
Medium Priority
?
338 Views
Last Modified: 2011-10-03
I am trying to print out a long list Document by using VC++ 6.0. I use CView::OnDraw() and CDC::TextOut(x, y, string) to make the output. When the y exceeds 32768, the output will fold over to the first line( like y=0). so, the two lines will be overlapped.
By the way, I am using Win95. That won't be a problem when under WINDOW NT.
0
Comment
Question by:JHuang
[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
  • 8
  • 8
  • 6
  • +2
28 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1198324
Yes, that's one of the limitations of Windows 9x. Windows 9x implements some GDI features in 16 bits. It uses a 16-bit world coordinate system and restricts x- and y- coordinates for text and graphics to the range ±32K. Windows NT/Windows 2000 uses a 32-bit world coordinate system and allows coordinates in the range ±2 gigabytes (GB). For more information, see

Windows 95/98 Limitations on Graphics Device Interface
http://msdn.microsoft.com/library/sdkdoc/win95/chilimit_8wit.htm
0
 

Author Comment

by:JHuang
ID: 1198325
In fact, I knew the limitation you mentioned.
My question is how to resolve this problem.
Thank you any way.
0
 
LVL 3

Expert Comment

by:shaig
ID: 1198326
You will probably need to do the paging yourself.
You will ned to decide when to jump to a new page, like word does. If you really feel ike it you can also deal with viewing the tail & head of two paegs simultaniously.

0
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.

 
LVL 22

Expert Comment

by:nietod
ID: 1198327
First of all, why is your Y coordinate so large?  Are you setting the mapping mode in such a way that such large Y's might still remain on the page?  Or is that a coordinate that should be off the page, and therefore clipped out of the image, but is instead printing because of the 16 bit overflow.?

Also chensu's answer was correct.  There is no reason to reject a correct answer.  If you want more information, you can request it without rejecting.
0
 

Author Comment

by:JHuang
ID: 1198328
Hi, shaig and nietod:
Thank you for your comment. I am interest in both of your comments.
Actually, I am printing the information from a database.Some times, the list will be very long.For simple, let me show your my testing program. I use CScrollView.The mapping mode is TEXT.
//////////
CScView::Public CScrollView

////////////
CScView::OnDraw(CDC *pDC)
{
    int i=0, x=0, y=0;
    int MAX=10000;
    int hChar=80;
    CString strInt;

    for (i=0; i<MAX; ++i)
    {
        strInt.Format("i=%d". i);
        pDC->TextOut(x, y, strInt); ////Information here

        y += hChar;
    }
/////
    If you reduce MAX and let y not exceed 32K, it works fine. It's very convinent to make a print preview and printing. It will make page break itself. I only change the viewport in OnPrint() and Set MaxPageNumber.
    I wonder where I should  make the page break myself.

    I am looking forward to your answers.

     

       


0
 

Author Comment

by:JHuang
ID: 1198329
Another thing more important:
I'd like to say sorry to chensu. This's my very first to ask a question. I didn't know I could request a further comment. I only wanted another answer.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198330
No problem.

You may try this method. But I am not sure if it will work.

Set the mapping mode to MM_ANISOTROPIC so that one logical unit equals n device units (pixels) in vertical direction. n is the height of the text. Thus, hopefully, you can print up to 32767 lines of text.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1198331
I don't like that.  Your logical units are huge in size which means that if you have other things to display, they must be placed imprecisely.  In addition, if you have too many lines of text it still won't work.  (Other than those weaknesses, it is a pretty simple and elegant solution, though.)  What I would do is

int PageHeight = pDC->GetDeviceCaps(VERTRES);

 for (i=0; i<MAX; ++i)
{
     strInt.Format("i=%d". i);
      pDC->TextOut(x, y, strInt); ////Information here

      y += hChar;
      if  (y  > PageHeight)
          y = 0;
}

I use this approach myself.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198332
nietod,

Sorry but I don't understand how it solves the problem.

if (PageHeight >= 32767)
{
    // Isn't it the same?
}
else
    if (PageHeight < 32767)
    {
        // Even worse
    }

Did you miss out any important code?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1198333
I wasn't quite precise enough because of the way I handle printing.  

for (i=0; i<MAX; ++i)
{
     strInt.Format("i=%d". i);
      pDC->TextOut(x, y, strInt); ////Information here

      y += hChar;
      if  (y  > PageHeight)
     {
          y = 0;
          pDC->EndPage();
         pDC->StartPage();
      }
 }

i.e. start a new page and reset y to the top of the page.  Actually the way that is written you might loose the bottom part of the last line.  There are a variety of ways around that.  If the character height is constant, you subtract that from the pageheight when you get that at the top.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198334
But I guess JHuang also wants the screen content to be displayed correctly.
0
 

Author Comment

by:JHuang
ID: 1198335
Hi, chensu and nietod:

Thank you so much!

I haven't got chance to test the programs.

Once I test them, I will notice both of you immediately.

I may take care of the last line each page.

I can use CListView to resolve the screen problem. That's different from CView.

I mean I can use CListView to display the infor. which won't overflown, and I use CView to print the Infor.

Thank you.



Jerry
0
 

Author Comment

by:JHuang
ID: 1198336
Hi, nietod and chensu:

I just tested the programs.

1.  nietod's method works good for printing and just like chensu's statement that the preview doesn't work. So, both of you gave me much useful help. Thank you very much.
I'd like to give each of you 50 points, but I don't know how to split it. In fact, each of you deserves excellent grade. By the way, I looked up some reference books about the printing problem. To resolve this limitation of Win95 completely must use some low lever programing.

2. I tried chensu's method but failed. The MM_ANISOTROPIC mode is not as easy as MM_TEXT mode.

3. There is a  MS Access format database. I need get the data from it and process it.
I knew VB can do this easily, but I really like C's style much more VB's. For this reason, I selected VC. Would you please tell me if it's a good idea?


0
 
LVL 23

Expert Comment

by:chensu
ID: 1198337
1. If you would like to give us points, you may post another dummy question for either me or nietod to answer. And ask the customer service to reduce by (or refund) 50 points of this question.

2. What did you get?

3. It's hard to say. It also depends on other functionality of your application. I would prefer Visual C++ too.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1198338
1.  Note that this is a "form answer"
***************************************
There is no way to split points between experts.   You must choose the expert that you feel contributed the most and ask them to submit an answer (if they have not).  

If you feel two or more experts really deserve the credit you have two choices.  

First, if you have sufficient points and are feeling very generous, you can ask one expert to submit an answer to the current question, then ask additional "Dummy" questions for the other expert(s) to answer.  

Second, you can post a request at the EE customer service topic are that the points for the question be reduced or that you be given additional points in order to ask "dummy" question(s) for the other expert(s).  This should only be done in extreme cases as the customer service people are quite busy.

If you do ask dummy questions, post a comment on this message to let the experts know to look for the questions.  Also be sure to include the expert's name in the question so that other expert know what the question is for.  i.e. give the question a title like "Points for XXXXXXX"
***************************************
However since chensu, was "here first" I think that he at least deserves the points.

2.   MM_ANISOTROPIC mode is definitley not as easy to set up.  That is because you have to set the viewport and window extents and this is made even more difficult by the fact that windows 9x has the 16 bit GDI.  However it should work fine if you set the Window extent to 1440/4 ( that is 360) in both directions with SetWindowExtEx() and set the viewport extent to the number of pixels per inch divided by 4 in both directions.  That should look like

SetWindowExtEx(hDC,1440/4,1440/4,NULL);
int XRes = ,GetDeviceCaps(hDCLOGPIXELSX);
int YRes = ,GetDeviceCaps(hDCLOGPIXELSY);
SetWindowExtEx(hDC,XRes/4,YRes/4,NULL);

3.  I believe that MFC provides classes for doing this.  But I don't know any details, chensu might.
0
 
LVL 3

Expert Comment

by:darinw
ID: 1198339
Reviewing question.

darinw
Customer Service @ Experts Exchange
0
 
LVL 3

Expert Comment

by:darinw
ID: 1198340
nietod: Please post an answer for this thread.

chensu: Please post an answer for this question -
http://www.experts-exchange.com/bin/EQ.10175997

JHuang: Please refer to comments in your Customer Service question.

darinw
Customer Service @ Experts Exchange

0
 
LVL 3

Expert Comment

by:darinw
ID: 1198341
By the way, it is not possible to lower the points on a question once it has been posted and points assigned. The only way to get points back is to delete the original question.

darinw
Customer Service @ Experts Exchange

0
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 1198342
Thankyou Darin.  Wouldn't your life be easier if there was a built-in feature for spliting points?  :- )
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198343
>I believe that MFC provides classes for doing this.

Yes, you can use either MFC ODBC classes (CDatabase, CRecordset, CRecordView) or MFC DAO classes (CDaoDatabase, CDaoRecordset, CDaoRecordView) to access Microsoft Access database (.mdb). They are easy to use.

>Wouldn't your life be easier if there was a built-in feature for spliting points?

But that won't make the EE programmers' life easier. :-(
0
 

Author Comment

by:JHuang
ID: 1198344
Thank both of you.
I will ask another question "Question for chensu only".
The question is only for chensu.
The question may be not a dummy question but the points will increase to 100.
In any case, I will grade chensu.

JHuang
0
 
LVL 3

Expert Comment

by:darinw
ID: 1198345
JHuang,

There is no need to post a question for chensu. I have posted one in order to award the points and grade to him/her.

I have deleted your 'for chensu' question and accepted the answer posted by chensu to the question I posted.

darinw
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198346
darinw copied the questions JHuang posted to me. Since the question has been deleted, I am going to answer here.

>1. I'm using MFC:CDaoRecordSet to fetch data from a .MDB
file. Would you please tell me what the major difference is between DAO and ODBC? Which one will you suggest me to choose? I knew CDaoRecordSet can only access .MDB file. CRecordSet can access the other types of files, like DBASE, FOXPRO, .CSV file, even EXCELL. Is it easy to fetch data from .CSV file by using ODBC?

"DAO is, in many ways, almost a superset of the ODBC classes, containing most of the functionality of the ODBC classes and adding a great deal of its own. Unfortunately, although DAO can read ODBC data sources for which ODBC drivers are available, it's not particularly efficient at the task. For this reason, the DAO classes are best suited for programming applications that manipulate Microsoft's .mdb database files, which are created by Microsoft Access. Other file formats that DAO can read directly are those created by Fox Pro and Excel. If you are writing an application that uses an Access database and always will, you might want to use DAO for its extra functionality. If, as is more likely, your application uses another database format now or will move to another format in the future, use ODBC instead." (From the book "Special Edition Using Visual C++ 6")

>2.The following is a Window95 question. Don't let the second question bother you too much.

>If I get a new type of file (with new extention, say MyFile.AAA) in my harddisk. When I double click the file, Window95 will let me select an application to open this file. I choose NotePad. After that, any file with extention .AAA will be opened by NotePad automatically except that I run the other application first, then open the file with extention .AAA. How can I cancel this link between the file extention and the application?
I even tried to rename the file. I found I only could change the filename, not the extention. For example, I want to change MyFile.TXT to MyFile.CPP, but I got MyFile.CPP.TXT.
Could you tell me how to change a file's extention?

Windows Explorer -> Menu View/Folder Options... -> File Types tab -> Locate AAA -> Remove or Edit.

Notepad always append txt extension to the filename. Use Windows Explorer to rename it.

>Oh, my god! The fire alarm is ringing! Rush out!!!
0
 
LVL 3

Expert Comment

by:darinw
ID: 1198347
My apologies to both of you. I did not catch the fact that it was a semi-new question.

At any rate, I'd prefer that a newer question (one having sub-questions attached) be started in a new thread and end this one cleanly.

darinw
0
 

Author Comment

by:JHuang
ID: 1198348
Hi, chensu,

I have tried your methods, but failed. I even tried the comments from nietod. The characters are overlapped.

The following is my code:

pDC->SetMapMode(MM_ANISORTROPIC);
pDC->SetWindowExtEx(1, hChar);   //hChar is about 80
pDC->SetViewportEx(1, hChar);

y=0;
for (i=0; i<5000; ++i)
{
   string.Format("i=%d  y=%d", i, y);
   pDC->TextOut(0, y, string);

//   y++;  //I hope I could write code like this
         //but I only got the last line
         //I have to use
   y += hChar; //but I can't print 32767 lines.
}

I looked up the help of VC6, the explanations of SetWindowEx and SetViewPortEx are the same. I don't understand why I need set both of them.

Thank you for your help;

You may reach me at geng@usc.edu if needed.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1198349
pDC->SetMapMode(MM_ANISORTROPIC);
pDC->SetWindowExtEx(1, 1);
pDC->SetViewportEx(1, hChar);
0
 
LVL 22

Expert Comment

by:nietod
ID: 1198350
>> SetWindowEx and SetViewPortEx are the
>> same. I don't understand why I need set
>> both of them
They aren't the same.  They are seting a scale.  For get about the functions for a second.  A scale--in a single direction--requires two numbers.  Like 10 logical units is 120 pixels.  Two numbers.  Since we are dealing with 2 dimensions, we need to specify 4 numbers to set the scale.  The windows interface allows you to set these numbers seperately.   Which is a little weird.

The Window Extent (SetWindowEx())  is the logical units pair of numbers.  These logical units are the units you want to express your coordinates in.   The viewport extent (SetViewPortExt()) is the number of device units (pixels) that are to coorespond to the logical units you specify in the window extent.

Your code above still need to check if y is too large.  If y is off the page, you must not output the line.
0
 

Author Comment

by:JHuang
ID: 1198351
Hi, nietod and chensu:
    Finally, I understood the meanings of SetWindowEx and SetViewportEx. Thank you nietod.
   If I use the code "y++", I don't need check if y is too large because the maximum value of y is 5000. Using this way, I can print 5000 rows. In the other words, I can print up to 32767 rows once and the coordinates won't overflow 16 bit's capacity. That's really great to me. I think 32767 rows are enough recently. Plus, I will add the codes to check the value of y in case some special situation happens.

   I tried chensu's codes. It's better. I still can't use "y++". I didn't print out the result. I only tried the preview. I can't see a clear preview until I increase the step to "4". 4 is the minimum value. So I may print out and preview up to (32767/4) rows. Better!

  I wish both of you would have a wonderful holiday.
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 the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 …
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

660 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