Home|Download|Buy online|Affiliates|Search|Feedback|Site Map|Forum|ReviewsUse our online RSS & XML news feeds to get the latest news about our products delivered to your desktop... RSS feed    05.09.2010
Home»BestView preview library»Tips and tricks
Find out more how to use BestView...
Step by step guide

Step by step guide

It is very easy to build your own print preview with this this library! Below is the minimal set of steps you need to do:

  • Init the library with the bvInit function call. Usually it is made in the InitInstance() function of your application
  • Work - here the easiest way to create a preview window is to write your own class derived from CorePreviewCallbackWrapper. Below is an example of such class:
    #ifndef PREVIEW_H_INCLUDED
    #define PREVIEW_H_INCLUDED
    
    #include "BestView.h"
    
    class CPreview : public  BESTVIEW::CCorepreviewCallbackWrapper
    	{
    	public :
    	CPreview();
    	void CcwDrawPage(HDC ,DWORD ,BOOL );
    	};
    
    #endif  // PREVIEW_H_INCLUDED 			
    	

    And Preview.cpp file:

    	
    #include "Preview.h"
    #include <atlstr.h>
    
    CPreview::CPreview()
    	{
    	SetNumPages(3); // three pages 
    	
    	// set width as the default scale factor 
    	SetInitialPreviewMode(BESTVIEW::PREVIEW_MODE_WIDTH); 
    	
    	ZeroMemory(&CorePreviewPageSize,sizeof(CorePreviewPageSize)); 
    	CorePreviewPageSize.dwSize=sizeof(CorePreviewPageSize);
    	
    	// let the page be A4 format, i.e. 210x297 mm with 10 mm margins 
    	CorePreviewPageSize.dwPageWidth=21000;
    	CorePreviewPageSize.dwPageHeight=29700;
    	CorePreviewPageSize.dwLeftOffset=1000;
    	CorePreviewPageSize.dwTopOffset=1000;
    	CorePreviewPageSize.dwWidth=19000;
    	CorePreviewPageSize.dwHeight=27700;
    	}
    
    void CPreview::CcwDrawPage(HDC  dc,DWORD  Page,BOOL )
    	{
    	if(Page==0) // first page
    		{
    		HPEN  hPen =CreatePen(PS_SOLID,1,RGB(0,0,255));
    		HPEN  hOldPen=(HPEN)SelectObject(dc,hPen);
    		DWORD xOffset(0);  
    		for(;xOffset<=CorePreviewPageSize.dwWidth;xOffset+=1000)
    			{
    			MoveToEx(dc,xOffset,0,0);
    			LineTo(dc,xOffset,CorePreviewPageSize.dwHeight);
    			}
    		SelectObject(dc,hOldPen);
    		DeleteObject(hPen);
    		}
    		
    	if(Page==1) // second page
    		{
    		...
    		}
    
    	if(Page==2) // third page
    		{
    		...
    		}		
    			
    	}			
    		

    and in your command handler we will create a frame preview window:

    void CElementaryDlg::OnBnClickedCreatePreview()
    	{
    	CPreview * pPreview;
    	pPreview=new CPreview();
    	pPreview->CreatePreview(GetSafeHwnd(),_T("my first preview window"));
    	}	
    	

    For details please get a look at corresponding examples.

  • At the end of work the application has to call the bvTerm function to clean up all internal resources that have been allocated by the library
Valid HTML 4.01 Transitional© PVL team, 2004-2010, all rights reserved. This Web site and its entire contents are for personal use only and may not be copied, reproduced, modified, published or distributed in any way,without PVL team's prior written permission.