Usando HBZEBRA.LIB para generar QRCODE

Post Reply
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Usando HBZEBRA.LIB para generar QRCODE

Post by karinha »

Master Daniel, está correcto? Gracias.

// Usando HBZEBRA.LIB para gerar QRCODE.

Code: Select all

#Include "Fivewin.ch"
#Include "Codebar.ch"

STATIC oCode, oWnd, cCode

//function Main()
FUNCTION QrCode( SEQUENC )

   local oMenu
   
   oCode := TCodeBars():New(500,500)

   // SEQUENC := ( "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" )

   IF ( SEQUENC ) = NIL

      cCode := "CODIGO INVALIDO OU VAZIO..."

      ? cCode

      RETURN NIL

   ENDIF

   cCode := ALLTRIM( SEQUENC )

   // Direto sem MENU
   // oMenu = BuildMenu()  // nao quero menu
   
   //DEFINE WINDOW oWnd menu oMenu
   //-> Invisibilizo a Janela
   DEFINE WINDOW oWnd FROM -10, -10 TO -5, -5


   // ATIVO, APENAS PARA GERAR SEM MOSTRAR
   ACTIVATE WINDOW oWnd ; // nCode     // cCode
      ON INIT( BuildCode( CODEBAR_QRCODE, cCode  ), oWnd:End() )

RETURN NIL

/*
function BuildMenu()
   
   local oMenu

   menu oMenu
      menuitem "CodeBar"
        menu
           menuitem "EAN13"      action( BuildCode( CODEBAR_EAN13,      "477012345678" ) )
           menuitem "EAN8"       action( BuildCode( CODEBAR_EAN8,       "1234567" ) )
           menuitem "UPCA"       action( BuildCode( CODEBAR_UPCA,       "01234567891" ) )
           menuitem "UPCE"       action( BuildCode( CODEBAR_UPCE,       "123456" ) )
           menuitem "CODE39"     action( BuildCode( CODEBAR_CODE39,     "ABC123" ) )
           menuitem "ITF"        action( BuildCode( CODEBAR_ITF,        "1234", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "MSI"        action( BuildCode( CODEBAR_MSI,        "1234567", HB_ZEBRA_FLAG_CHECKSUM ) )
           menuitem "CODABAR"    action( BuildCode( CODEBAR_CODABAR,    "40156", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "CODE93"     action( BuildCode( CODEBAR_CODE93,     "ABC-123" ) )
           menuitem "CODE11"     action( BuildCode( CODEBAR_CODE11,     "12", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "CODE128"    action( BuildCode( CODEBAR_CODE128,    "Code 128") )
           menuitem "PDF417"     action( BuildCode( CODEBAR_PDF417,     "PDF17" ) )
           menuitem "DATAMATRIX" action( BuildCode( CODEBAR_DATAMATRIX, "DataMatrix :)") )

           //menuitem "QR-CODE"    action( BuildCode( CODEBAR_QRCODE,     "http://danielgarciagil.com/") )
                                 // nCode            // cCode
           menuitem "QR-CODE"    ;
              action( BuildCode( CODEBAR_QRCODE,     "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" ) )

        endmenu
   endmenu
   
return oMenu
*/

function BuildCode( nCode, cCode, nFlags )

   local oVent
   local hDC := oWnd:GetDC()
   local oPrn
   LOCAL hDib
   LOCAL hBmp := CreateCompatibleBitmap( hDC, 150, 50 )  // 150, 50
   LOCAL hOldBmp := SelectObject( hDC, hBmp )

   default nFlags := 0
   
   oCode:Reset()

   if nCode < CODEBAR_PDF417
      oCode:nHeightCode = oCode:nHeight - 50
      oCode:nWidthCode  = 1.5
   else

      if nCode == CODEBAR_QRCODE

         oCode:nHeightCode =  3   // altura  // 7.23 PAGINA CHEIA
         oCode:nWidthCode  =  3   // Largura // 7.23 PAGIAN CHEIA

      else

         oCode:nHeightCode = 3
         oCode:nWidthCode  = 1

      endif
   endif

   oCode:SetType( nCode )
   oCode:SetCode( cCode )
   oCode:SetFlags( nFlags )
   oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   hDib := DibFromBitmap( oCode:hCodeBar )

   DibWrite( "QRCODE.BMP" , hDib )

   // HBZEBRA, SOMENTE GERA EM *.BMP, uma pena.
   // DibWrite( "QRCODE.JPG" , hDib )  // mesmo tamanho que o *.BMP ??

   GloBalFree( hDib )


   // SE EU QUISER IMPRIMIR.
   /*
   PRINT oPrn NAME "Qr code print" PREVIEW
      PAGE
         *Drawbitmap( oPrn, oCode:hCodeBar, 100, 100)
         *oPrn:SayImage( 100, 100, oCode:hCodeBar, 300, 300 )
         *oPrn:SayBitmap( 100, 100, oCode:hCodeBar, 300, 300 )

         //Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         //oPrn:Say( 500, 100, "This is a test" )


      ENDPAGE
   ENDPRINT
   */
   
   oWnd:ReleaseDC()
   
return nil   

// CLASSE

/*
#include "fivewin.ch"
#include "codebar.ch"
*/

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
*/

// FIM DO PROGRAMA - 26/08/2015
 
saludos.
João Santos - São Paulo - Brasil
User avatar
mastintin
Posts: 1502
Joined: Thu May 27, 2010 2:06 pm

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by mastintin »

Karinha ....

Code: Select all

  ...
 oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   hDib := DibFromBitmap( oCode:hCodeBar )

   DibWrite( "temp.BMP" , hDib )
  
  // añadido para grabar en otros formatos 
  oGbmp:= GDIBmp():new( "temp.BMP" )
  oGBmp:Save( "qrcode.jpg" )    // valido a jpg,gif,tif,png
  oGbmp:end()
  ferase( "temp.bmp")
   ......

 
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by karinha »

mastintin wrote:Karinha ....

Code: Select all

  ...
 oCode:Build()
   
   DrawBitmap( hDC, oCode:hCodeBar, 0, 0 )

   hDib := DibFromBitmap( oCode:hCodeBar )

   DibWrite( "temp.BMP" , hDib )
  
  // añadido para grabar en otros formatos 
  oGbmp:= GDIBmp():new( "temp.BMP" )
  oGBmp:Save( "qrcode.jpg" )    // valido a jpg,gif,tif,png
  oGbmp:end()
  ferase( "temp.bmp")
   ......

 
Gracias Master, perfecto!!
João Santos - São Paulo - Brasil
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by karinha »

Versão final - Versión final.

Code: Select all

// Gerador de QrCode - Modificado em: 31/08/2015 By Joao Santos.
// Usando HBZEBRA.LIB para gerar QRCODE com FWHX1505 Maio de 2015.
// kmt_karinha@pop.com.br / joao@pleno.com.br - Modificado: 02/09/2015

// www.fivewin.com.br - gilmer@fivewin.com.br - Representante no Brasil.

#Include "Fivewin.ch"
#Include "Codebar.ch"

STATIC oCode, oWnd, cCode

/* // Comentado, apenas para testes
FUNCTION Main() // Imitando um programa DOS

  MEMVAR  SEQUENC
  PRIVATE SEQUENC

  SEQUENC := SPACE(500)

  SEQUENC := MemoRead( "SEQSAT.TXT" )

  ? SEQUENC  // CHEGOU CORRETO.

  // RUN QRCODE SEQUENC  // OU &SEQUENC  // MODO CONSOLE/CONSOLA
  QrCode( SEQUENC )

RETURN NIL
*/

// VEJA, AQUI TEM QUE CHEGAR: SEQUENC, NAO PODE TER OUTRO NOME
FUNCTION QrCode( SEQUENC )  // CHEGOU CORRETO

   LOCAL oMenu

   cCode := SPACE(500)
   
   oCode := TCodeBars():New(500,500)

   //SEQUENC := ( "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" )

   // VINDO DO PROMPT - VAZIO OU COM NOME, TEM QUE ESCOLHER O ARQUIVO.
   IF ( SEQUENC ) = NIL       .OR. ( SEQUENC ) = "FA1.TXT" .OR. ;
      ( SEQUENC ) = "FA2.TXT" .OR. ( SEQUENC ) = "FA3.TXT" .OR. ;
      ( SEQUENC ) = "FA4.TXT" .OR. ( SEQUENC ) = "FA5.TXT" .OR. ;
      ( SEQUENC ) = "FA6.TXT" .OR. ( SEQUENC ) = "FA7.TXT" .OR. ;
      ( SEQUENC ) = "FA8.TXT" .OR. ( SEQUENC ) = "FA9.TXT"

      //cCode := MemoRead( cGetFile( "FA1.TXT", "Por favor, selecione um *.TXT para gerar o QRCODE" ). )

      cCode := MemoRead( "FA1.TXT" )
   
      IF EMPTY( cCode )

         cCode := "CODIGO INVALIDO OU VAZIO..."

         ? cCode

         RETURN NIL

      ENDIF

      MsgWait( "GERANDO QRCODE... VIA ARQUIVO...", ;
               "AGUARDE UM MOMENTO POR FAVOR... ", 2.5 )

   ELSEIF ( SEQUENC ) = "SEQSAT.TXT"

      cCode := MemoRead( "SEQSAT.TXT" )
   
      IF EMPTY( cCode )

         cCode := "CODIGO INVALIDO OU VAZIO..."

         ? cCode

         RETURN NIL

      ENDIF

      MsgWait( "GERANDO QRCODE... VIA SEQSAT.TXT", ;
               "AGUARDE UM MOMENTO POR FAVOR... ", 2.5 )

   ELSE // VINDO DO PROGRAMA - ESTA GERANDO CORRETAMENTE - 02/09/2015

         MsgWait( "GERANDO QRCODE... VIA PROGRAMA...", ;
                  "AGUARDE UM MOMENTO POR FAVOR...  ", 2.5 )

      cCode := ALLTRIM( SEQUENC )

   ENDIF

   // Direto sem MENU
   // oMenu = BuildMenu()  // nao quero menu
   
   //DEFINE WINDOW oWnd menu oMenu
   //-> Invisibilizo a Janela
   DEFINE WINDOW oWnd FROM -10, -10 TO -5, -5


   // ATIVO, APENAS PARA GERAR SEM MOSTRAR
   ACTIVATE WINDOW oWnd ; // nCode     // cCode
      ON INIT( BuildCode( CODEBAR_QRCODE, cCode  ), oWnd:End() )

RETURN NIL

/*
function BuildMenu()
   
   local oMenu

   menu oMenu
      menuitem "CodeBar"
        menu
           menuitem "EAN13"      action( BuildCode( CODEBAR_EAN13,      "477012345678" ) )
           menuitem "EAN8"       action( BuildCode( CODEBAR_EAN8,       "1234567" ) )
           menuitem "UPCA"       action( BuildCode( CODEBAR_UPCA,       "01234567891" ) )
           menuitem "UPCE"       action( BuildCode( CODEBAR_UPCE,       "123456" ) )
           menuitem "CODE39"     action( BuildCode( CODEBAR_CODE39,     "ABC123" ) )
           menuitem "ITF"        action( BuildCode( CODEBAR_ITF,        "1234", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "MSI"        action( BuildCode( CODEBAR_MSI,        "1234567", HB_ZEBRA_FLAG_CHECKSUM ) )
           menuitem "CODABAR"    action( BuildCode( CODEBAR_CODABAR,    "40156", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "CODE93"     action( BuildCode( CODEBAR_CODE93,     "ABC-123" ) )
           menuitem "CODE11"     action( BuildCode( CODEBAR_CODE11,     "12", HB_ZEBRA_FLAG_WIDE3 ) )
           menuitem "CODE128"    action( BuildCode( CODEBAR_CODE128,    "Code 128") )
           menuitem "PDF417"     action( BuildCode( CODEBAR_PDF417,     "PDF17" ) )
           menuitem "DATAMATRIX" action( BuildCode( CODEBAR_DATAMATRIX, "DataMatrix :)") )

           //menuitem "QR-CODE"    action( BuildCode( CODEBAR_QRCODE,     "http://danielgarciagil.com/") )
                                 // nCode            // cCode
           menuitem "QR-CODE"    ;
              action( BuildCode( CODEBAR_QRCODE,     "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw==" ) )

        endmenu
   endmenu
   
return oMenu
*/

function BuildCode( nCode, cCode, nFlags )

   local oVent, oGbmp
   local hDC := oWnd:GetDC()
   local oPrn
   LOCAL hDib
   LOCAL hBmp := CreateCompatibleBitmap( hDC, 150, 50 )  // 150, 50
   LOCAL hOldBmp := SelectObject( hDC, hBmp )

   default nFlags := 0

   // apaga anterior

   IF FILE( "QRCODE.BMP" )

      FERASE( "QRCODE.BMP" )

   ENDIF

   // apaga anterior
   IF FILE( "QRCODE.JPG" )

      FERASE( "QRCODE.JPG" )

   ENDIF
   
   oCode:Reset()

   if nCode < CODEBAR_PDF417

      oCode:nHeightCode = oCode:nHeight - 50
      oCode:nWidthCode  = 1.5

   else

      if nCode == CODEBAR_QRCODE

         oCode:nHeightCode =  3   // altura  // 7.23 PAGINA CHEIA
         oCode:nWidthCode  =  3   // Largura // 7.23 PAGIAN CHEIA

      else

         oCode:nHeightCode = 3
         oCode:nWidthCode  = 1

      endif

   endif

   oCode:SetType( nCode )
   oCode:SetCode( cCode )
   oCode:SetFlags( nFlags )
   oCode:Build()

                                                // TAMANHO
   DrawBitmap( hDC, oCode:hCodeBar, 500, 500 )  // 500 X 500

   hDib := DibFromBitmap( oCode:hCodeBar )

   //DibWrite( "TEMP.BMP" , hDib )
   DibWrite( "QRCODE.BMP" , hDib )  // voltando a .BMP Edgard

   // añadido para grabar en otros formatos - Mister Mastintin
   oGbmp:= GDIBmp():new( "QRCODE.BMP" )  // TEMP;JPG
   oGBmp:Save( "QRCODE.JPG" )    // valido a jpg,gif,tif,png
   oGbmp:End()

   /*
   FERASE( "TEMP.BMP")
   */

   GloBalFree( hDib )


   // SE EU QUISER IMPRIMIR.
   /*
   PRINT oPrn NAME "Imprimir QrCode" PREVIEW
      PAGE
         *Drawbitmap( oPrn, oCode:hCodeBar, 100, 100)
         *oPrn:SayImage( 100, 100, oCode:hCodeBar, 300, 300 )
         *oPrn:SayBitmap( 100, 100, oCode:hCodeBar, 300, 300 )

         //Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         Drawbitmap( oPrn:hDCOut, oCode:hCodeBar, 200, 400)

         //oPrn:Say( 500, 100, "This is a test" )


      ENDPAGE
   ENDPRINT
   */
   
   oWnd:ReleaseDC()
   
return nil   

// CLASSE

/*
#include "fivewin.ch"
#include "codebar.ch"
*/

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
*/

// FIM DO PROGRAMA
 
João Santos - São Paulo - Brasil
jesusdelamora
Posts: 20
Joined: Fri Apr 25, 2014 3:05 pm

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by jesusdelamora »

¿ Donde puedo descargar HBZEBRA.LIB ?
User avatar
Baxajaun
Posts: 853
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by Baxajaun »

Hola Jesús,

si descargas Harbour de su sitio web, encontrarás la librería en directorio contrib. Y si descargas Harbour desde este foro, la encontrarás en el directorio lib.

Saludos
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Usando HBZEBRA.LIB para generar QRCODE

Post by karinha »

João Santos - São Paulo - Brasil
Post Reply