BarCodem

Calls to BarCodem 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 BarCodem 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.

 

BarCodem(0,lpRect,&logfont,(LPBAR)&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);
          }

Note that if bc.nominal_size had been set to 1, then the lpRect values would have been reset to represent the nominal size in units of 0.01 mm.

LPHANDLE WINAPI BarCodem(HMODULE hInstance, LPRECT lpRectIn, LPLOGFONT lpLogFontIn, LPBAR bc, LPHANDLE &hmf, LPSTR szPat)

where

hInstance is the instance handle of the calling application. This parameter  may be 0, in which case dBarcode creates its own using LoadLibrary.

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).

lpLogFontIn is a long pointer to a LOGFONT structure filled with information about the font with which any text will be displayed on the barcode.  The font height will be treated as Points and treated as positive.

bc is a BARCODE structure - the LPBAR cast is required.

hmf is a HMETAFILEPICT handle that will contain the handle of the image on return.

szPat is a long pointer to a string that receives a pattern of 0s and 1s representing spaces and bars respectively. This variable must be declared as
char szPat[4096];
before calling the library routines - even if you do not intend to use the pattern. If your barcodes
are not likely to exceed 12 characters in length, then the pattern string may be declared as szPat[1024].

A call to BarCodemx is almost identical, except that the hmf handle and the handle returned are of type HENHMETAFILE and provide Enhanced metafile pictures rather than standard metafile pictures. hDCRef is a reference device context for the enhanced metafile; if NULL is passed then the default device context for the system will be used to create the enhanced metafile.

More:

BarCodeh