Pas uda deket2 UAS, kami para pengambil mata kuliah pemrograman api dikejutkan dengan berita dari Bu Henning. Yups! Sebagai pengganti UAS, kami diharuskan membuat program dengan menggunakan fungsi API. Yo namanya juga kuliah pemrograman API, semakin banyak fungsi API yang dipake.. semakin bagus nilai UAS kami.
Hhmmm.. karna tema bebas, jadi malah bingung mau bikin apaan. Ide ini muncul saat lagi sayang bgt ama se2org. Uda pede gitu, yakin dah yg mau ama dia seumur hidup. Kepikir tentang sebuah buku tamu buat acara nikahan tar! Buku tamu yang g biasanya, yang g Cuma datang – tanda tangan – udah. G berkesan banget kan? Mana kita tau tuh org beneran dateng ato Cuma nitip absen doang *hihi.. nitip absen?? emgny kuliah??
Akhirnya kuputuskan untuk membuat sebuah “APLIKASI BUKU TAMU MENGGUNAKAN WEBCAM”. Kebetulannya lagi.. laptopku uda dilengkapi ama fasilitas webcam, jadinya y ga perlu ribet nyari pinjeman webcam dsb.
· Jadi gini gambaran aplikasi secara umumnya :
Aplikasi ini merupakan aplikasi buku tamu menggunakan komputer. Setiap tamu yang datang akan mengisi identitas berupa nama, comment, serta foto yang bisa diambil langsung pada saat itu juga. Pengambilan foto dilakukan dengan menggunakan webcam yang telah terpasang dan terintegrasi pada aplikasi. Data daftar tamu yang hadir bisa dilihat pada daftar foto dalam tampilan thumbnail, yang jika di-klik akan menampilkan data nama serta comment yang telah diinputkan.
· Fungsi API yang digunakan
- Fungsi API untuk webcam
- Public Declare Function capCreateCaptureWindow Lib “avicap32.dll” Alias “capCreateCaptureWindowA” _
(ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long _
, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
- Public Declare Function SendMessage Lib “user32″ _
Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
- Fungsi API untuk tampilan thumbnail
- Public Declare Function CopyImage Lib “user32″ (ByVal handle As Long, ByVal imageType As Long, ByVal newWidth As Long, ByVal newHeight As Long, ByVal lFlags As Long) As Long
- Public Declare Function SetClipboardData Lib “user32″ (ByVal wFormat As Long, ByVal hMem As Long) As Long
- Public Declare Function EmptyClipboard Lib “user32″ () As Long
- Public Declare Function CloseClipboard Lib “user32″ () As Long
- Public Declare Function OpenClipboard Lib “user32″ (ByVal hwnd As Long) As Long
· Listing Code
1. Menghidupkan
Private Sub CamOn_Click()
Dim temp As Long
If temp = SendMessage(hCap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&) Then
hCap = capCreateCaptureWindow(iDevice, WS_CHILD Or WS_VISIBLE, 0, 0, PicWebCam.Width, PicWebCam.Height, PicWebCam.hwnd, 0)
If hCap <> 0 Then
Call SendMessage(hCap, WM_CAP_DRIVER_CONNECT, 0, 0)
Call SendMessage(hCap, WM_CAP_SET_PREVIEWRATE, 66, 0&)
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End If
Else
Call SendMessage(hCap, WM_CAP_DRIVER_CONNECT, 0, 0)
Call SendMessage(hCap, WM_CAP_SET_PREVIEWRATE, 66, 0&)
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End If
End Sub
2. Mematikan
Private Sub CamOff_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
End Sub
Private Sub CommSubmit_Click()
Dim photoLocation As String
On Error GoTo ErrHandler
If TextNameForm.Text = “” Or TextAddress.Text = “” Then
MsgBox “Please fill your form and take your photo”, vbExclamation, “Required”
TextNameForm.SetFocus
Exit Sub
Else
strTanggal = Format(Now, “yyyymmdd”) & Format(Now, “_HH_MM_ss”)
photoLocation = “\photo\” & strTanggal & “.bmp”
With AdoUser
AdoUser.RecordSource = “select * From GuestTable”
.Refresh
.Recordset.AddNew
.Recordset!Name = TextNameForm
.Recordset!address = TextAddress
.Recordset!comment = TextComment
.Recordset!photo = photoLocation
.Recordset.Update
End With
End If
uploadImage
MsgBox “Your data successfully saved”, vbInformation, “Message”
TextNameForm.Text = “”
TextAddress.Text = “”
TextComment.Text = “”
CommSubmit.Enabled = False
Exit Sub
ErrHandler:
MsgBox “Saving failed” & Err.Description, vbExclamation, “Error”
End Sub
Tampilan Thumbnail
1. Menampilkan foto dalam bentuk thumbnail
Private Sub Form_Load()
Dim test As String
AdoUser.RecordSource = “select photo From GuestTable”
AdoUser.Refresh
With LV
.View = lvwIcon
.Arrange = lvwAutoLeft
.LabelEdit = lvwManual
.BorderStyle = ccFixedSingle
.Appearance = cc3D
.OLEDragMode = ccOLEDragAutomatic
.OLEDropMode = ccOLEDropNone
.HideSelection = True
.LabelWrap = True
.Enabled = True
End With
Do While Not AdoUser.Recordset.EOF
test = AdoUser.Recordset![photo]
addMe App.path & test
AdoUser.Recordset.MoveNext
Loop
End Sub
Public Function addMe(strPath As String)
Screen.MousePointer = vbHourglass
‘copy the image to a desired size
lngCpyImg = CopyImage(LoadPicture(strPath).handle, IMAGE_BITMAP, 100, 100, LR_COPYRETURNORG)
‘open the clipboard
OpenClipboard Me.hwnd
‘empty clipboard
EmptyClipboard
‘assign the copy image to the clipboard
SetClipboardData CF_BITMAP, lngCpyImg
‘close the clipboard
CloseClipboard
‘add the clipboard data to the imagelist
iList.ListImages.Add , strPath, Clipboard.GetData()
‘always set the listview arragement to left
‘in some cases you need the thumbnails displayed horizontally
LV.Arrange = lvwAutoLeft
If LV.ListItems.Count = 0 Then
‘clear the listview
LV.ListItems.Clear
’set icons to nothing
Set LV.Icons = Nothing
‘assign the imagelist to the listview icons
Set LV.Icons = iList
End If
‘get the filename
strfName = StrReverse(strPath)
strfName = Mid$(strfName, 1, InStr(strfName, “\”) – 1)
‘display the copy image to the listview
Set lstItmLstVw = LV.ListItems.Add(, strPath, StrReverse(strfName), strPath)
Screen.MousePointer = vbDefault
End Function
2. Fungsi double click yang bisa menampilkan detail foto
Private Sub LV_DblClick()
If LV.ListItems.Count = 0 Then Exit Sub
‘assign the image path path
filePath = LV.SelectedItem.Key
‘call frmview to display the image
FormPerson.Show
End Sub
3. Meload data foto yang telah di klik pada form baru
Private Sub Form_Load()
Dim appPath As Integer
Dim strfName, path As String
strfName = StrReverse(filePath)
path = Mid(strfName, 1, 28)
path = StrReverse(path)
strfName = Mid$(strfName, 1, InStr(strfName, “\”) – 1)
‘assign
Me.Caption = StrReverse(strfName)
’stretch if needed
PictGuest.Stretch = IIf(origAs = 0, True, False)
‘load the image
PictGuest.Picture = LoadPicture(filePath)
AdoDetail.RecordSource = “select * From GuestTable where [photo]=’” & path & “‘”
AdoDetail.Refresh
LabelName = AdoDetail.Recordset![Name]
LabelAddress = AdoDetail.Recordset![address]
LabelComment = AdoDetail.Recordset![comment]
End Sub
Private Sub Form_Load()
Adoview.Refresh
PictGuest.Picture = LoadPicture(App.path & Label1.Caption)
End Sub