|
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[^]
|
|
|
|
|
Hi, I will afterwards take a look to your code.
On the other hand...
1) The document should not be a problem to print or not to print.
2) If you are seeing the things in your screen, the easy reports should not be the problem
3)...
4) It is ok, you can do it.
Some check-points I faced in one project...
Are you taking care on your MAPMODE and page Orientation? (screen are pixels with a meaning, but printers... this is another world)
Are you taking care about the m_rectDraw and page offsets?
Are you using CreaterPrinterDC??
ADD: You may want to take a look here[^]
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.
modified on Monday, June 9, 2008 2:21 PM
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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);
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.
|
|
|
|
|
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);
CRect printArea;
printArea.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
pDC->DrawText("My Test is OK.", printArea, DT_NOPREFIX | DT_WORDBREAK);
CScrollView::OnPrint(pDC, pInfo);
}
|
|
|
|
|
Joe Smith IX wrote: CReportDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->Draw(pDC); // This does not print anything
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 )
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);
}
|
|
|
|
|
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 the CEasyReport::WriteParagraph () , in the CEasyReport::Start () and the CEasyReport::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.
|
|
|
|
|
Pretty cool. I dl'd and printed blank pages too! Lemme poke it with a stick...
|
|
|
|
|
You dn't want This[^] do you?
|
|
|
|
|
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
|
|
|
|
|
void CPoView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CPoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//if(pDoc->r.top>>120)
//{
InvalidateRect(pDoc->r,TRUE);
pDoc->r.left+=1;
pDoc->r.top-=2;
pDoc->r.right+=1;
pDoc->r.bottom-=2;
InvalidateRect(pDoc->r,FALSE);
//}
if(what?)
{InvalidateRect(pDoc->r,TRUE);
pDoc->r.left+=1;
pDoc->r.top+=2;
pDoc->r.right+=1;
pDoc->r.bottom+=2;
InvalidateRect(pDoc->r,FALSE);
}
CView::OnTimer(nIDEvent);
I want to make a Ellipse move up according to my path,then it arrive a line above it will change path,moving down accoring to my another path,
that control how to definite?
I am expecting your wonderfull answer!
|
|
|
|
|
And what has to do pDoc with the Ellipse?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
What about being a place to save "r"?
pDoc is supposed to be where the data have to be saved :P
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.
|
|
|
|
|
youareabigboy wrote: want to make a Ellipse move up according to my path,then it arrive a line above it will change path,moving down accoring to my another path,
that control how to definite?
Please explain yourself better
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.
|
|
|
|
|
Im not sure but do you need to CRectTracker ?
|
|
|
|
|
A program that will prompt the user to enter the
numerical grade, converts the numerical grade
to a letter grade, and displays the letter grade as
shown in the table:
NUMERICAL GRADE LETTER GRADE
greater than or equal to 95 A+
Less than 95 but greater than or equal 90 A
Less than 90 but greater than or equal 85 B+
Less than 85 but greater than or equal 80 B
Less than 80 but greater than or equal 75 C+
Less than 75 but greater than or equal 70 C
Less than 70 but greater than or equal 60 D
Less than 60 F
(it's in Visual Basic C++)
thank you
Keypi
|
|
|
|
|
visual basic or C++ ???
anyway, this is very, very basic, you should ask your teacher/instructor/tutor for some guidance.
This signature was proudly tested on animals.
|
|
|
|
|
|
what about something like :
if ( )
{
}
else if ( )
{
}
Like I said, this is really basic stuff...
This signature was proudly tested on animals.
|
|
|
|
|
Maximilien wrote:
Like I said, this is really basic stuff...
I thought he said it was C++.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|