?
Solved

Need some help wiht DrawText

Posted on 2011-09-19
11
Medium Priority
?
414 Views
Last Modified: 2012-05-12
Hello,
I would like to print the content of a editbox (str_Betreff) in my letter-print-program.
The content of the editbox could be very large and I could need 2 pages for the print.
I use DrawText to printout the content of the editbox.
But how can I break the text….if  the text  is to long for the first page.
In this case I have a max of –2840  for rect.bottom of the first page.


 if(rect_help<-2840)I would like to start a new page and print out the rest of the editbox

How can I do this? I hope you can understand my question.
500 points with a solution.
Best regards,
Thomas




CString str_Betreff_help;
      
m_Edit_Betreff.GetWindowText(str_Betreff);//read editbox
str_Betreff_help=str_Betreff;

int stelle=0;
int Anzahl_returns=0;


//-------------- I could the number of returns in the editbox -------------
for(int i=0;i<=120;i=i+1)
{
  stelle= str_Betreff_help.Find("\r\n");
  if(stelle>0)
  {
     Anzahl_returns=Anzahl_returns+1;
     str_Betreff_help.Delete(stelle);
  }
}
//-------------------------------------------------------
  int rect_help=(30*Anzahl_returns)-2*(30*Anzahl_returns)+(-1050);

  CRect rect;
  rect.left = 155;
  rect.top  = -1050;
  rect.right = 1300;     //max 1. rect.bottom= -2840
  rect.bottom= (30*Anzahl_returns)-2*(30*Anzahl_returns)+(-1050);
  if(rect.bottom<-2840)rect.bottom=-2840;
     
  pDC->SelectObject(m_fontUeberschrift12);
  pDC->DrawText(str_Betreff,-1,&rect,DT_WORDBREAK);

             
if(rect_help<-2840)
{
     start a new page and print out the rest.
.    here I would like to print the rest of str_Betreff
.
.
0
Comment
Question by:tsp2002
[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
  • 5
  • 4
  • 2
11 Comments
 
LVL 35

Expert Comment

by:sarabande
ID: 36566130
you need to determine the height of 1 line and then calculate how many lines fit into the first page.

as far as i see the height is 30 and you start from -1050. hence the pixels for the text on the first page is (2840-1050)/30  what is 59.

so in your first loop where you count the linefeeds you need to make a split of the CString variable when the count reached 59.

Sara

by the way the statement

rect.bottom= (30*Anzahl_returns)-2*(30*Anzahl_returns)+(-1050);

easier can be written as

rect.bottom= 1050 - (30*Anzahl_returns);
0
 

Author Comment

by:tsp2002
ID: 36566230
Hi Sara,
yes...I had the same thought to do this with counting.
I just was wondering if there is any function like
DT_WORDBREAK etc. for an Editbox/CString  that will do the trick in a magic?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 36566381
you should see that pages is a printer-only issue while the edit box is a control which never was divided into two parts.

you wouldn't need a loop for counting lines cause there is a CEdit::GetLineCount member function. you also can get the index where the split must be done by m_edit.LineIndex(60). that would return the begin of line 60 of your edit control and you could fill two CString variables from str_Betreff.Left(line60) and strBetreff.Mid(60).

Sara
0
Independent Software Vendors: 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!

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36566494
@Sara
by the way the statement

rect.bottom= (30*Anzahl_returns)-2*(30*Anzahl_returns)+(-1050);

easier can be written as

rect.bottom= 1050 - (30*Anzahl_returns);


Are you certain ?
0
 

Author Comment

by:tsp2002
ID: 36566552
how should I use the LineIndex...?
0
 

Author Comment

by:tsp2002
ID: 36566564
@Sara
by the way the statement

rect.bottom= (30*Anzahl_returns)-2*(30*Anzahl_returns)+(-1050);

easier can be written as

rect.bottom= 1050 - (30*Anzahl_returns);

Are you certain ?
 No Andy that was wrong... it must be a minus digit !
0
 
LVL 35

Expert Comment

by:sarabande
ID: 36566596
yes it is

rect.bottom= -1050 - (30*Anzahl_returns);

i made too much copy-paste

Sara

0
 

Author Comment

by:tsp2002
ID: 36566655
can you give me an example how I should use lineindex
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36566760
:-)
0
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 36566906
the LineIndex would return the character index where the line begins in the edit field.

so by

int line60 = m_edit.LineIndex(59);  // seems the line number is 0-based

you would get the position where to split the multline edit string.

Sara
0
 

Author Closing Comment

by:tsp2002
ID: 36571976
Thank you Sara
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 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