Solved

Need some help wiht DrawText

Posted on 2011-09-19
11
399 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 33

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 33

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 33

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 33

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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