www.pudn.com > PKEncodeDemo.zip > Demo.frm


VERSION 5.00 
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" 
Begin VB.Form Demo  
   AutoRedraw      =   -1  'True 
   Caption         =   "demo" 
   ClientHeight    =   7944 
   ClientLeft      =   60 
   ClientTop       =   456 
   ClientWidth     =   11328 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   7944 
   ScaleWidth      =   11328 
   StartUpPosition =   3  'Windows Default 
   Begin VB.CommandButton EncodeToFile  
      Caption         =   "Encode To File" 
      Height          =   375 
      Left            =   5640 
      TabIndex        =   2 
      Top             =   7320 
      Width           =   1455 
   End 
   Begin VB.PictureBox Picture1  
      BackColor       =   &H8000000E& 
      Height          =   6735 
      Left            =   240 
      ScaleHeight     =   6684 
      ScaleWidth      =   10764 
      TabIndex        =   1 
      Top             =   240 
      Width           =   10815 
   End 
   Begin VB.CommandButton Encode  
      Caption         =   "Encode" 
      Height          =   375 
      Left            =   2880 
      TabIndex        =   0 
      Top             =   7320 
      Width           =   1455 
   End 
   Begin MSComDlg.CommonDialog fileDlg  
      Left            =   720 
      Top             =   7200 
      _ExtentX        =   847 
      _ExtentY        =   847 
      _Version        =   393216 
      InitDir         =   """""" 
   End 
End 
Attribute VB_Name = "Demo" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Dim m_image  As PTIMAGESTRUCT 
Dim DLLFileDrive As String 
Dim DLLFileDir As String 
 
 
 
Private Sub Form_Load() 
    'you can set the correct drive and dir of the dll in your computer; 
    DLLFileDrive = "d" 
    DLLFileDir = "d:\PTEnCode\SampleVB" 
  
    ChDrive DLLFileDrive 
    ChDir DLLFileDir 
     
    Dim ret As Long 
    Call PtInitImage(m_image) 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    Call PtFreeImage(m_image) 
End Sub 
 
Private Sub Encode_Click() 
    Dim ret    As Long 
    Dim Encode As PTPDF417ENCODESTRUCT 
    Call PtPDF417EncodeInit(Encode) 
     
    Dim str As String 
    str = "Hello world!" 
    'Don't use StrPtr or VarPtr Function to get the address of the string 
    'Use lstrcpy to copy the string to itself,then return the address of the string 
    Encode.pData = lstrcpy(str, str) 
    Encode.nDataLength = lstrlen(str) 
    'Dim data(10) As Byte  'encode binary data 
    'm_encode.pData = VarPtr( data(0) ) 
    'm_encode.nDataLength = 10 
 
    ret = PtPDF417Encode(Encode, m_image) 
    If ret <> PT_PDF417ENCODE_SUCCESS Then 
        MsgBox ("Encocde Error") 
        Exit Sub 
    End If 
     
    ret = PtSaveImage("tempPDF417.bmp", m_image) 
    If ret <> PT_IMAGERW_SUCCESS Then 
        MsgBox ("save file  Error") 
    Else 
        Picture1.Picture = LoadPicture("tempPDF417.bmp") 
    End If 
    Call PtFreeImage(m_image) 
End Sub 
 
Private Sub EncodeToFile_Click() 
    fileDlg.Filter = "Supported files|*.bmp;*.tiff;*.tif;*.jpg;*.png;*.gif|bmp files|*.bmp|tiff files|*.tiff;*.tif|jpeg files|*.jpg|png files|*.png|gif files|*.gif" 
    fileDlg.CancelError = False 
    fileDlg.ShowOpen 
    If Err = cdlCancel Then Exit Sub 
    Dim ret As Long 
    ret = PtLoadImage(fileDlg.fileName, m_image) 
    If ret <> PT_IMAGERW_SUCCESS Then 
       MsgBox ("fail to load the file ") 
       Exit Sub 
    End If 
     
    'The fileDlg will modify the current driver and dir . 
    ChDrive DLLFileDrive 
    ChDir DLLFileDir 
    Dim Encode As PTPDF417ENCODESTRUCT 
    Call PtPDF417EncodeInit(Encode) 
    Dim StartX, StartY As Long 
    Dim str As String 
    StartX = 10 
    StartY = 10 
    str = "This is a test of VB!" 
    'Don't use StrPtr or VarPtr Function to get the address of the string 
    'Use lstrcpy to copy the string to itself,then return the address of the string 
    Encode.pData = lstrcpy(str, str) 
    Encode.nDataLength = lstrlen(str) 
     
    ret = PtPDF417EncodeToImage(Encode, m_image, 10, 10) 
    If ret <> PT_PDF417ENCODE_SUCCESS Then 
        MsgBox ("fail to paste the image!") 
        Exit Sub 
    End If 
        
    ret = PtSaveImage("temopPDF417.bmp", m_image) 
    If ret <> PT_IMAGERW_SUCCESS Then 
        MsgBox ("save file  Error") 
    Else 
        Picture1.Picture = LoadPicture("temopPDF417.bmp") 
    End If 
    Call PtFreeImage(m_image) 
End Sub