Thursday, December 23, 2010

Cetak Ke Printer Via LPT Port Menggunakan VB6

Di bawah ini merupakan contoh cara mencetak ke printer via LPT Port menggunakan Visual Basic 6 - Adapun kodenya adalah sebagai berikut:
Public Function PrintToLPTPort(ByVal port As String, ByVal text As String) As Boolean 
On Error GoTo
ErrHandler
Dim l As Long
l = FreeFile
Open
port For Output As #l
Print #F, text
Close #l
PrintToLPTPort = True
Exit Function

ErrHandler:
PrintToLPTPort = False
End Function
Contoh penggunaan cetak ke printer via LPT Port:
Private Sub Command1_Click() 
PrintToLPTPort "LPT1", "Test Print"
End Sub
READ MORE - Cetak Ke Printer Via LPT Port Menggunakan VB6

Wednesday, December 22, 2010

Web Color Spy - Mendeteksi Warna Standar Web

Di bawah ini merupakan project VB6 sederhana untuk mendeteksi warna standar web. Bagaimana kode project web color spy untuk mendeteksi warna standar web, bisa lihat di bawah ini:
'simpan kode di bawah pada module 
Option Explicit

Public Declare Function
CreateDC& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Any)
Public Declare Function DeleteDC& Lib "gdi32" (ByVal hdc As Long)
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Type
POINTAPI
X As Long
Y As Long
End Type

Public Declare Function
GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'simpan kode di bawah pada form 
'Timer.Interval = 1
'Picture1.AutoRedraw = True

Option Explicit

Dim pt As
POINTAPI
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 
Timer1.Enabled = True
Picture1.MousePointer = vbCrosshair
End Sub

Private Sub
Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = False
Picture1.MousePointer = vbDefault
End Sub

Private Sub
Timer1_Timer()
Dim screendc As Long
GetCursorPos pt
screendc = CreateDC("DISPLAY", "", "", 0&)
Picture1.BackColor = GetPixel(screendc, pt.X, pt.Y)
Text1.Text = "#" & Hex(GetPixel(screendc, pt.X, pt.Y))
DeleteDC (screendc)
End Sub
READ MORE - Web Color Spy - Mendeteksi Warna Standar Web