i have a cstring.If i press a print button in the dialog box,i want this string to be printed to the default printer connected to the system.Can anyone pleae tell me how to do this.
Hi, It's not that simple, you better read it on a manual of Visual C++ this is only a breif explanation of how the print job works but it's very difficult to explain it all.
When you create A Single document or a multi document project the wizard creates for you the following functions
BOOL ClassViewName::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
void ClassViewName::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
void ClassViewName::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
And by the classwizard you have to create the
void CClassView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrint(pDC, pInfo);
}
by your own.
Now the OnPreparePrinting carries out all the settings for the printer like on which printer you wanto to go ect..
the OnBeginPrinting all ready has CDC handle to the printer, here you can set font with textmetrix ect.. and even page brakes ....
the OnPrint function consider your document a "1 page document" and you have to call it for all the pages. Using function as TextOut or similar you can print informations.
I have created a function of my own that draws a text of one line in a specific rectangle the function is this ne
void DrawTextInRect(int Left,int Top,int Right,int Bottom,CString& TBuffer,int Para,CDC* pDC)
{
int DtParam= DT_SINGLELINE|DT_NOPREFIX;
if (Para!=-1)
DtParam= DtParam | Para ;
CRect Rect(Left,Top,Right,Bottom);
//hRgn.CreateRectRgnIndirect((RECT FAR *)&Rect);
pDC->DrawText(TBuffer.GetBuffer(1),-1,(RECT FAR *)&Rect,DtParam);
}
if you put the definition in a header file the body in your source file and call it from the print function this will print the string.
Here is an explantion of the seven parameters.
The first parameter you specify the x cordinator of the left corner of the box, the second parameter you specify the y cordinator of the left corner of the box, the third and forth parameters are the x and y cordinators of the bottom corner the fifth parameter is the string the sixth parameter can be set to -1 and finaly the seventh parameter is the CDC pointer of the print function.
Hope this will help Alex
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.