Solved

Need some help wiht DrawText

Posted on 2011-09-19
11
403 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 34

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 34

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 34

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 34

Accepted Solution

by:
sarabande earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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 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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

734 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