PrinterCE
SDK Special Topics
.Net CF C# or VB.Net: Printing Utilities |
PrintDC
Developer's Guide
|
PDC_PrintDlg() - Puts up "Select Printer" dialog box, returns printer DC (device context) and other printer info. | |
PDC_SetAbortProc() - Establish abort query handler which main app is responsible for. | |
PDC_StartDoc() - Start printing document | |
PDC_StartPage() - Start next page | |
PDC GDI calls to draw printing data to printer device context (see functions below) | |
PDC_EndPage() - print out this page... if more pages to print, loop back to PDC_StartPage() | |
PDC_EndDoc() - done with the document - close printer connection | |
PDC_DeleteDC() - delete Printer DC. |
Notes:
Fonts,
pens, and brushes can be created using all standard functions (such as
CreateFontIndirect(), etc).. See limitations under PDC_SelectObject()
below. | |
Bitmaps and DIBSections can be created in any desired way. PDC_CreateCompatibleDC() is then used to create a memDC, the image is selected into the printer DC via PDC_SelectObject() and “printed” via PDC_BitBlt() or PDC_StretchBlt(). | |
See example code here for code to load BMP file into a DibSection and print it - look for definition and usage of CELoadDIBSectionFromBMPFile()) | |
Note: Line
drawing is done via PDC_Polyline(). |
PrintDC
Special Functions:
The
main set of PrintDC functions are equivalent to the standard set of
Windows printing-related functions (see below). The "Special
Functions" here are setup, cleanup and status checking functions for
PrintDC.
int PDC_Init(LPTSTR
szInitString)
Handles
all startup and initialization processes for PrintDC and PrinterCE
controls. szInitString is the License Key to “unlock” PrintDC (works
as PrinterCE License Key also). Returns FALSE (0) if successful. This MUST
be the first PrintDC function called.
int PDC_UnInit()
Shuts down PrintDC and frees up resources used. Returns FALSE if no error.
void PDC_PrDialogBox(int
Operation)
Same as PrinterCE's PrDialogBox(). Pass vbDlgBoxDisable
void PDC_SetReportLevel(long
ReportLevel)
Same as PrinterCE's SetReportLevel(). Pass 0 (default) if PrintDC should
notify users of printing errors, 1 if no PrintDC error boxes, 3 for no
error dialogs and to skip Cancel Y/N dialog.
int PDC_SetScaleMode(long
value)
Same as PrinterCE's ScaleMode().
0
– no error | |
1
– User cancelled print job | |
2
– Error aborted print operation (such as image not found error) but
print job is still viable). | |
3 – Error aborted print job |
int PDC_GetVersion()
Same
as PrinterCE's GetVersion().Returns current version of PrintDC/PrinterCE
(multiplied by 1000, so v2.0 returns as 2000)
bool PDC_SetupPrinter()
bool
PDC_SetupPrinterOther()
bool
PDC_SetupPaper()
bool
PDC_SetupNetPath()
Similar
to PrinterCE's equivalent SetupPrinter(), SetupPrinterOther(), SetupPaper()
and SetupNetPath() functions. Call to
programmatically set printer, paper and connection settings, then call
PDC_PrintDlg() with PD_RETURNDEFAULTDC bitflag to skip Select Printer
dialog. These return TRUE if successful, FALSE if error is found.
PDC_SetupPrinter() has one additional parameter (OpenPort) that is not found for SetupPrinter():
SetupPrinter(long Printer,long Port, long Baudrate,bool OpenPort).
If OpenPort is TRUE, it causes the printer communication to be established before PDC_SetupPrinter() returns. If OpenPort is FALSE, the printer communication is not established until PDC_EndDoc or PDC_EndPage is called.
PrintDC's
Standard Printing Functions:
Note:
See eVC HPC & HPC/Pro documentation for full details of these
functions.
HDC PDC_CreateCompatibleDC(HDC
hdc)
BOOL PDC_DeleteDC(HDC
hdc)
int PDC_DrawText(HDC
hPrDC,LPTSTR lpString,int nCount,LPRECT lpRect,UINT uFormat) – NOTE:
PDC_DrawText, like it's WinCE counterpart DrawText() doesn’t properly
support rotated text. So be aware that any usage of DrawText will not
currently work properly for Landscape printing.
BOOL PDC_Ellipse(HDC
hdc,int nLeftRect, int nTopRect, int nRightRect,int nBottomRect)
int PDC_EndDoc(HDC
hdc)
int PDC_EndPage(HDC
hdc)
BOOL PDC_ExtTextOut(HDC
hdc,int X, int Y, UINT fuOptions, const RECT *lprc, LPTSTR lpString, UINT
cbCount,const int *lpDx) – Not supported options:
fuOptions
always 0 | |
lprc
always NULL | |
lpDx
always NULL |
int PDC_GetDeviceCaps(HDC hdc,int nIndex) – supported nIndex values:
HORZRES | |
VERTRES | |
PHYSICALWIDTH | |
PHYSICALHEIGHT | |
PHYSICALOFFSETX | |
PHYSICALOFFSETY | |
LOGPIXELSX | |
LOGPIXELSY | |
BITSPIXEL | |
PLANES | |
NUMCOLORS |
BOOL PDC_GetTextExtentExPoint(HDC hdc,LPTSTR lpszStr, int cchString,int nMaxExtent,LPINT lpnFit, LPINT alpDx, LPSIZE lpSize)
BOOL PDC_GetTextExtentPoint(HDC hdc,LPTSTR lpszStr, int cbString,LPSIZE lpSize)BOOL PDC_GetTextMetrics(HDC
hdc,LPTEXTMETRIC lptm) – fully supported
BOOL PDC_PageSetupDlg(LPPAGESETUPDLG
lppsd ) – Same as HPC/Pro PageSetupDlg. Primary difference – you do
not use CreateDC() with pDriverName, pDeviceName, pPort, and lpDevMode to
get printer DC – just access the global “PDC_hPrDC” value after
PDC_PageSetupDlg() returns. Valid “Flags” :
PSD_INTHOUSANDTHSOFINCHES | |
PSD_INHUNDREDTHSOFMILLIMETERS | |
PSD_MARGINS | |
PSD_RETURNDEFAULT |
BOOL PDC_Polyline(HDC
hdc,const POINT * lppt, int cPoints)
void PDC_PrDialogBoxText(LPTSTR MainText, LPTSTR TitleText,
LPTSTR CancelBtnText)
PD_SELECTDRAFTMODE | |
PD_SELECTLETTER | |
PD_SELECTA4 | |
PD_SELECTINFRARED | |
PD_SELECTSERIAL | |
PD_SELECTPORTRAIT | |
PD_SELECTLANDSCAPE | |
PD_INTHOUSANDTHSOFINCHES | |
PD_INHUNDREDTHSOFMILLIMETERS | |
PD_MARGINS | |
PD_RETURNDEFAULTDC |
BOOL PDC_RoundRect(HDC
hdc,int nLeftRect, int nTopRect, int nRightRect,int nBottomRect, int
nWidth, int nHeight)
HGDIOBJ PDC_SelectObject(HDC hdc,HGDIOBJ hgdiobj) – Used to select any valid HFONT, HBRUSH, HPEN, HBITMAP, or HDIBSECTION into the PrintDC DC. Note that only solid Pens and Brushes are supported.
int PDC_SetAbortProc(HDC
hdc,ABORTPROC lpAbortProc)
COLORREF PDC_SetBkColor(HDC
hPrDC,COLORREF crColor)
int PDC_SetBkMode(HDC
hPrDC,int iBkMode)
int PDC_SetROP2(HDC
hPrDC,int fnDrawMode)
int PDC_StartDoc(HDC
hdc,const DOCINFO * lpdi)
int PDC_StartPage(HDC
hdc)
BOOL PDC_StretchBlt(HDC
hdcDest,int nXOriginDest,int nYOriginDest,int nWidthDest, int nHeightDest,
HDC hdcSrc, int nXOriginSrc,int nYOriginSrc, int nWidthSrc, int nHeightSrc,
DWORD dwRop)
COLORREF PDC_SetTextColor(HDC
hPrDC,COLORREF crColor)