Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need some help wiht DrawText

Posted on 2011-09-19
11
Medium Priority
?
424 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 45

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 45

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

604 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