|
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
And Preview.cpp file:
#include "Preview.h"
#include <atlstr.h>
CPreview::CPreview()
{
SetNumPages(3);
SetInitialPreviewMode(BESTVIEW::PREVIEW_MODE_WIDTH);
ZeroMemory(&CorePreviewPageSize,sizeof(CorePreviewPageSize));
CorePreviewPageSize.dwSize=sizeof(CorePreviewPageSize);
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)
{
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)
{
...
}
if(Page==2)
{
...
}
}
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
|
|
| | | |