Calls to Bar2Dm create the barcode metafile image and the image pattern (for developers who wish to draw their own bars), returning an error code in the barcode structure in the event of an error.
Thus the following sample code shows a call to Bar2Dm followed by the code to display the metafile on the device specified by hDC within the rectangle defined by lpRect (the device context in this example is in MM_ISOTROPIC mode and uses logical units of 0.01 mm with the Y value increasing DOWN the page. Your starting point may be different. If it is, for example if your Y increases UP the page, don’t forget to adjust the calculation of iht to get a positive value - otherwise your image will be inverted!).
In this example the metafile is deleted once displayed.
lph=(HMETAFILE*)Bar2Dm(GhDlsbar2D(),lpRect,(LPBAR2D)&bc,(LPHANDLE)&hmf,(LPSTR)szPat);
iht=lpRect->bottom-lpRect->top;
iwid=lpRect->right-lpRect->left;
CopyRect(&tRect,lpRect);
LPtoDP(hDC,(LPPOINT)&tRect,2);
i=(tRect.right-tRect.left);
j=(int)((long)i*(long)iht/(long)iwid);
if
(hmf>0)
{
SaveDC(hDC);
SetMapMode(hDC,MM_ANISOTROPIC);
SetWindowOrg(hDC,0,0);
SetViewportOrg(hDC,tRect.left,tRect.top);
SetViewportExt(hDC,i,
j);
PlayMetaFile(hDC,hmf);
RestoreDC(hDC,-1);
DeleteMetaFile(hmf);
}
LPHANDLE WINAPI Bar2Dm(HANDLE hModule, LPRECT lpRectIn, LPBAR2D bc, LPHANDLE &hmf, LPSTR szPat)
where
hModule is the Module handle of the calling application.
lpRectIn is a long pointer to a rectangle that is the destination rectangle for the barcode image (with coordinates in units of 0.01 mm).
bc is a BARCODE2D structure - the LPBAR2D cast is required.
hmf is a HMETAFILEPICT handle that will contain the handle of the metafile image on return.
szPat if a long pointer to a string that receives a pattern of 0s and 1s representing spaces and bars respectively. This variable must either be declared as
char szPat[4096];
before calling the library routines - or passed as NULL – in which case no pattern is returned. For very large barcodes it may be necessary to increase the size of this buffer to 8k or even 16k. For information on the pattern string see the 2D Barcodes Help file.
More: