/*
Use in c:\xharbour\include:
harupdf.ch
hbzebra.ch
*/
#Include "Fivewin.ch"
#Include "Codebar.ch"
#define PAD_LEFT Â Â Â Â Â Â 0
#define PAD_RIGHT Â Â Â Â Â 1
#define PAD_CENTER Â Â Â Â Â 2
function Main()
  local oPrn, oFont, oPen
  Local nLinI, nColI, nLinF, nColF, oCode, nRow, nCol
  PRINT oPrn NAME "Print QrCode" PREVIEW
   DEFINE FONT oFont NAME "Arial" SIZE 0, -10 BOLD OF oPrn
   DEFINE PEN oPen WIDTH  2             OF oPrn
Â
   oPrn:SetPage(9)  // A4
   oPrn:SetPortrait() //Vertical
   PAGE
     oCode := TCodeBars():New(370,370)
     oCode:Reset()
     oCode:nHeightCode =  10
     oCode:nWidthCode  =  10
     oCode:SetType( 14 )  //CODEBAR_QRCODE
     oCode:SetCode( "your text will be written here" )
     oCode:SetFlags(0)
     oCode:Build()
     Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 500, 500)
   ENDPAGE
  ENDPRINT
  oFont:End()
  oPen:End()
return nil
CLASS TCodeBars
 Â
  DATA aTypes HIDDEN
 Â
  DATA cCode
  DATA nFlags
 Â
  DATA hCodeBar
  DATA hData
 Â
  DATA nType, nWidth, nHeight, nWidthCode, nHeightCode
  METHOD New()
  METHOD End()   INLINE  DeleteObject( ::hCodeBar ),  If( ::hData != NIL, hb_zebra_destroy( ::hData ), )
 Â
  METHOD DefError( nError )
  METHOD SetCode( cCode )
  METHOD SetFlags( nFlags )
  METHOD SetType( cnType )
  METHOD Reset()  INLINE ::End()
  METHOD Build() Â
  METHOD Rebuild() INLINE ::Reset(), ::Build()
 Â
 Â
ENDCLASS
//--------------------------------------//
METHOD New( nWidth, nHeight, nWidthCode, nHeightCode, cnType, cCode, nFlags ) CLASS TCodeBars
  DEFAULT nWidth := 200,;
      nHeight := 100,;
      nWidthCode := 1,;
      nHeightCode := 3
 Â
  ::aTypes = { { "EAN13"    , {| | hb_zebra_create_ean13( ::cCode, ::nFlags )    } },;
        { "EAN8"    , {| | hb_zebra_create_ean8( ::cCode, ::nFlags )    } },;
        { "UPCA"    , {| | hb_zebra_create_upca( ::cCode, ::nFlags )    } },;
        { "UPCE"    , {| | hb_zebra_create_upce( ::cCode, ::nFlags )    } },;
        { "ITF"     , {| | hb_zebra_create_itf( ::cCode, ::nFlags )     } },;
        { "MSI"     , {| | hb_zebra_create_msi( ::cCode, ::nFlags )     } },;
        { "CODABAR"   , {| | hb_zebra_create_codabar( ::cCode, ::nFlags )   } },;
        { "CODE11"   , {| | hb_zebra_create_code11( ::cCode, ::nFlags )   } },;
        { "CODE39"   , {| | hb_zebra_create_code39( ::cCode, ::nFlags )   } },;
        { "CODE93"   , {| | hb_zebra_create_code93( ::cCode, ::nFlags )   } },;
        { "CODE128"   , {| | hb_zebra_create_code128( ::cCode, ::nFlags )   } },;
        { "PDF417"   , {| | NIL /*hb_zebra_create_pdf417( ::cCode, ::nFlags )   */} },;
        { "DATAMATRIX" , {| | hb_zebra_create_datamatrix( ::cCode, ::nFlags ) } },;
        { "QRCODE"   , {| | hb_zebra_create_qrcode( ::cCode, ::nFlags )   } } }
 Â
  ::nWidth  = nWidth
  ::nHeight = nHeight
  ::nWidthCode  = nWidthCode
  ::nHeightCode = nHeightCode
 Â
  ::SetType( cnType )
  ::SetCode( cCode )
  ::SetFlags( nFlags )
return Self
//--------------------------------------//
METHOD Build() CLASS TCodeBars
  local hBmpOld
  local hDCDesk := GetDC( GetDesktopWindow() )
  local hDCMem  := CreateCompatibleDC( hDCDesk )
  local hBrush  := CreateSolidBrush( 0 )
  local hBack  := CreateSolidBrush( CLR_WHITE )
  ::hCodeBar = CreateCompatibleBitMap( hDCDesk, ::nWidth, ::nHeight )
  hBmpOld   = SelectObject( hDCMem, ::hCodeBar ) Â
  ::hData := Eval( ::aTypes[ ::nType ][ CODEBAR_BLOCK ] )
 Â
  ::DefError()
  FillRect( hDCMem, { 0, 0, ::nHeight, ::nWidth }, hBack )
  hb_zebra_draw( ::hData, {| x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, ::nWidthCode, ::nHeightCode )
 Â
  //DrawText( hDCMem, ::cCode, { ::nHeight - 15, 0, ::nHeight, ::nWidth }, 1 )
 Â
  SelectObject( hDCMem, hBmpOld )
  ReleaseDC( GetDesktopWindow(), hDCDesk )
  DeleteDC( hDCMem )
  DeleteObject( hBrush )
  DeleteObject( hBack )
 Â
 Â
return NIL
//--------------------------------------//
METHOD SetCode( cCode ) CLASS TCodeBars
  if ! Empty( cCode )
   if ValType( cCode ) != "C"
     cCode = cValToChar( cCode )
   endif
   ::cCode = cCode
  endif
return NIL
//--------------------------------------//
METHOD SetFlags( nFlags ) CLASS TCodeBars
  ::nFlags = nFlags
return NIL
//--------------------------------------//
METHOD SetType( cnType ) class TCodeBars
  local cType
  if ( ( cType := ValType( cnType ) )$"CN" )
   if cType == "N"
     if cnType > 0 .and. cnType < 15
      ::nType = cnType
     endif
   else
     ::nType = AScan( ::aTypes, {| a | a[ CODEBAR_TYPE ] == Upper( cnType ) } )
   endif
  else
   ::nType = DEFAULT_CODEBAR
  endif
 Â
return NIL Â
//--------------------------------------//
METHOD DefError( ) CLASS TCodeBars
  local oError
  local nError := 0
 Â
  if ::hData != NIL
   nError = hb_zebra_geterror( ::hData )
  endif
 Â
 Â
  if nError != 0
   hb_zebra_destroy( ::hData )
   oError := ErrorNew()
   oError:SubSystem  = "TCODEBARS"
   oError:SubCode   = nError
   oError:Severity   = 2
  Â
   Eval( ErrorBlock(), oError ) Â
 Â
  endif
RETURN nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( CREATECOMPATIBLEBITMAP ) // hDC, nWidth, nHeight
{
  hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}
#pragma ENDDUMP
/*
// CODEBAR.CH
#include "hbzebra.ch"
#define CODEBAR_EAN13 Â Â Â Â Â 1
#define CODEBAR_EAN8 Â Â Â Â Â 2
#define CODEBAR_UPCA Â Â Â Â Â 3
#define CODEBAR_UPCE Â Â Â Â Â 4
#define CODEBAR_ITF Â Â Â Â Â Â 5
#define CODEBAR_MSI Â Â Â Â Â Â 6
#define CODEBAR_CODABAR Â Â Â Â 7
#define CODEBAR_CODE11 Â Â Â Â 8
#define CODEBAR_CODE39 Â Â Â Â 9
#define CODEBAR_CODE93 Â Â Â Â 10
#define CODEBAR_CODE128 Â Â Â Â 11
#define CODEBAR_PDF417 Â Â Â Â 12
#define CODEBAR_DATAMATRIX Â Â 13
#define CODEBAR_QRCODE Â Â Â Â 14
#define CODEBAR_TYPE Â Â Â Â Â 1
#define CODEBAR_BLOCK Â Â Â Â Â 2
#define DEFAULT_CODEBAR Â Â Â Â CODEBAR_PDF417
*/