Imports System.Runtime.InteropServices

Public Class Form1
    '1. Printable Data Handling APIs
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub ClearSpool()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CompressedBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub ControlCommand(ByVal Cmds As Byte(), ByVal iLength As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub DataMatrixSaveSpool(ByVal width As Integer, ByVal height As Integer, ByVal moduler As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GS1DatabarSaveSpool(ByVal type As Integer, ByVal n As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub LoadLogoSaveSpool(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub MaxicodeSaveSpool(ByVal mode As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub MicroPDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal row As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub NormalBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub OneDimensionBarcodeSaveSpool(ByVal ucBarcodeType As Byte, _
               ByVal ucBarWidth As Integer, ByVal ucBarHeight As Integer, ByVal HRI_On As Boolean, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DotFeed(ByVal dots As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawBox(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawEllipse(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal A_length As Integer, ByVal B_length As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawLine(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal iX2Pos As Integer, ByVal iY2Pos As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_LineFeed(ByVal lines As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Newline()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Print()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Print_StandardMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal level As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintData()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintDotFeed(ByVal dots As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintLineFeed(ByVal lines As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function PrintSpool(ByVal bDelete_Spool As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Function PrintSpoolForTTF(ByVal sData As String, ByVal iXFontSize As Byte, ByVal iYFontSize As Byte) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub QRCodeSaveSpool(ByVal version As Integer, ByVal level As Char, ByVal moduler As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub TextSaveSpool(ByVal textData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub TruncatedPDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal level As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub

    '2. Printer Mode & Setting APIs 
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetPrinterModelName()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetFirmwareVersion()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetPrinterStatus(ByVal iTimeoutMsec As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetPrinterStatusEx(ByVal iTimeoutMsec As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitLineSpace()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitPageMode(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitPrinterStatus()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_ClearCurrentData()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetArea(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetDirection(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetPosition(ByVal iXPos As Integer, ByVal iYPos As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetStandardMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetAbsPosition(ByVal distance As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetCharCodeTable(ByVal n As Integer, ByVal MCU As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetCharSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetFontForTTF(ByVal ttfFile As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetFontSize(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetLineSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetPageMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetTextAlignment(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetTextStyle(ByVal underline As Integer, ByVal emphasize As Boolean, ByVal width As Integer, ByVal height As Integer, ByVal reverse As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetUpsideDown(ByVal setting As Boolean)
    End Sub

    '3. Misc Device Handling APIs
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CancelMSRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ClosePrinterConnection() As Boolean
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CancelSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ConnectSerialPrinter(ByVal sPortName As String, ByVal iBaudRate As Integer, ByVal iTimeoutMsec As Integer, ByVal bProtocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ConnectUSBPrinter(ByVal iTimeoutMsec As Integer, ByVal Protocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ConnectWirelessPrinter(ByVal sIP_ADDR As String, ByVal iPortNum As Integer, ByVal iTimeoutMsec As Integer, ByVal bProtcol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CutPaper(ByVal mode As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub EnterMSRMode(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub EnterSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub FeedToMark()
    End Sub

    <DllImport("user32.dll")> _
   Private Shared Function RegisterWindowMessage( _
        ByVal lpByVal As String) As UInteger
    End Function


    Private WM_RECEIVE_MSG As Integer = RegisterWindowMessage("WOOSIM_PRT_OK")

    '***************************************************************************
    '           CONST DEFINE
    '***************************************************************************
    Private Const DATA As Integer = &H44
    Private Const STATUS_ANSWER As Integer = &H53

    ' Return Message 
    Private Const SUCCESS As Integer = 1
    Private Const ALREADY_OPENED As Integer = -1
    Private Const TIMEOUT As Integer = -7
    Private Const NOT_OPEN_THE_PORT As Integer = -11

    'Serial & Bluetooth
    Private Const UNABLE_TO_OPEN_THE_PORT As Integer = -2
    Private Const UNABLE_TO_CONFIGURE_THE_SERIAL_PORT As Integer = -3
    Private Const UNABLE_TO_SET_THE_TIMEPIT_PARAMETERS As Integer = -4

    'Wireless
    Private Const SOCKET_ERROR As Integer = -2
    Private Const CONNECT_FAIL As Integer = -3

    'USB
    Private Const UNABLE_TO_MAKE_CONNECTION As Integer = -2
    Private Const UNABLE_TO_GET_INFOMATION As Integer = -3
    Private Const NOT_WOOSIM_PRINTER As Integer = -4

    'barcode type
    Enum Barcode
        UPCA = 65
        UPCE
        EAN13
        EAN8
        CODE39
        ITF
        CODABAR
        CODE93
        CODE128
    End Enum

    'Printer page width
    Enum PageWidth
        _1INCH = 192
        _2INCH = 384
        _3INCH = 576
        _4INCH = 768
    End Enum

    'MCU
    Enum MCU
        M16C
        ARM
        RX
    End Enum

    'Text width size
    Enum TextWidth
        TEXTWIDTH01
        TEXTWIDTH02
        TEXTWIDTH03
        TEXTWIDTH04
        TEXTWIDTH05
        TEXTWIDTH06
        TEXTWIDTH07
        TEXTWIDTH08
    End Enum

    'Text height size
    Enum TextHeight
        TEXTHIGHT01
        TEXTHIGHT02
        TEXTHIGHT03
        TEXTHIGHT04
        TEXTHIGHT05
        TEXTHIGHT06
        TEXTHIGHT07
        TEXTHIGHT08
    End Enum

    'barcode type
    'Public Const UPCA As Int32 = 65
    'Public Const UPCE As Int32 = 66
    'Public Const EAN13 As Int32 = 67
    'Public Const EAN8 As Int32 = 68
    'Public Const CODE39 As Int32 = 69
    'Public Const ITF As Int32 = 70
    'Public Const CODABAR As Int32 = 71
    'Public Const CODE93 As Int32 = 72
    'Public Const CODE128 As Int32 = 73

    'print width
    'Private Const _1INCH As Integer = 192
    'Private Const _2INCH As Integer = 384
    'Private Const _3INCH As Integer = 576
    'Private Const _4INCH As Integer = 832

    'MCU
    'Private Const MCU_RX As Integer = 2
    'Private Const MCU_ARM As Integer = 1
    'Private Const MCU_M16C As Integer = 0

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ComboBox1.SelectedIndex = 0
        ComboBox2.SelectedIndex = 1
        ComboBox3.SelectedIndex = 0
        ComboBox4.SelectedIndex = 3

        Panel1.Location = New Point(13, 37)
        Panel2.Location = New Point(13, 37)
        Panel3.Location = New Point(13, 37)

        Panel1.Show()
        Panel2.Hide()
        Panel3.Hide()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If (ComboBox1.SelectedIndex = 0) Then
            Panel1.Show()
            Panel2.Hide()
            Panel3.Hide()

        ElseIf (ComboBox1.SelectedIndex = 1) Then
            Panel1.Hide()
            Panel2.Location = Panel1.Location
            Panel2.Show()
            Panel3.Hide()

        ElseIf (ComboBox1.SelectedIndex = 2) Then
            Panel1.Hide()
            Panel2.Hide()
            Panel3.Location = Panel1.Location
            Panel3.Show()

        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim intReturnValue As Integer = 0
        Dim SetPort As String = ""
        Dim BaudRate As Integer
        Dim DefaultTimeout As Integer = 1000


        If (ComboBox1.SelectedIndex = 0) Then
            Select Case (ComboBox3.SelectedIndex)
                Case 0 : SetPort = "COM1"
                Case 1 : SetPort = "COM2"
                Case 2 : SetPort = "COM3"
                Case 3 : SetPort = "COM4"
                Case 4 : SetPort = "COM5"
                Case 5 : SetPort = "COM6"
                Case 6 : SetPort = "COM7"
                Case 7 : SetPort = "COM8"
                Case 8 : SetPort = "COM9"
                Case 9 : SetPort = "COM10"
            End Select

            Select Case (ComboBox4.SelectedIndex)
                Case 0 : BaudRate = 9600
                Case 1 : BaudRate = 19200
                Case 2 : BaudRate = 38400
                Case 3 : BaudRate = 57600
                Case 4 : BaudRate = 115200
            End Select

            intReturnValue = ConnectSerialPrinter(SetPort, BaudRate, 1000, False)

            Select Case (intReturnValue)
                Case 1 : Label7.Text = "SUCCESS"
                Case -1 : Label7.Text = "ALREADY OPEND"
                Case -2 : Label7.Text = "UNABLE TO OPEN THE PORT"
                Case -3 : Label7.Text = "UNABLE_TO_CONFIGURE_THE_SERIAL_PORT"
                Case -4 : Label7.Text = "UNABLE_TO_SET_THE_TIMEOUT_PARAMETERS"
                Case -5 : Label7.Text = "NO_RESPONSE_FROM_PRINTER"
                Case -7 : Label7.Text = "TIMEOUT"
            End Select

        ElseIf (ComboBox1.SelectedIndex = 1) Then
            Dim ipAddr As String
            Dim ipPort
            ipAddr = TextBox2.Text.ToString()
            ipPort = Convert.ToDecimal(TextBox3.Text.ToString())

            intReturnValue = ConnectWirelessPrinter(ipAddr, ipPort, DefaultTimeout, False)

            Select Case (intReturnValue)
                Case 1 : Label7.Text = "SUCCESS"
                Case -1 : Label7.Text = "SOCKET ERROR"
                Case -2 : Label7.Text = "CONNECT_FAIL"
                Case -3 : Label7.Text = "ALREADY_CONNECTED"
                Case -5 : Label7.Text = "NO_RESPONSE_FROM_PRINTER"
                Case -7 : Label7.Text = "TIMEOUT"
            End Select

        ElseIf (ComboBox1.SelectedIndex = 2) Then
            intReturnValue = ConnectUSBPrinter(DefaultTimeout, False)

            Select Case (intReturnValue)
                Case 1 : Label7.Text = "SUCCESS"
                Case -1 : Label7.Text = "ALREADY OPEND"
                Case -2 : Label7.Text = "UNABLE_TO_MAKE_CONNECTION"
                Case -3 : Label7.Text = "UNABLE_TO_GET_INFOMATION"
                Case -4 : Label7.Text = "NOT_WOOSIM_PRINTER"
                Case -5 : Label7.Text = "NO_RESPONSE_FROM_PRINTER"
                Case -7 : Label7.Text = "TIMEOUT"
            End Select

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ClosePrinterConnection()
        Label7.Text = "CONNECTION CLOSED"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        InitPageMode(0, 0, PageWidth._2INCH, PageWidth._3INCH)

        'Draw Black & long box
        Page_DrawBox(PageWidth._2INCH - 80, 30, 30, 150, 20)
        Page_DrawBox(PageWidth._2INCH - 80, 200, 30, PageWidth._3INCH - 200 - 30, 1)

        'Contained text "TEXT"
        Page_DrawBox(214, 224, 50, 258, 1)

        'Boxes in Box
        Page_DrawBox(60, 234, 104, 44, 1)
        Page_DrawBox(60, 312, 28, 150, 1)
        Page_DrawBox(98, 312, 28, 150, 1)
        Page_DrawBox(136, 312, 28, 150, 1)
        Page_DrawBox(50, 224, 124, 258, 3)

        'Draw vertical lines
        Page_DrawBox(205, 30, 0, 140, 1)
        Page_DrawBox(235, 30, 0, 140, 1)
        Page_DrawBox(265, 30, 0, 140, 1)

        'Draw horizontal lines
        Page_DrawBox(185, 55, 100, 0, 1)
        Page_DrawBox(185, 95, 100, 0, 1)
        Page_DrawBox(185, 135, 100, 0, 1)

        'Draw outline-Box
        Page_DrawBox(30, 0, PageWidth._2INCH - 60, PageWidth._3INCH, 1)

        Page_SetDirection(3) ' Clockwise rotation
        Page_SetPosition(214, 30) 'Y_pos, X_pos
        SetTextStyle(0, False, TextWidth.TEXTWIDTH02, TextHeight.TEXTHIGHT02, False)
        TextSaveSpool("Text")
        Page_SetPosition(270, 70)
        QRCodeSaveSpool(0, "H", 2, "www.woosim.com/english")

        SetTextStyle(0, True, TextWidth.TEXTWIDTH02, TextHeight.TEXTHIGHT01, False)
        Page_SetPosition(126, 256) 'Y_pos, X_pos
        TextSaveSpool("TEXT")

        Page_Print_StandardMode()

        Page_SetDirection(0)
        InitPageMode(0, 0, PageWidth._2INCH, PageWidth._2INCH)

        Page_DrawBox(0, 30, PageWidth._2INCH, 0, 5)
        Page_DrawBox(30, 0, 0, PageWidth._2INCH, 5)
        Page_DrawLine(30, 30, 170, 160, 3)
        Page_DrawLine(170, 160, 130, 190, 3)
        Page_DrawLine(130, 190, 210, 250, 3)
        Page_DrawLine(210, 250, 190, 270, 3)
        Page_DrawLine(190, 270, 270, 340, 3)
        Page_DrawLine(270, 340, 210, 370, 3)
        Page_Newline()
        Page_Print()

        Page_ClearCurrentData()
        Page_DrawBox(0, PageWidth._1INCH, PageWidth._2INCH, 0, 5)
        Page_DrawBox(PageWidth._1INCH, 0, 0, PageWidth._2INCH, 5)
        Page_DrawBox(PageWidth._1INCH / 2, PageWidth._1INCH, PageWidth._1INCH, 0, 0)
        Page_DrawEllipse(PageWidth._1INCH, PageWidth._1INCH, PageWidth._1INCH / 2, PageWidth._1INCH, 3)
        Page_Print_StandardMode()

        If PrintSpool(True) = False Then
            MessageBox.Show("Error")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        InitPrinterStatus()

        ' TODO: Add your control notification handler code here
        TextSaveSpool("   매 출 전 표" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))

        'Company
        TextSaveSpool("상점명             Woosim Coffee" + Chr(&HA))
        TextSaveSpool("사업자등록번호      119-81-36382" + Chr(&HA))
        'Reg Number
        TextSaveSpool("대표자                  이 일 복" + Chr(&HA))
        'Address
        TextSaveSpool("서울특별시 금천구 가산동 448번지" + Chr(&HA) + "대륭테크노타운 3차, 501호" + Chr(&HA))
        'Tel
        TextSaveSpool("문의                02-2107-3709" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))
        TextSaveSpool("    우심 비자 카드" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        'Card number
        TextSaveSpool("카드번호     9445 4103 9533 2096" + Chr(&HA))
        TextSaveSpool("유효 기간                2012/10" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("거 래 일 자           2011/04/11" + Chr(&HA))
        TextSaveSpool("거 래 종 류       [신용거래승인]" + Chr(&HA))
        TextSaveSpool("단 말 번 호            123456789" + Chr(&HA))
        TextSaveSpool("승 인 번 호            987654321" + Chr(&HA))
        TextSaveSpool("결 제 금 액             50,000원" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("서명: " + Chr(&HA) + Chr(&HA) + Chr(&HA) + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))

		'Title
        'TextSaveSpool("  SALES  SLIP" + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA))
        'Company
        'TextSaveSpool("MERCHANT NAME      Woosim Coffee" + Chr(&HA))
        'Reg Number
        'TextSaveSpool("MASTER                LEE IL BOK" + Chr(&HA))
        'Address
        'TextSaveSpool("ADDRESS" + Chr(&HA) + " #501, DaerungTechnotown3th 448," + Chr(&HA) + "  Gasan-dong, Geumchun-gu, Seoul" + Chr(&HA) + "  Korea" + Chr(&HA))
        'Tel
        'TextSaveSpool("HELP DESK       (+82-2)2107-3714" + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))
        'TextSaveSpool("        WOOSIM  CARD " + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA))
        'TextSaveSpool("CARD NO.     4428-8819-0118-****" + Chr(&HA))
        'TextSaveSpool("EXPIRY                   2012/10" + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA))
        'TextSaveSpool("TRANS. YEAR & DATE   2008/04/15" + Chr(&HA))
        'TextSaveSpool("TRANS CLASS             [Credit]" + Chr(&HA))
        'TextSaveSpool("TERMINAL ID.           123456789" + Chr(&HA))
        'TextSaveSpool("APPROVAL NO.           987654321" + Chr(&HA))
        'TextSaveSpool("AMOUNT                   500.00$" + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA))
        'TextSaveSpool("SIGNATURE:  " + Chr(&HA) + Chr(&HA))
        'TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))

        If PrintSpool(True) = False Then
            MessageBox.Show("Error")
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim exists As Boolean
        exists = System.IO.File.Exists("./woosim.bmp")
        If (exists) Then
            InitPrinterStatus()

            'Normal BMP file print
            TextSaveSpool("Print Bmp file woosim.bmp")
            PrintData()

            NormalBmpSaveSpool("./woosim.bmp")

            PrintLineFeed(2)

            'BMP file print using Compressed algorithm
            TextSaveSpool("Print Bmp file using compressed algorithm")
            PrintData()
            CompressedBmpSaveSpool("./woosim.bmp")
            PrintLineFeed(2)

            'Print pre-download image.
            TextSaveSpool("Print pre-downloaded image file #0")
            PrintData()
            LoadLogoSaveSpool(0)
            PrintData()

            PrintSpool(True)
        Else
            MsgBox("""woosim.bmp"" is not found")
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        InitPrinterStatus()
        TextSaveSpool("UPCA" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.UPCA, 2, 100, True, "012100000642")
        PrintData()

        TextSaveSpool("UPCE" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.UPCE, 2, 100, True, "065100004328")
        PrintData()

        TextSaveSpool("EAN13" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.EAN13, 2, 100, True, "123456478901")
        PrintData()

        TextSaveSpool("EAN8" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.EAN8, 2, 100, True, "12345678")
        PrintData()

        TextSaveSpool("CODE39" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE39, 2, 100, True, "12345678901")
        PrintData()

        TextSaveSpool("ITF" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.ITF, 2, 100, True, "123456")
        PrintData()

        TextSaveSpool("CODABAR" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODABAR, 2, 100, True, "123456")
        PrintData()

        TextSaveSpool("CODE93" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE93, 2, 100, True, "12345678901")
        PrintData()

        TextSaveSpool("CODE128" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE128, 2, 100, True, "12345678901")
        PrintData()

        PrintSpool(True)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        InitPrinterStatus()

        TextSaveSpool("PDF417")
        PrintData()
        PDF417SaveSpool(2, 2, 2, 2, "0123456789", False)
        PrintData()

        TextSaveSpool("DataMatrix")
        PrintData()
        DataMatrixSaveSpool(36, 36, 2, "0123456789")
        PrintLineFeed(1)

        TextSaveSpool("QR Code")
        PrintData()
        QRCodeSaveSpool(0, "H", 3, "0123456789")
        PrintDotFeed(30)

        TextSaveSpool("Micro PDF417")
        PrintData()
        MicroPDF417SaveSpool(2, 1, 0, 2, "01234567", False)
        PrintDotFeed(30)

        TextSaveSpool("Truncated PDF417")
        PrintData()
        TruncatedPDF417SaveSpool(2, 2, 2, 2, "0123456789", False)
        PrintData()

        TextSaveSpool("Maxicode")
        PrintData()
        MaxicodeSaveSpool(4, "0123456789")
        PrintData()

        PrintSpool(True)
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        GetPrinterStatus(1000)
        'GetPrinterStatusEx(1000)
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        GetPrinterModelName()
        GetFirmwareVersion()
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        InitPageMode(0, 0, PageWidth._2INCH, 700)
        SetTextStyle(0, True, TextWidth.TEXTWIDTH02, TextHeight.TEXTHIGHT02, False)
        TextSaveSpool("Woosim Cafe" + Chr(&HA))

        SetTextStyle(0, False, TextWidth.TEXTWIDTH01, TextHeight.TEXTHIGHT01, False)
        TextSaveSpool("Coffee, tea and bread" + Chr(&HA))
        Page_DotFeed(15)
        SetFontSize(1)
        Page_SetPosition(277, 105)
        TextSaveSpool("2015-01-27" + Chr(&HA))
        SetFontSize(0)

        Page_SetPosition(290, 5)
        QRCodeSaveSpool(0, "H", 2, "www.woosim.com/english")

        Page_DrawBox(0, 130, PageWidth._2INCH, 0, 2)
        Page_DotFeed(5)
        TextSaveSpool(" #      Item      Num    Charge" + Chr(&HA))
        TextSaveSpool(" 1      Latte      1     $ 3.35")
        Page_Newline()
        TextSaveSpool(" 2  House Coffee   2     $ 3.98")
        Page_Newline()
        TextSaveSpool(" 3       Tea	       1     $ 1.95")
        Page_DotFeed(10)
        Page_DrawBox(0, 270, PageWidth._2INCH, 0, 2)
        Page_Newline()

        Page_DrawBox(0, 310, 115, 0, 2)
        Page_DrawBox(260, 310, 124, 0, 2)
        Page_DotFeed(15)
        Page_SetPosition(123, 300)
        TextSaveSpool("Credit Card" + Chr(&HA))

        TextSaveSpool("Number:         ")
        SetFontSize(1)
        TextSaveSpool("6688-9988-6644-3311")
        Page_Newline()
        SetFontSize(0)
        TextSaveSpool("Payment:                $ 9.50 ")
        Page_Newline()

        Page_DrawBox(0, 400, 120, 0, 2)
        Page_DrawBox(250, 400, 134, 0, 2)
        Page_DotFeed(15)
        Page_SetPosition(145, 390)
        TextSaveSpool("Payment" + Chr(&HA))

        TextSaveSpool("Price:                  $ 9.28")
        Page_Newline()
        TextSaveSpool("Tax:                    $ 0.22")
        Page_Newline()

        Page_DrawBox(0, 490, PageWidth._2INCH, 0, 2)
        Page_DotFeed(15)
        TextSaveSpool("Total:                  $ 9.50")
        Page_Newline()
        TextSaveSpool("Credit Card:            $ 9.50")
        Page_Newline()

        Page_SetPosition(40, 580)
        OneDimensionBarcodeSaveSpool(Barcode.CODE128, 2, 50, True, "20150127123456789")
        Page_LineFeed(2)

        Page_Print_StandardMode()
        PrintSpool(True)
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Dim modeSelect As Integer = 0

        'MSR sample is based 12Track magnetic card
        Select Case (ComboBox2.SelectedIndex)
            Case 0 : modeSelect = 0 'Read 1T. If 23T card, read 2T.
            Case 1 : modeSelect = 1 'Read 2T. If 23T card, read 3T.
            Case 2 : modeSelect = 4 'Read 3T. It only use for 123T.
            Case 3 : modeSelect = 2 'Read 12T. If 23T card, read 23T.
            Case 4 : modeSelect = 3 'Read 123T. It only use for 123T.
        End Select

        EnterMSRMode(modeSelect)
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        CancelMSRMode()
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Button2_Click(sender, e)
        Me.Close()
    End Sub

    Protected Overrides Sub WndProc(ByRef msg As Message)
        If msg.Msg = WM_RECEIVE_MSG Then
            Dim chk As Short
            Dim length As Long

            chk = msg.WParam.ToInt32() >> 16 ' x86
            length = msg.WParam.ToInt32() And &HFFFF 'x86

            If chk = DATA Then

                Me.Label7.Text = "DATA"

                Dim sScanData As String
                Dim Revstr As String = Nothing
                If (True) Then
                    sScanData = Marshal.PtrToStringUni(msg.LParam)
                    Dim CardData() As Byte = System.Text.Encoding.Unicode.GetBytes(sScanData)

                    Dim i As Integer
                    For i = 0 To CardData.Length - 1
                        Revstr += Chr(CardData(i))
                    Next

                End If
                Me.TextBox1.Text = Revstr


            ElseIf chk = STATUS_ANSWER Then
                Me.Label7.Text = "STATUS_ANSWER"

                Dim lParamByte(length) As Byte

                Marshal.Copy(msg.LParam, lParamByte, 0, length)

                Me.TextBox1.Text = Hex(lParamByte(0))
            Else
                Me.Label7.Text = ""
            End If
        End If
        MyBase.WndProc(msg)
    End Sub


    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        SetFontForTTF("WSTTFB.ttf")
        PrintSpoolForTTF("Woosim System Inc.", 10, 18)
        PrintSpool(True)
    End Sub
End Class

