11 Replies - 4710 Views - Last Post: 02 January 2013 - 05:38 PM Rate Topic: -----

#1 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

can not configure onprint() function correctly

Posted 01 January 2013 - 01:52 PM

hi
I want to configure printing in my program and I have problem in dividing my view into multiple pages to be printed
my program is a drawing program that basically contain two C-arrays one for drawn lines and the other for the curves
when I search for the printing I understand that I have to specify what will be drawn at each page by myself inside OnPrint() function. so I tried to do this. but it did not works

here what I did I only try on the lines array I was trying to print on the second page

void Cpatron1View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	Cpatron1Doc* doc = GetDocument();
    ASSERT_VALID(pDoc);
	int cur= pInfo->m_nCurPage;
	int pageHeight = pDC->GetDeviceCaps(VERTRES);
	int pageWidth = pDC->GetDeviceCaps(HORZSIZE);
	if(cur==2){
		////////////////////////////////
		for(int i=0; i< doc->mylines.GetSize() ; i++){
			
			if((abs(doc->mylines[i]->getspoints().y)< pageHeight) &&
			   (abs(doc->mylines[i]->getepoints().y)< pageHeight ) &&
			   (abs(doc->mylines[i]->getspoints().x)> pageWidth ) &&
			   (abs(doc->mylines[i]->getepoints().x)> pageWidth )
			   ){
				   if(doc->mylines[i]->type ==1 || doc->mylines[i]->type ==2 || 
	                doc->mylines[i]->type ==3  || doc->mylines[i]->type ==5 ){
				   doc->mylines[i]->drawline(pDC);
				   }
				   if(doc->basic == true &&  doc->mylines[i]->type ==4){
					   doc->mylines[i]->drawline(pDC);
				   }//basic	   
			}//if

		}//for lines
		///////////////////////////////


		////////////////////////////
	}//print

	CScrollView::OnPrint(pDC, pInfo);
}



would you please tell me how I can get the page height/width and convert it to .mm
because in my drawing I am using MM_LOMETRIC mode so I feel confused how
I compare pixels to mm.

please help me in get more understanding printing on many pages

Thanks a lot

Is This A Good Question/Topic? 0
  • +

Replies To: can not configure onprint() function correctly

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 02:04 PM

Quote

would you please tell me how I can get the page height/width and convert it to .mm


VERTSIZE and HORZSIZE which is the page height and width are already in millimeters.

If your units are already in MM_LOMETRIC, then your units are in 0.1 mm each. So to convert to millimeters, you multiply your units by 10.
Was This Post Helpful? 0
  • +
  • -

#3 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 02:32 PM

View PostSkydiver, on 01 January 2013 - 02:04 PM, said:

Quote

would you please tell me how I can get the page height/width and convert it to .mm


VERTSIZE and HORZSIZE which is the page height and width are already in millimeters.

If your units are already in MM_LOMETRIC, then your units are in 0.1 mm each. So to convert to millimeters, you multiply your units by 10.

you mean I can use it for printing height??
because I saw it but I read in msdn page
http://msdn.microsof...7(v=vs.85).aspx

that it is for Width, in millimeters, of the physical screen.
so I thought it deffer from the printing page height and I can not use it

thanks
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 02:57 PM

Yes, you can use it unless Microsoft severely screwed up and broke backward compatibility. See this KB article:

http://support.microsoft.com/kb/11863
Was This Post Helpful? 1
  • +
  • -

#5 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 05:26 PM

Finally I did get the width and height for the printer
You were right but I had to define device context for the printer which I finally know how to do it from this link:

http://support.micro...kb/162609/en-us

but I have one more question do I need to set any view port
to allow the content of the second page appear ??
because it does not appear and I did not see any mistakes in
my if conditions that I use.
can you tell me please about this ??

Thanks a lot you giave me a greate help in my project
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 05:59 PM

I don't do MFC so take what I say with a grain of salt.

The CDC passed in to you for OnPrint() should have been the printer DC as I understand the MFC documentation: http://msdn.microsof...b(v=vs.80).aspx You shouldn't have to create your own DC.

Are you sure that your drawline() calls on lines 19 and 22 are even being executed? Have you set breakpoints there to verify?

If they are being executed, you mentioned that your units for your lines is MM_LOMETRIC. Did you ensure that the printer DC's map mode got set to MM_LOMETRIC as well while you are drawing to the page?

I don't know if MFC does banding or not. If it does banding, are you sure that the lines you are rendering are within the bands?
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 06:00 PM

Hmm,

Seems an overtly complicated way to print...
with all those pointers in place....
See this tutorial for a simpler method...


Printing Tutorial

to your last question I suppose this has to do with printing your pages

for(int i=0; i< doc->mylines.GetSize() ; i++){

where do you implement StartPage and EndPage ??

I ask because its not clear

Snoopy
Was This Post Helpful? 1
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: can not configure onprint() function correctly

Posted 01 January 2013 - 06:44 PM

Exactly why I don't do MFC. MFC hides too much of the Win32 API in the hopes of making things simpler, but it actually complicates things because you now not only need to know how Win32 works, but also how MFC works.

Anyway, if I'm willing to guess that the StartPage() and EndPage() calls are done prior to calling the OnPrint() override.
Was This Post Helpful? 1
  • +
  • -

#9 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1432
  • View blog
  • Posts: 4,968
  • Joined: 19-February 09

Re: can not configure onprint() function correctly

Posted 02 January 2013 - 04:33 PM

Do you need to declare other printing functions such as onbeginPrinting and OnPrepareDC?

MFC Print Tutorial
Was This Post Helpful? 1
  • +
  • -

#10 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: can not configure onprint() function correctly

Posted 02 January 2013 - 05:17 PM

View PostSkydiver, on 01 January 2013 - 05:59 PM, said:

I don't do MFC so take what I say with a grain of salt.

The CDC passed in to you for OnPrint() should have been the printer DC as I understand the MFC documentation: http://msdn.microsof...b(v=vs.80).aspx You shouldn't have to create your own DC.

Are you sure that your drawline() calls on lines 19 and 22 are even being executed? Have you set breakpoints there to verify?

If they are being executed, you mentioned that your units for your lines is MM_LOMETRIC. Did you ensure that the printer DC's map mode got set to MM_LOMETRIC as well while you are drawing to the page?

I don't know if MFC does banding or not. If it does banding, are you sure that the lines you are rendering are within the bands?


for the onprint DC I thought it may cause the error in my calculations so I defined the printer dc by my self and use dc.SetMapMode(MM_LOMETRIC );
to set the map mode I think I will remove it and back to the original one


also for the lines I did not use break point but I think it works because I set condition inside ondraw function to prevent it from drawing if the program is printing and before I implement the code inside on print the print preview pages was empty

I do not know for the banding I will search for it
...........
I think you are right in what you said about MFC ... I think I will learn Win32 AP after I finish my project to understand how to do everything by myself

Thanks a lot

This post has been edited by Hooor: 02 January 2013 - 05:42 PM

Was This Post Helpful? 0
  • +
  • -

#11 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: can not configure onprint() function correctly

Posted 02 January 2013 - 05:28 PM

View Postsnoopy11, on 01 January 2013 - 06:00 PM, said:

Hmm,

Seems an overtly complicated way to print...
with all those pointers in place....
See this tutorial for a simpler method...


Printing Tutorial

to your last question I suppose this has to do with printing your pages

for(int i=0; i< doc->mylines.GetSize() ; i++){

where do you implement StartPage and EndPage ??

I ask because its not clear

Snoopy



I really feel lost in this printing part maybe because I am learning and implementing it at the same time
I will see your tutorial to get more understanding

do you mean set max/min page ?? if yes I did calculate it inside OnPreparePrinting function

I am trying to get the page boundaries then compare it to the lines coordinates to decide in which page it should be printed

maybe I need more time to get more understanding
Thanks a lot
Was This Post Helpful? 0
  • +
  • -

#12 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: can not configure onprint() function correctly

Posted 02 January 2013 - 05:38 PM

#define

I implement the set max and min page inside OnPreparePrinting

BOOL Cpatron1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	 CClientDC dc(this);
	  dc.SetMapMode(MM_LOMETRIC );
	  OnPrepareDC(&dc); // set up mapping mode and viewport origi
	Cpatron1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

	CRect r;
	 r.left = 0;  r.top  = 0;
     r.right = (dc.GetDeviceCaps (HORZSIZE))*10;
     r.bottom = dc.GetDeviceCaps (VERTSIZE)*10;
	// Get the whole document area
CRect DocExtent = pDoc->GetDocExtent();
    dc.LPtoDP(DocExtent);
  pInfo->SetMinPage(1);
  pInfo->SetMaxPage((ceil(double(DocExtent.Width())/r.Width())) * (ceil(double(DocExtent.Height())/r.Height()))  );
	
    return DoPreparePrinting(pInfo);
}


void Cpatron1View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
	Cpatron1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
	pDC->SetMapMode ( MM_LOMETRIC ) ;
	SetGraphicsMode(NULL,GM_ADVANCED);

	
CScrollView::OnPrepareDC(pDC, pInfo);
}




Thanks for the tutorial

Sorry all for not been answering you I had problems in my connection, I could not open the page
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1