Blank printout to printer
-
Hi, Yes, following the article number 4, I use CreaterPrinterDC and initialize m_rectDraw and m_nCurPage. I do not change the page orientation nor the MAPMODE (I figure I can deal with this later IF the printed results is incorrect, yes?) Regards, jsix
Orientation should be portrait by default, but depending on MAPMODE you can probably see nothing printed. Take a look into GetDeviceCaps and pInfo. Printing is not so easy. I needed between 3 and 4 weeks to get output in three different printers correctly.
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
Orientation should be portrait by default, but depending on MAPMODE you can probably see nothing printed. Take a look into GetDeviceCaps and pInfo. Printing is not so easy. I needed between 3 and 4 weeks to get output in three different printers correctly.
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
Thanks for the tips, but actually I once trying inserting one DrawText function and it printed out the text fine, but the report was not printed. So I am guessing that the parameter for the printer were correct already and problem is somewhere else. Did you try compiling and printing my report? (I know printing is not easy. But I want to have something printed out first, correctly or not, before experimenting/learning other parameters).
-
Thanks for the tips, but actually I once trying inserting one DrawText function and it printed out the text fine, but the report was not printed. So I am guessing that the parameter for the printer were correct already and problem is somewhere else. Did you try compiling and printing my report? (I know printing is not easy. But I want to have something printed out first, correctly or not, before experimenting/learning other parameters).
I don't have VC++ installed in this laptop so it is difficult for me to compile/debug. I am just answering by heart (I can have errors). I have taken a look into your code and...
bPrintingOK &= dc.StartDoc(&docinfo);
bPrintingOK &= dc.StartPage();
((CReportView*)theApp.m_pReportView)->OnPrint(&dc, &Info);
//
//
bPrintingOK &= dc.EndPage();
((CReportView*)theApp.m_pReportView)->OnEndPrinting(&dc, &Info);Why are you mixing a dialog to set printing parameters but then printing from your other view? Wouldn't be easier to set parameters and print directly there? Chris' article is to print within a dialog. So, as you said, using a DrawText in the dialog prints it works. Sending DCs and pInfos from one place to another is not so good idea. I think the problem can be there
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
I don't have VC++ installed in this laptop so it is difficult for me to compile/debug. I am just answering by heart (I can have errors). I have taken a look into your code and...
bPrintingOK &= dc.StartDoc(&docinfo);
bPrintingOK &= dc.StartPage();
((CReportView*)theApp.m_pReportView)->OnPrint(&dc, &Info);
//
//
bPrintingOK &= dc.EndPage();
((CReportView*)theApp.m_pReportView)->OnEndPrinting(&dc, &Info);Why are you mixing a dialog to set printing parameters but then printing from your other view? Wouldn't be easier to set parameters and print directly there? Chris' article is to print within a dialog. So, as you said, using a DrawText in the dialog prints it works. Sending DCs and pInfos from one place to another is not so good idea. I think the problem can be there
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
Ah, so you can't compile it now, I see. Could you please try it later? In Chris' article, it shows that the parameters are set from CMyDialog::Print() and pass them to the view class.
OnPrint(&dc, &Info); // Call your "Print page" function
Anyway, I tried setting/calling the print dialog from within the view, same result: empty page.
-
Ah, so you can't compile it now, I see. Could you please try it later? In Chris' article, it shows that the parameters are set from CMyDialog::Print() and pass them to the view class.
OnPrint(&dc, &Info); // Call your "Print page" function
Anyway, I tried setting/calling the print dialog from within the view, same result: empty page.
My private laptop is broken and in this (work) I have not the VC++, I won't be able to compile. On the other hand... Quote from the article: In order to keep the MFC Doc/View feel I recomend providing helper callback functions OnBeginPrinting, OnEndPrinting and OnPrint similar to the CView versions. A CDC and a CPrintInfo object is passed into each of these functions. You will have to provide these functions yourself. Read carefully the introduction. These functions are to be made into the dialog. Other thing that you can make is to track down your code when you call the OnPrint of your recport view, and see if the pDC there is getting the right values (think that I guess is your problem). What are you using your ReportViewDlg for?
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
My private laptop is broken and in this (work) I have not the VC++, I won't be able to compile. On the other hand... Quote from the article: In order to keep the MFC Doc/View feel I recomend providing helper callback functions OnBeginPrinting, OnEndPrinting and OnPrint similar to the CView versions. A CDC and a CPrintInfo object is passed into each of these functions. You will have to provide these functions yourself. Read carefully the introduction. These functions are to be made into the dialog. Other thing that you can make is to track down your code when you call the OnPrint of your recport view, and see if the pDC there is getting the right values (think that I guess is your problem). What are you using your ReportViewDlg for?
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
I use the ReportViewDlg to show the report in the custom control (see number 3 in my initial post). I think the pDC is correct. Here is the function where I inserted the DrawText that prints OK.
void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC); // This does not print anythingCRect printArea;
printArea.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
pDC->DrawText("My Test is OK.", printArea, DT_NOPREFIX | DT_WORDBREAK); // This prints OKCScrollView::OnPrint(pDC, pInfo);
} -
I use the ReportViewDlg to show the report in the custom control (see number 3 in my initial post). I think the pDC is correct. Here is the function where I inserted the DrawText that prints OK.
void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC); // This does not print anythingCRect printArea;
printArea.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
pDC->DrawText("My Test is OK.", printArea, DT_NOPREFIX | DT_WORDBREAK); // This prints OKCScrollView::OnPrint(pDC, pInfo);
}Joe Smith IX wrote:
CReportDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->Draw(pDC); // This does not print anything
:doh: :doh: :confused::confused::confused: I thought you were not using Doc-View Framework.... pDoc is not the same as pDC... I think you are complicating yourself more than necessary and that you don't have your concepts clear. In the projec I downloaded there was nothing in the CTestReportView. Anyways... the second snippet prints... so what you should do is continue up from there, getting your parameters and sending them to pDC. pDoc gives no support to printing, printing is something that depends on the view. I am going to have dinner and see a film, take a look in what you are really doing, make some tests and answer me tomorrow. Maybe I won't answer till wed (depending on Football tomorrow, Spain plays in the europa's cup and I am meeting some friends to see the match with some beers :P, I know when I'm going out, but not when I'm coming back ;) :rolleyes: ) Good luck with your tests
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
Hi all, I am writing an MFC program (VC++ 6) that generates a report and supposedly able to print it out. The report is fine, but somehow it prints a blank page to the printer. After days of debugging the code, I still cannot locate the problem. This is why I can't simply post the problematic code here, I don't know which part is the problem! (Please forgive me if this is really not the right way to ask) Here I created a (much) simplified code that simulates my problem. It could be because: 1. It is SDI-based program, but I deleted the CDocument class since I don't need it. 2. I use Easy! Reports (http://www.codeproject.com/KB/miscctrl/easyreports.aspx[^]) to generate the report 3. The report is shown using a custom control (http://www.codeproject.com/KB/docview/dfv.aspx[^]) 4. Lastly, I am trying to print without using doc/view framework (http://www.codeproject.com/KB/printing/printing_wo_docview.aspx[^]) Could anyone please help me here. From what I understand, all I have to do is prepare the device context for printing (using number 4 above) and send it to the report generator function (number 2). Yet, it prints a blank page. If anyone could please take a glance and point me to the right direction, I would really appreciate it. Thanks. Download link: http://rs324.rapidshare.com/files/121245334/TestReport.zip[^]
-
That one doesn't have print preview, does it? My reports should be shown on the screen to the user, along with the option to print it out. So you can't locate the problem in the code? Regards, jsix
-
Joe Smith IX wrote:
CReportDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->Draw(pDC); // This does not print anything
:doh: :doh: :confused::confused::confused: I thought you were not using Doc-View Framework.... pDoc is not the same as pDC... I think you are complicating yourself more than necessary and that you don't have your concepts clear. In the projec I downloaded there was nothing in the CTestReportView. Anyways... the second snippet prints... so what you should do is continue up from there, getting your parameters and sending them to pDC. pDoc gives no support to printing, printing is something that depends on the view. I am going to have dinner and see a film, take a look in what you are really doing, make some tests and answer me tomorrow. Maybe I won't answer till wed (depending on Football tomorrow, Spain plays in the europa's cup and I am meeting some friends to see the match with some beers :P, I know when I'm going out, but not when I'm coming back ;) :rolleyes: ) Good luck with your tests
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
I am NOT using Doc/View framework. The view/doc I am using are the classes from the custom control I am using (number 3 in my original post). The function that prints on the screen is
void CReportView::OnDraw(CDC* pDC)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC);
}The pDC above is pointing to the screen, right? My thinking is that if I use the use printer's pDc, then it should print out on the printer, yes?
void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC);
CScrollView::OnPrint(pDC, pInfo);
} -
I am NOT using Doc/View framework. The view/doc I am using are the classes from the custom control I am using (number 3 in my original post). The function that prints on the screen is
void CReportView::OnDraw(CDC* pDC)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC);
}The pDC above is pointing to the screen, right? My thinking is that if I use the use printer's pDc, then it should print out on the printer, yes?
void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CReportDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->Draw(pDC);
CScrollView::OnPrint(pDC, pInfo);
}Quote from the file EasyReport.cpp /***************************************************************** * * method :void CEasyReport::Start(void) * * parameters : none * * returns : * * description: Start the report generation. Create all the fonts, etc * Try and get the printer device context, If no printer is set up as * the default printer on the system, create a screen device context. * ****************************************************************/ So you have to make that your code attach the printerDC you are getting to the m_printerDC, that printerDC is being used in the
CEasyReport::CEasyReport ()
, in theCEasyReport::WriteParagraph ()
, in theCEasyReport::Start ()
and theCEasyReport::End ()
. But watch out, the definition is an HDC so maybe you can not use your CDC* directly. I suggest you to read another time carefully the articles whose code you are using, go slow through the code they provided because the support for printing is in the pre-done code you are using. You just have to find your way to correctly connect them. If I were you I would try to contact with the autors ask them directly. Good Luck :)Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.