Solved

Need some help wiht DrawText

Posted on 2011-09-19
11
397 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 32

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 32

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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 32

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 32

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now