Sunday, April 4, 2010

VB6 Code - Mencari Dengan Cepat Pada Listbox (Fungsi Api)

Di bawah ini merupakan fungsi VB6 yang digunakan untuk mencari sebuah item yang terdapat dalam objek ListBox dengan cepat.
Option Explicit

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Private Const LB_FINDSTRING = &H18F

Public Function SearchInList(sText As String, lst As ListBox)
On Error Resume Next
lst.ListIndex = SendMessage(lst.hWnd, LB_FINDSTRING, -1, ByVal sText)
lst.TopIndex = List1.ListIndex - 1
End Function
Contoh penggunaan mencari dengan cepat menggunakan fungsi API
Private Sub Form_Load()
With List1
.AddItem "Bandung"
.AddItem "Jakarta"
.AddItem "Garut"
.AddItem "Surabaya"
.AddItem "New York"
.AddItem "Khoiriyyah"
End With
End Sub

Private Sub Text1_Change()
SearchInList Text1.Text, List1
End Sub
READ MORE - VB6 Code - Mencari Dengan Cepat Pada Listbox (Fungsi Api)

VB6 Code - Menjalankan Screen Saver

Di bawah ini merupakan fungsi uVB6 ntuk menjalankan screen saver melalui pemrograman.
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_SYSCOMMAND = &H112&
Private Const SC_SCREENSAVER = &HF140&

Public Sub RunScreenSaver()
Call SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_SCREENSAVER, 0&)
End Sub
Contoh penggunaan menjalankan screen saver
Private Sub Command1_Click()
RunScreenSaver
End Sub
READ MORE - VB6 Code - Menjalankan Screen Saver

VB6 Code - Memperoleh Waktu Double Klik Pada Mouse

Source code VB6 di bawah ini berguna untuk memperoleh waktu double klik pada mouse dengan menggunakan fungsi API GetDoubleClick.
Option Explicit

Private Declare Function GetDoubleClickTime Lib "user32" () As Long

Private Sub Command1_Click()
Dim ret As Long
ret = GetDoubleClickTime
Text1.Text = ret & " milliseconds"
End Sub
READ MORE - VB6 Code - Memperoleh Waktu Double Klik Pada Mouse

VB6 Code - Menjalankan Aplikasi Pada Start Up

Di bawah ini merupakan cara yang mudah untuk menjalankan aplikasi pada saat startup menggunakan kode VB6. Pada dasarnya fungsi startup, hanyalah fungsi baca dan tulis ke dalam registy. Kodenya pendek, karena ia meminjam ActiveX Windows Script Host Object Model atau yang lebih dikenal dengan nama WSHOM.OCX.
Option Explicit

Dim oWSHShell As New WshShell

Private Function RegWrite(sKey As String, sFilepath As String)
oWSHShell.RegWrite sKey, sFilepath
End Function

Private Function RegDelete(sKey As String)
oWSHShell.RegDelete sKey
End Function
Contoh penggunaan fungsi di atas yang digunakan untuk menulis ke dalam registry
Private Sub Command1_Click()
RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\" & _
App.EXEName, App.Path & "\" & App.EXEName & ".exe"
End Sub
Contoh penggunaan fungsi di atas yang digunakan untuk menghapus entry yang terdapat dalam registry
Private Sub Command2_Click()
RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName
End Sub
READ MORE - VB6 Code - Menjalankan Aplikasi Pada Start Up

VB6 Code - Animasi Ketikan Tanpa Flicker

Fungsi VB6 di bawah ini digunakan untuk animasi yang menyerupai text yang sedang di ketik. Animasinya sangat halus nyaris tanpa kedipan.
Option Explicit

Dim sAnimation As String

Private Sub Form_Load()
sAnimation = "Asep Hibban : http://4basic-vb.blogspot.com"
End Sub

Private Sub Timer1_Timer()
Dim sToAnimate As String
Static iAnimation As Integer
Dim c As Integer
iAnimation = iAnimation + 1

sToAnimate = Mid(sAnimation, 1, iAnimation)
With Picture1
.Cls
.CurrentX = 25
.CurrentY = 100
Picture1.Print sToAnimate
End With
If iAnimation >= Len(sAnimation) Then
iAnimation = 0
End If
End Sub
READ MORE - VB6 Code - Animasi Ketikan Tanpa Flicker

VB6 Code - Menjalankan File .mp3

Di bawah ini merupakan contoh menggunakan Microsoft Multimedia Control yang digunakan untuk menjalankan file .mp3 menggunakan VB6.
Option Explicit

Private Sub Command1_Click()
MMC.FileName = OpenFile
Me.Caption = MMC.FileName
MMC.Command = "open"
MMC.Command = "play"
End Sub

Private Function OpenFile() As String
With CommonDialog1
.FileName = ""
.DialogTitle = "Open Files"
.InitDir = "C:\My Documents"
.Filter = "MP3 File (*.MP3)|*.MP3"
.ShowOpen
If .FileName = "" Then Exit Function
MMC.Command = "stop"
OpenFile = .FileName
End With
End Function

Private Sub Command2_Click()
MMC.Command = "stop"
End Sub
READ MORE - VB6 Code - Menjalankan File .mp3

VB6 Code - Menghapus Spasi Rangkap

Di bawah ini merupakan fungsi VB6 untuk menghapus/menghilangkan spasi yang tidak diperlukan (spasi rangkap).
Option Explicit

Private Function DelJunkSpace(str As String) As String
Do While (InStr(str, " ") > 0)
str = Replace(str, " ", " ")
Loop
DelJunkSpace = str
End Function
Contoh penggunaan fungsi di atas
Private Sub Form_Load()
Dim str As String
str = "Asep Hibban http://4basic-vb.blogspot.com"
'menjadi = "Asep Hibban http://4basic-vb.blogspot.com"
Text1.Text = str
End Sub
READ MORE - VB6 Code - Menghapus Spasi Rangkap

VB6 Code - Menjadikan Input Textbox Kapital

Di bawah ini merupakan kode VB6 untuk menjadikan text yang terdapat pada textbox menjadi kapital. Kode yang ditrigger pada saat penekanan tombol.
Option Explicit

'This one line code makes the contents of text box in capital. As you keep in typing it. Just copy this code keypress
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
READ MORE - VB6 Code - Menjadikan Input Textbox Kapital

VB6 Code - Memperoleh Jumlah Baris TextBox

Di bawah ini merupakan fungsi VB6 untuk memperoleh/mengetahui jumlah jajaran dalam sebuah textboxt. Fungsi tersebut menggunakan fungsi API SendMessageLong.
Option Explicit

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_GETLINECOUNT = &HBA

Public Function GetLineCount(Txt As TextBox)
Dim lngLineCount As Long
On Error Resume Next
lngLineCount = SendMessageLong(Txt.hwnd, EM_GETLINECOUNT, 0&, 0&)
GetLineCount = Format$(lngLineCount, "##,###")
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
MsgBox GetLineCount(Text1)
End Sub
READ MORE - VB6 Code - Memperoleh Jumlah Baris TextBox

VB6 Code - Menghapus Isi Textbox Dengan Cepat

Di bawah ini merupakan procedure VB6 untuk menghapus isi/text yang terdapat dalam textbox dengan cepat. Kami buat menjadi procedure agar mudah dalam penggunaan dan memiliki sifat mudah digunakan kembali (reusability)
Option Explicit

Public Sub ClearAllTextBoxes(frmClearMe As Form)
Dim txt As Control
For Each txt In frmClearMe
If TypeOf txt Is TextBox Then txt.Text = ""
Next
End Sub
Contoh penggunaan/pemanggilan procedure di atas
Private Sub Command1_Click()
ClearAllTextBoxes Me
End Sub
READ MORE - VB6 Code - Menghapus Isi Textbox Dengan Cepat

VB6 Code - Fungsi Shutdown, Restart, Log-off

Di bawah ini merupakan fungsi untuk men-shutdown, restart, log-off sebuah komputer.
Option Explicit

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Const ENDSESSION_LOGOFF As Long = &H80000000

Public Enum EShutDownTypes
[_First] = 0
EWX_LOGOFF = 0
EWX_SHUTDOWN = 1&
EWX_REBOOT = 2&
EWX_FORCELOGOFF = 4&
EWX_FORCESHUTDOWN = 5&
EWX_FORCEREBOOT = 6&
EWX_POWEROFF = 8&
EWX_FORCEIFHUNG = 10& ' NT5 only
[_Last] = &H20& - 1
End Enum

Public Enum EShutDownErrorBaseConstant
eeSSDErrorBase = vbObjectError Or (1048 + &H210)
End Enum

Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0

Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private Const FORMAT_MESSAGE_FROM_STRING = &H400
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Private Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF

Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long

Private Type LARGE_INTEGER
LowPart As Long
HighPart As Long
End Type

Private Type LUID
LowPart As Long
HighPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(0 To 0) As LUID_AND_ATTRIBUTES
End Type

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetTokenInformation Lib "advapi32.dll" (ByVal TokenHandle As Long, TokenInformationClass As Integer, TokenInformation As Any, ByVal TokenInformationLength As Long, ReturnLength As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long

Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2

Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)

Private Const TOKEN_ASSIGN_PRIMARY = &H1
Private Const TOKEN_DUPLICATE = (&H2)
Private Const TOKEN_IMPERSONATE = (&H4)
Private Const TOKEN_QUERY = (&H8)
Private Const TOKEN_QUERY_SOURCE = (&H10)
Private Const TOKEN_ADJUST_PRIVILEGES = (&H20)
Private Const TOKEN_ADJUST_GROUPS = (&H40)
Private Const TOKEN_ADJUST_DEFAULT = (&H80)
Private Const TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or TOKEN_ASSIGN_PRIMARY Or _
TOKEN_DUPLICATE Or TOKEN_IMPERSONATE Or TOKEN_QUERY Or TOKEN_QUERY_SOURCE Or TOKEN_ADJUST_PRIVILEGES Or TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_DEFAULT)
Private Const TOKEN_READ = (STANDARD_RIGHTS_READ Or TOKEN_QUERY)
Private Const TOKEN_WRITE = (STANDARD_RIGHTS_WRITE Or TOKEN_ADJUST_PRIVILEGES Or TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_DEFAULT)
Private Const TOKEN_EXECUTE = (STANDARD_RIGHTS_EXECUTE)
Private Const TokenImpersonationLevel = 9
Private Const TokenOwner = 4
Private Const TokenUser = 1
Private Const TokenPrimaryGroup = 5
Private Const TokenStatistics = 10
Private Const TokenType = 8
Private Const TokenPrivileges = 3
Private Const TokenSource = 7
Private Const TokenDefaultDacl = 6
Private Const TokenGroups = 2

Public Function WinError(ByVal lLastDLLError As Long) As String

Dim sBuff As String
Dim lCount As Long

sBuff = Space(255)
lCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDLLError, 0&, sBuff, Len(sBuff), ByVal 0)

If lCount Then
WinError = Left(sBuff, lCount)
End If

End Function

Public Function IsNT() As Boolean

Static bOnce As Boolean
Static bValue As Boolean

If Not (bOnce) Then
Dim tVI As OSVERSIONINFO

tVI.dwOSVersionInfoSize = Len(tVI)

If (GetVersionEx(tVI) <> 0) Then
bValue = (tVI.dwPlatformId = VER_PLATFORM_WIN32_NT)
bOnce = True
End If
End If

IsNT = bValue

End Function

Private Function NTEnableShutDown(ByRef sMsg As String) As Boolean

Dim tLUID As LUID
Dim hProcess As Long
Dim hToken As Long
Dim tTP As TOKEN_PRIVILEGES
Dim tTPOld As TOKEN_PRIVILEGES
Dim lTpOld As Long
Dim lR As Long

lR = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, tLUID)

If (lR <> 0) Then

hProcess = GetCurrentProcess()
If (hProcess <> 0) Then
lR = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken)
If (lR <> 0) Then

With tTP
.PrivilegeCount = 1
With .Privileges(0)
.Attributes = SE_PRIVILEGE_ENABLED
.pLuid.HighPart = tLUID.HighPart
.pLuid.LowPart = tLUID.LowPart
End With
End With

lR = AdjustTokenPrivileges(hToken, 0, tTP, Len(tTP), tTPOld, lTpOld)

If (lR <> 0) Then
NTEnableShutDown = True
Else
Err.Raise eeSSDErrorBase + 6, App.EXEName & ".mShutDown", "Can't enable shutdown: You do not have the privileges to " & "shutdown this system. [" & WinError(Err.LastDllError) & "]"
End If

CloseHandle hToken
Else
Err.Raise eeSSDErrorBase + 6, App.EXEName & ".mShutDown", "Can't enable shutdown: You do not have the privileges to " & "shutdown this system. [" & WinError(Err.LastDllError) & "]"
End If
Else
Err.Raise eeSSDErrorBase + 5, App.EXEName & ".mShutDown", "Can't enable shutdown: Can't determine the current process. [" & WinError(Err.LastDllError) & "]"
End If
Else
Err.Raise eeSSDErrorBase + 4, App.EXEName & ".mShutDown", _
"Can't enable shutdown: Can't find the SE_SHUTDOWN_NAME privilege value. [" & _
WinError(Err.LastDllError) & "]"
End If

End Function

Public Function ShutdownSystem(Optional ByVal eType As EShutDownTypes = EWX_SHUTDOWN) As Boolean

Dim yesno As Integer

Dim lR As Long
Dim sMsg As String

If (eType < EShutDownTypes.[_First] And eType > EShutDownTypes.[_Last]) Then
Err.Raise eeSSDErrorBase + 7, App.EXEName & ".mShutDown", "Invalid parameter to ShutdownSystem: " & eType, vbInformation
Exit Function
End If

If (IsNT) Then
If Not (NTEnableShutDown(sMsg)) Then
Exit Function
End If
End If

lR = ExitWindowsEx(eType, &HFFFFFFFF)

If (lR = 0) Then
Err.Raise eeSSDErrorBase + 3, App.EXEName & ".mShutDown", "ShutdownSystem failed: " & WinError(Err.LastDllError)
Else
ShutdownSystem = True
End If

End Function
Contoh penggunaan fungsi di atas -shutdown
Private Sub Command1_Click()
ShutdownSystem EWX_FORCESHUTDOWN
End Sub
Contoh penggunaan fungsi di atas -restart
Private Sub Command2_Click()
ShutdownSystem EWX_FORCEREBOOT
End Sub
Contoh penggunaan fungsi di atas -log-off
Private Sub Command3_Click()
ShutdownSystem EWX_FORCELOGOFF
End Sub
READ MORE - VB6 Code - Fungsi Shutdown, Restart, Log-off

VB6 Code - Mengetahui Lama Windows Dijalankan

Fungsi VB6 untuk mengetahui berapa lama windows telah dijalankan.
Option Explicit

Private Declare Function GetTickCount Lib "Kernel32" () As Long

Private Sub Timer1_Timer()
Text1.Text = Format(GetTickCount, "0") & " milisceconds"
Text2.Text = Format(GetTickCount / 60000, "0") & " minutes"
End Sub
READ MORE - VB6 Code - Mengetahui Lama Windows Dijalankan

VB6 Code - Memperoleh Time Out Screen Saver

Di bawah ini merupakan fungsi VB6 untuk memperoleh/mengetahui time out screen saver. Adapun kodenya di bawah ini:
Option Explicit

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPI_GETSCREENSAVETIMEOUT = 14

Function ScrTimeOut() As Integer
Dim intValue As Integer
Call SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, vbNull, intValue, 0)
ScrTimeOut = intValue
End Function
Contoh penggunaan fungsi di atas:
Private Sub Command1_Click()
MsgBox ("Screen saver time-out value: " & ScrTimeOut & " seconds.")
End Sub
READ MORE - VB6 Code - Memperoleh Time Out Screen Saver

Saturday, April 3, 2010

VB6 Code - Fungsi Untuk Merubah Desktop Wallpaper

Di bawah ini merupakan fungsi VB6 untuk merubah desktop wallpaper. Bagaimana implementasinya dalam Visual Basic 6.0?
Option Explicit

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SETDESKWALLPAPER = 20

Public Function ChangeWallPaper(imgFile As String)
Call SystemParametersInfo(SPIF_SETDESKWALLPAPER, 0&, imgFile, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Function
Contoh penggunaan kode di atas
Private Sub Command1_Click()
Call ChangeWallPaper("C:\Windows\Blue.bmp")
End Sub
READ MORE - VB6 Code - Fungsi Untuk Merubah Desktop Wallpaper

VB6 - Menyembunyikan Dan Menampilkan Windows Taskbar

Di bawah ini merupakan contoh standar untuk menyembunyikan dan menampilkan windows taskbar menggunakan Visual Basic 6.
Option Explicit

Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40

Public Sub HideTaskBar()
Dim hWnd1 As Long
hWnd1 = FindWindow("Shell_traywnd", "")
Call SetWindowPos(hWnd1, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
End Sub

Public Sub ShowTaskBar()
Dim hWnd1 As Long
hWnd1 = FindWindow("Shell_traywnd", "")
Call SetWindowPos(hWnd1, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
End Sub
Contoh penggunaan untuk menyembunyikan windows taskbar
Private Sub  Command1_Click()
HideTaskBar
End Sub
Contoh penggunaan untuk menampilkan windows taskbar
Private Sub Command2_Click()
ShowTaskBar
End Sub
Demikian mengenai cara menampilkan dan menyembunyikan windows taskbar menggunakan Visual Basic 6.
READ MORE - VB6 - Menyembunyikan Dan Menampilkan Windows Taskbar

VB6 Code - Menampilkan Kotak Dialog Shutdown

Di bawah ini merupakan fungsi API untuk menampilkan kotak dialog shutdown menggunakan kode VB6. Fungsi yang digunakan adalah SHShutDownDialog yang terdapat pada Shell32.dll.
Option Explicit

Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal sParam As Long) As Long
Contoh penggunaan fungsi API di atas:
Private Sub Command1_Click()
SHShutDownDialog 0
End Sub
READ MORE - VB6 Code - Menampilkan Kotak Dialog Shutdown

VB6 Code - Fungsi Untuk Memeriksa Resolusi Screen

Di bawah ini merupakan fungsi VB6 untuk mengetahui resolusi screen. Bagaimana implementasinya dalam Visual Basic 6.0? bisa kita simak kodenya di bawah ini:
Option Explicit
Public Function ScreenResolution(iWidth, iHeight) As String
iWidth = Screen.Width \ Screen.TwipsPerPixelX
iHeight = Screen.Height \ Screen.TwipsPerPixelY
ScreenResolution = "Screen Resolution:" + vbCrLf + vbCrLf + Str$(iWidth) + " x" + Str$(iHeight)
End Function
Contoh penggunaan fungsi di atas:
Private Sub Command1_Click()
Dim intWidth As Integer
Dim intHeight As Integer
MsgBox ScreenResolution(intWidth, intHeight)
MsgBox intWidth
MsgBox intHeight
End Sub
READ MORE - VB6 Code - Fungsi Untuk Memeriksa Resolusi Screen

VB6 Code - Drag Form Yang Tidak Memiliki Controlbox

Di bawah ini merupakan fungsi VB6 (menggunakan fungsi API) untuk men-drag form yang tidak memiliki Control Box.
Option Explicit

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()

Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Public Sub DragForm(frm As Form)
Dim lngReturnValue As Long
Call ReleaseCapture
lngReturnValue = SendMessage(frm.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub
Contoh penggunaan drag form yang tidak memiliki controlbox
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragForm Me
End Sub
READ MORE - VB6 Code - Drag Form Yang Tidak Memiliki Controlbox

VB6 Code - Mencari Aplikasi Asosiasi Sebuah File

Di bawah ini merupakan fungsi VB6 untuk mencari aplikasi yang diasosiasikan terhadap sebuah file. Bingung? misalnya kita double klik file berektensi .ini maka aplikasinya notepad.exe, double klik file berektensi .doc maka aplikasinya Microsoft Word, dst.
Option Explicit

Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpdirectory As String, ByVal lpResult As String) As Long
Private Const MAX_FILENAME_LEN = 256

Public Function FindExecutable(FileName As String) As String
Dim iReturn As Integer
Dim sResults As String

sResults = String(MAX_FILENAME_LEN, 32) & Chr$(0)

iReturn = FindExecutableA(FileName & Chr$(0), vbNullString, sResults)

If iReturn > 32 Then
FindExecutable = Left$(sResults, InStr(sResults, Chr$(0)) - 1)
Else
FindExecutable = ""
End If
End Function
Contoh penggunaan fungsi untuk mencari assosiasi sebuah file
Private Sub Form_Load()
MsgBox FindExecutable("c:\boot.ini")
End Sub
READ MORE - VB6 Code - Mencari Aplikasi Asosiasi Sebuah File

VB Code - Mengubah Object LeftToRight Menjadi RighToLeft

Di bawah ini merupakan fungsi VB6 untuk mengubah objek yang tidak memiliki properties LeftToRight agar seolah-olah memiliki properties tersebut. Melalui akal-akalan fungsi API, hal tersebut mungkin untuk dilakukan.
Option Explicit

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 'TreeView1 RightToLeft True

Private Const WS_EX_LAYOUTRTL = 4194304
Private Const GWL_EXSTYLE = -20

Public Sub ctlRightToLeft(ctl As Control)
SetWindowLong ctl.hWnd, GWL_EXSTYLE, WS_EX_LAYOUTRTL
End Sub
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
ctlRightToLeft TreeView1
TreeView1.Appearance = cc3D
TreeView1.BorderStyle = ccFixedSingle
TreeView1.Refresh
End Sub
Coba Anda ganti objeknya misalnya menggunakan Progress Bar, kemudian lihat apa yang terjadi?
READ MORE - VB Code - Mengubah Object LeftToRight Menjadi RighToLeft

VB6 Code - Download File Menggunakan IE

Di bawah ini merupakan procedure VB6 untuk mendownload sebuah file dengan memanfaatkan file bawaan IE (internet explorer) hdocvw.dll. Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya di bawah ini:
Option Explicit

Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long

Public Sub DownloadFile(URL As String)
Dim sDownload As String
sDownload = StrConv(Text1.Text, vbUnicode)
Call DoFileDownload(sDownload)
End Sub
Contoh penggunaan procedure VB6 di atas:
Private Sub Command1_Click()
DownloadFile "http://google.co.id"
End Sub
READ MORE - VB6 Code - Download File Menggunakan IE

VB6 Code - Apakah Aplikasi Masih Dalam IDE VB6

Ini merupakan cara yang cerdik untuk mengetahui apakah sebuah aplikasi masih dalam IDE Visual Basic 6.0 ataukah sudah dicompile. Procedurenya sangat sederhana sekali yakni dengan memanfaatkan handle error.
Public Function IsIDE() As Boolean
On Error GoTo ErrHandler
Debug.Print 1 / 0
ErrHandler:
IsIDE = Err
End Function
Contoh penggunaan kode VB6 di atas:
Private Sub Form_Load()
If IsIDE Then
MsgBox "Jalankan aplikasi ini dari file .EXE", vbInformation, "Message"
End If
End Sub

READ MORE - VB6 Code - Apakah Aplikasi Masih Dalam IDE VB6

VB6 Code - Memindahkan File Ke Recycle Bin

Di bawah ini merupakan procedure VB6 untuk memindahkan/menghapus file ke dalam recycle bin. Bagaimana kodenya dalam Visual Basic 6.0? bisa kita simak di bawah ini:
Option Explicit

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type

Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4

Public Sub SendFileToRecycleBin(FileName As String, Optional Confirm As Boolean = True, Optional Silent As Boolean = False)
Dim FileOp As SHFILEOPSTRUCT

With FileOp
.wFunc = FO_DELETE
.pFrom = FileName
fFlags = FOF_ALLOWUNDO
If Not Confirm Then .fFlags = .fFlags + FOF_NOCONFIRMATION
If Silent Then .fFlags = .fFlags + FOF_SILENT
End With
SHFileOperation FileOp
End Sub
Contoh penggunaan procedure VB6 di atas:
Private Sub Command1_Click()
SendFileToRecycleBin "c:\42.tmp", True, False
End Sub
READ MORE - VB6 Code - Memindahkan File Ke Recycle Bin

VB6 Code - Menghapus Seluruh File Recycle Bin

Di bawah ini merupakan fungsi VB6 untuk menghapus seluruh file yang terdapat pada recycle bin. Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya di bawah ini
Option Explicit

Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Const SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4

Public Sub EmptyRecycleBin(frm As Form)
Dim RetVal
RetVal = SHEmptyRecycleBin(frm.hWnd, "", SHERB_NOPROGRESSUI + SHERB_NOCONFIRMATION)
End Sub
Contoh pengunaan procedure VB6 di atas
Private Sub Command1_Click()
EmptyRecycleBin Me
End Sub
READ MORE - VB6 Code - Menghapus Seluruh File Recycle Bin

VB6 Code - Apakah Recycle Bin Kosong?

Di bawah ini merupakan fungsi VB6 untuk memeriksa apakah recycle bin kosong? Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya dibawah ini:
Option Explicit

Private Type SHQUERYRBINFO
cbSize As Long
i64SizeLo As Long
i64SizeHi As Long
i64NumItemsLo As Long
i64NumItemsHi As Long
End Type

Private Declare Function SHQueryRecycleBin Lib "shell32" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO) As Long

Function IsEmptyRecycle() As Boolean
Dim RB As SHQUERYRBINFO
RB.cbSize = Len(RB)
Call SHQueryRecycleBin("C:\", RB)
IsEmptyRecycle = (RB.i64NumItemsLo = 0)
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
MsgBox IsEmptyRecycle
End Sub
READ MORE - VB6 Code - Apakah Recycle Bin Kosong?

VB6 Code - Menghapus Seluruh File Recent Document

Di bawah ini merupakan procedure VB6 untuk menghapus seluruh yang terdapat pada recent document. Untuk keperluan ini digunakan satu fungsi API yakni SHAddToRecentDocs yang terdapat pada shell32.dll.
Option Explicit

Private Declare Sub SHAddToRecentDocs Lib "shell32.dll" (ByVal uFlags As Long, ByVal pv As Any)

Sub EmptyRecentDocument()
SHAddToRecentDocs 0, CLng(0)
End Sub
Contoh penggunaan procedure VB6 di atas:
Private Sub Command1_Click()
EmptyRecentDocument
End Sub
READ MORE - VB6 Code - Menghapus Seluruh File Recent Document

VB6 Code - Membuat Efek Bayangan Pada Objek

Di bawah ini merupakan fungsi VB6 untuk membuat efek bayangan pada sebuah objek. Bagaimana implementasi dalam Visual Basic 6.0? bisa Anda simak kodenya di bawah ini:
Option Explicit

Public Function Shadow(frm As Form, ctl As Control, Optional shWidth = 3, Optional Color = vbGrayed)
Dim oldWidth As Integer
Dim oldScale As Integer

With frm
oldWidth = .DrawWidth
oldScale = .ScaleMode
.ScaleMode = 3
.DrawWidth = 1
frm.Line (ctl.Left + shWidth, ctl.Top + shWidth)-Step(ctl.Width - 1, ctl.Height - 1), Color, BF
.DrawWidth = oldWidth
.ScaleMode = oldScale
End With

End Function
Contoh penggunaan fungsi membuat efek bayangan pada objek:
Private Sub Command1_Click()
Shadow Me, Command1, 2, vbBlack
End Sub

Anda dapat menggunakannya pada objek secara bulk dengan menggunakan for...each.
READ MORE - VB6 Code - Membuat Efek Bayangan Pada Objek

VB6 Code - Menambahkan File Ke Recent Document

Di bawah ini merupakan fungsi VB6 (API) untuk menambahkan file ke recent document. Untuk keperluan ini digunakan satu fungsi API yakni SHAddToRecentDocs yang terdapat pada shell32.dll.
Option Explicit

Private Declare Sub SHAddToRecentDocs Lib "shell32.dll" (ByVal uFlags As Long, ByVal pv As String)

Public Function AddToRecentDocument(FileName As String)
Call SHAddToRecentDocs(3, FileName)
End Function
Cara menggunakan fungsi VB6 di atas:
Private Sub Command1_Click()
AddToRecentDocument "C:\boot.ini"
End Sub
READ MORE - VB6 Code - Menambahkan File Ke Recent Document

VB6 Code - Class Untuk Mengetahui Crc32 Dari Sebuah File

Di bawah ini merupakan class VB6 untuk mengetahui CRC32 dari sebuah file. Untuk keperluan ini copy dan pastekan kode di bawah ini ke dalam class, kemudian ganti nama kelasnya menjadi clsCRC.
Option Explicit

Private crcTable(0 To 255) As Long 'crc32

Private Function CRC32(ByRef bArrayIn() As Byte, ByVal lLen As Long, Optional ByVal lcrc As Long = 0) As Long

Dim lCurPos As Long
Dim lTemp As Long

If lLen = 0 Then Exit Function 'In case of empty file
lTemp = lcrc Xor &HFFFFFFFF 'lcrc is for current value from partial check on the partial array

For lCurPos = 0 To lLen
lTemp = (((lTemp And &HFFFFFF00) \ &H100) And &HFFFFFF) Xor (crcTable((lTemp And 255) Xor bArrayIn(lCurPos)))
Next lCurPos

CRC32 = lTemp Xor &HFFFFFFFF

End Function

Private Function BuildTable() As Boolean

Dim I As Long, x As Long, crc As Long
Const Limit = &HEDB88320 'usally its shown backward, cant remember what it was.

For I = 0 To 255
crc = I
For x = 0 To 7
If crc And 1 Then
crc = (((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF) Xor Limit
Else
crc = ((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF
End If
Next x
crcTable(I) = crc
Next I

End Function

Private Sub Class_Initialize()
BuildTable
End Sub

Public Function CekCRC32(FileName As String) As String

Dim lngCrc As Long
Dim sCrc As Long

On Error GoTo ErrHandler

Open FileName For Binary Access Read As #1
ReDim tmp(LOF(1)) As Byte
Get #1, , tmp()
Close #1

lngCrc = UBound(tmp)
lngCrc = CRC32(tmp, lngCrc)
CekCRC32 = Hex(lngCrc)

Exit Function

ErrHandler:

MsgBox Err.Description, vbCritical, "Error"

End Function
Contoh penggunaan Class CRC32
Option  Explicit

Private Sub Form_Load()
Dim crc As New clsCRC
MsgBox crc.CekCRC32("C:\boot.ini")
End Sub
READ MORE - VB6 Code - Class Untuk Mengetahui Crc32 Dari Sebuah File

VB6 Code - Mencegah Aplikasi Dijalankan Dua Kali - Part-2

Di bawah ini merupakan prosedure VB6 kedua masih mengenai cara mencegah aplikasi dijalankan dua kali. Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak kodenya di bawah ini:
Option Explicit

Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long

Public Const GW_HWNDPREV = 3

Sub ActivatePrevInstance()

Dim AppTitle As String
Dim PrevHndl As Long
Dim result As Long

AppTitle = App.Title
App.Title = "unwanted instance"

If PrevHndl = 0 Then
PrevHndl = FindWindow("ThunderRT6Main", AppTitle)
If PrevHndl <> 0 Then
PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
result = OpenIcon(PrevHndl)
result = SetForegroundWindow(PrevHndl)
End
End If
End If

End Sub
Contoh penggunaan prosedure VB6 di atas:
Private Sub Form_Load()
If App.PrevInstance Then ActivatePrevInstance
End Sub
READ MORE - VB6 Code - Mencegah Aplikasi Dijalankan Dua Kali - Part-2

VB6 Code - Mengetahui Jumlah Tombol Yang Terdapat Pada Mouse

Di bawah ini merupakan fungsi VB6 untuk mengetahui jumlah tombol yang terdapat pada mouse.
Option Explicit

Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CMOUSEBUTTONS As Long = 43

Public Function ButtonMouse()
ButtonMouse = GetSystemMetrics(SM_CMOUSEBUTTONS)
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
MsgBox ButtonMouse
End Sub
READ MORE - VB6 Code - Mengetahui Jumlah Tombol Yang Terdapat Pada Mouse

VB6 Code - Apakah Mouse Terinstall Pada Komputer Anda?

Di bawah ini merupakan fungsi VB6 untuk memeriksa apakah mouse terinstall pada komputer Anda. Bagaimana implementasinya dalam Visual Basic 6.0? simaklah kodenya di bawah ini.
Option Explicit

Private Const SM_CMOUSEBUTTONS = 43
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Public Function IsMousePresent() As Boolean
IsMousePresent = (GetSystemMetrics(SM_CMOUSEBUTTONS) > 0)
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
MsgBox IsMousePresent
End Sub
READ MORE - VB6 Code - Apakah Mouse Terinstall Pada Komputer Anda?

VB6 Code - Merubah Waktu Double Klik Pada Mouse

Di bawah ini merupakan fungsi VB6 untuk merubah waktu double klik pada mouse. Bagaimana implementasinya dalam Visual Basic 6.0? Simaklah kodenya di bawah ini.
Option Explicit

Private Declare Function SetDoubleClickTime Lib "user32" (ByVal wCount As Long) As Long

Public Function ChangeDBClkTime(Time As Integer)
SetDoubleClickTime (Time)
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
Call ChangeDBClkTime(1000)
End Sub
READ MORE - VB6 Code - Merubah Waktu Double Klik Pada Mouse

VB6 Code - Mencegah Aplikasi Dijalankan Dua Kali

Di bawah ini merupakan cara termudah untuk mencegah sebuah aplikasi dijalankan dua kali (double instance) menggunakan VB6. Bagaimana implementasinya dalam Visual Basic 6.0? Simaklah kodenya di bawah ini.
Option Explicit

Private Sub ActivatePrevInstance()
AppActivate App.Title
SendKeys "+", True
End
End Sub
Contoh penggunaan procedure VB6 di atas:
Private Sub Form_Load()
If App.PrevInstance Then ActivatePrevInstance
End Sub
READ MORE - VB6 Code - Mencegah Aplikasi Dijalankan Dua Kali

VB6 Code - Memindahkan Seluruh File Dalam Satu Directory

Di bawah ini merupakan fungsi VB6 untuk memindahkan seluruh file dari satu directory tertentu. Untuk keperluan ini Anda harus mereferensi pada objek Microsoft Scripting Runtime atau scrun.dll.
Option Explicit

Public Function MoveAllFiles()
Dim fso As New FileSystemObject
Call fso.MoveFolder(Source, Destination)
Set fso = Nothing
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
Call MoveAllFiles("C:\djview", "D:\djview")
End Sub
READ MORE - VB6 Code - Memindahkan Seluruh File Dalam Satu Directory

VB6 Code - Mengcopy Seluruh File Dalam Satu Directory

Di bawah ini merupakan fungsi VB6 untuk meng-copy seluruh file dari satu directory tertentu. Untuk keperluan ini Anda harus mereferensi pada objek Microsoft Scripting Runtime atau scrun.dll.
Option Explicit

Public Function CopyAllFiles(Source As String, Destination As String)
Dim fso As New FileSystemObject
Call fso.CopyFolder(Source, Destination)
Set fso = Nothing
End Function
Contoh penggunaan fungsi di atas:
Private Sub Command1_Click()
Call CopyAllFiles("C:\djview", "D:\djview")
End Sub
READ MORE - VB6 Code - Mengcopy Seluruh File Dalam Satu Directory

VB6 Code Konversi Warna Dari Qbcolor Ke RGB

Di bawah ini merupakan fungsi VB6 untuk meng-konversi warna dari QBColor ke RGB. Bagaimana implementasinya dalam Visual Basic 6.0? simak kodenya di bawah ini:
Public Sub QBColorToRGB(QBColorValue As Integer)
QBColorToRGB = LongToRGB(QBColor(QBColorValue))
End Sub
READ MORE - VB6 Code Konversi Warna Dari Qbcolor Ke RGB

VB6 Code - Konversi Warna Dari Rgb Ke Long

Di bawah ini merupakan fungsi VB6 untuk meng-konversi warna dari RGB(red, green, blue) ke Long. Bagaimana implementasinya dalam Visual Basic 6.0? simak kodenya di bawah ini:
Public Function RGBToLong(Red As Integer, Green As Integer, Blue As Integer)
RGBToLong = RGB(Red, Green, Blue)
End Function
Contoh penggunaan fungsi konversi warna dari RGB ke Long
Private Sub Command1_Click()
MsgBox RGB(8, 12, 254)
End Sub
READ MORE - VB6 Code - Konversi Warna Dari Rgb Ke Long

VB6 Code - Konversi Warna Long Ke RGB

Di bawah ini merupakan fungsi VB6 untuk meng-konversi warna dari long ke rgb (red, green, blue). Bagaimana implementasinya dalam Visual Basic 6.0? simak kodenya di bawah ini:
Public Sub LongToRGB(Color As Long, Red, Green, Blue)
Blue = Color \ 65536
Green = (Color - Blue * 65536) \ 256
Red = Color - (Blue * 65536) - (Green * 256)
End Sub
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
Dim red
Dim green
Dim blue
Call LongToRGB(CLng("23489"), red, green, blue)
MsgBox red & "," & green & "," & blue
End Sub
READ MORE - VB6 Code - Konversi Warna Long Ke RGB

VB6 Code - Konversi Warna Dari RGB Ke Hex

Di bawah ini merupakan fungsi VB6 untuk meng-konversi warna dari rgb (red, green, blue) ke Hex. Bagaimana implementasinya dalam Visual Basic 6.0? simak kodenya di bawah ini:
Public Function RGBToHex(Red As Integer, Green As Integer, Blue As Integer)
RGBToHex = Right(0 & Hex(Red), 2) & Right(0 & Hex(Green), 2) & Right(0 & Hex(Blue), 2)
End Function
Contoh penggunaan fungsi konversi warna dari RGB ke HEX
Private Sub Command1_Click()
MsgBox RGBToHex(0, 0, 12)
End Sub
READ MORE - VB6 Code - Konversi Warna Dari RGB Ke Hex

VB6 Code - Konversi Angka Dari Hexa Ke Decimal

Di bawah ini merupakan fungsi VB6 untuk mengkonversi angka dari hexadecimal ke decimal dan sebaliknya. Adapun kode untuk mengkonversi angka dari hexa ke decimal dan sebaliknya menggunakan VB6 adalah sebagai berikut:
Option Explicit

Public Function DecToHex(DecNumber)
DecToHex = Hex(DecNumber)
End Function

Public Function HexToDec(HexNumber)
HexToDec = Val("&H" & HexNumber)
End Function
Contoh penggunaan Konversi angka dari decimal ke hexa
Private Sub Form_Load()
MsgBox DecToHex(120000)
End Sub
Contoh penggunaan konversi angka dari hexa ke decimal
Private Sub Form_Load()
MsgBox HexToDec(120000)
End Sub
READ MORE - VB6 Code - Konversi Angka Dari Hexa Ke Decimal

VB6 Code - Menyembunyikan Dan Menampilkan Pointer Mouse

Di bawah ini merupakan procedure VB6 untuk menyembunyikan dan menampilkan pointer mouse. Bagaimana implementasinya dalam Visual Basic 6.0, simaklah kodenya di bawah ini:
Option Explicit

Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

Sub ShowMouseCursor(bShow As Boolean)
ShowCursor bShow
End Sub
Dua contoh penggunaan menyembunyikan dan menampilkan pointer mouse
Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ShowMouseCursor (Check1.Value = 0)
End Sub

Private Sub Command1_Click()
ShowMouseCursor True
End Sub

READ MORE - VB6 Code - Menyembunyikan Dan Menampilkan Pointer Mouse

VB6 Code - Vertical Scrollbar Textbox Pada Saat Runtime

Di bawah ini merupakan fungsi VB6 untuk menampilkan Vertical ScrollBar pada TextBox.
Option Explicit

Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long

Public Function ShowScroll(obj As Control, bShow As Boolean)
ShowScrollBar obj.hwnd, 1, bShow
obj.Refresh
End Function
Contoh penggunaan kode VB6 di atas:
Public Sub Command1_Click()
ShowScroll Text1, True
End Sub
READ MORE - VB6 Code - Vertical Scrollbar Textbox Pada Saat Runtime

VB6 Code - Fungsi Untuk Membentuk Form Dari Huruf

Di bawah ini merupakan fungsi VB6 untuk membentuk form dari sebuah huruf, kata, atau kalimat. Untuk keperluan ini Anda dapat memodifikasi besar serta jenis hurufnya. Untuk keperluan-keperluan yang seperti ini, kita tidak bisa memprogramnya secara langsung akan tetapi harus melewati fungsi-fungsi API. Bagaimana implementasinya dalam Visual Basic 6.0? bisa Anda simak implementasinya di bawah ini:
Option Explicit

Private Declare Function SelectClipPath Lib "gdi32" (ByVal hDC As Long, ByVal iMode As Long) As Long
Private Declare Function BeginPath Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private Const txt = "ASEP" & vbCrLf & "HIBBAN"

Public Function MakeFormChar(frm As Form)
Dim hRgn As Long

With frm.Font
.Name = "Comic Sans MS"
.Bold = True
.Size = 100
End With

With frm
.Width = frm.TextWidth(txt)
.Height = frm.TextHeight(txt)
BeginPath .hDC
.CurrentX = 0
.CurrentY = 0
frm.Print txt
EndPath .hDC
hRgn = PathToRegion(.hDC)
SetWindowRgn .hwnd, hRgn, False
.Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2
End With

End Function
READ MORE - VB6 Code - Fungsi Untuk Membentuk Form Dari Huruf

VB6 Code - Fungsi Untuk Menghancurkan File

Di bawah ini merupakan fungsi VB6 untuk menghancurkan file. Maksud dari fungsi ini, agar file yang sudah dihapus/dihancurkan, tidak dapat direcover dengan software-software recovery.
Core function dari fungsi penghancur file ini hanyalah 3 line code, yaitu:
Open Filename For Output As #1
Print #1, "Sorry, destroyed....."
Close #1
Adapun fungsi lengkapnya serta cara penggunaannya:
Option Explicit

Public Function DestroyFile(Filename As String)
Open Filename For Output As #1
Print #1, "Sorry, destroyed....."
Close #1
End Function
Cara penggunaan Fungsi Untuk Menghancurkan File
Private Sub Command1_Click()
Call DestroyFile("C:\hancur.jpg")
End Sub
Di atas merupakan cara penggunaan yang sederhana, dalam kenyataannya Anda dapat memodifikasi penggunaan, sehingga bisa digunakan untuk bulk files destroyer.
READ MORE - VB6 Code - Fungsi Untuk Menghancurkan File

VB6 Code - Procedure Membatasi Pointer Mouse

Di bawah ini merupakan procedure VB6 untuk membatasi gerak pointer mouse pada objek tertentu yang memilliki hwnd (handle window).
Option Explicit

Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)

Private Type RECT
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type

Private Type POINT
x As Long
y As Long
End Type

Public Sub LimitCursorMovement(ctl As Object)

Dim client As RECT
Dim upperleft As POINT
Dim lHwnd As Long

On Error Resume Next

lHwnd = ctl.hWnd
If lHwnd = 0 Then Exit Sub

GetClientRect ctl.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
ClientToScreen ctl.hWnd, upperleft
OffsetRect client, upperleft.x, upperleft.y
ClipCursor client

End Sub

Public Sub ReleaseLimit()
ClipCursor ByVal 0&
End Sub
Contoh penggunaan procedureVB6  membatasi pointer mouse
Private Sub Command1_Click()
Command1.Caption = IIf(Command1.Caption = "Set Limit", "Release", "Set Limit")
If Command1.Caption = "Set Limit" Then
ReleaseLimit
Else
LimitCursorMovement Command1
End If
End Sub

Private Sub Form_Load()
Command1.Caption = "Set Limit"
End Sub
READ MORE - VB6 Code - Procedure Membatasi Pointer Mouse

VB Code - Menukarkan Tombol Mouse

Di bawah ini merupakan procedure VB6 untuk menukarkan tombol mouse, dari kiri ke kanan dan sebaliknya. Bagaimana implementasinya dalam Visual Basic 6.0, simaklah kodenya di bawah ini:
Option Explicit

Private Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As Long

Public Sub SwapMouse(bSwap As Boolean)
SwapMouseButton bSwap
End Sub
Dua contoh penggunaan menukarkan tombol mouse
Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SwapMouse (Check1.Value=0)
End Sub

Private Sub Command1_Click()
SwapMouse True
End Sub
READ MORE - VB Code - Menukarkan Tombol Mouse

VB6 Code - Menggerakan Pointer Mouse Satu Koordinat

Di bawah ini merupakan fungsi VB6 untuk menggerakan pointer mouse pada koordinat tertentu.
Private Declare Function SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As Long) As Long
Contoh penggunaan code untuk menggerakan pointer mouse pada koordinat tertentu
Private Sub Command1_Click()
Call SetCursorPos(100, 200)
End Sub
READ MORE - VB6 Code - Menggerakan Pointer Mouse Satu Koordinat

VB6 Code - Menutup Seluruh Aplikasi Yang Sedang Berjalan

Di bawah ini merupakan fungsi VB6 untuk menutup seluruh aplikasi yang sedang berjalan. Mengapa seluruh aplikasi yang sedang berjalan tersebut harus ditutup? contoh kecilnya dalam pembuatan billing warnet. Misalnya A (user) log-out, kemudian datang B (user baru) log-in, B tidak akan melihat aplikasi-aplikasi yang masih terbuka (kemungkinan lupa ditutup oleh A), karena seluruh aplikasi yang sedang berjalan telah ditutup secara otomatis dengan fungsi di bawah ini.
Mungkin ada pertanyaan, Apakah ditutup dengan software billing warnetnya juga? ya, boleh jika kita mau, bahkan sekalian di shutdown pula.
Option Explicit

Public Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, _
ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Public Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Const SMTO_BLOCK = &H1
Public Const SMTO_ABORTIFHUNG = &H2
Public Const SC_CLOSE = &HF060&
Public Const WM_SYSCOMMAND = &H112
Public Const WM_NULL = &H0
Public Const PROCESS_ALL_ACCESS = &H1F0FFF

Public HWND_Taskbar As Long
Public HWND_Desktop As Long
Public HWND_ExplorerW As Long

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long

Dim lThreadID As Long
Dim lPid As Long
Dim lHp As Long

If hwnd <> HWND_Taskbar And hwnd <> HWND_Desktop And hwnd <> HWND_ExplorerW Then
lThreadID = GetWindowThreadProcessId(hwnd, lPid)
If lThreadID <> App.ThreadID Then
If IsWindowVisible(hwnd) Then
SendMessageTimeout hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, 0, 500, 0
If IsWindow(hwnd) Then
lHp = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPid)
TerminateProcess lHp&, 0&
CloseHandle lHp
End If
End If
End If
End If

EnumWindowsProc = 1

End Function

Public Sub CloseAllRuning()
HWND_Desktop = FindWindowEx(0&, 0&, "Progman", vbNullString)
HWND_Taskbar = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
Contoh Penggunaan fungsi untuk menutup seluruh aplikasi menggunakan VB6:
Sub Main()
Call CloseAllRuning
End Sub
READ MORE - VB6 Code - Menutup Seluruh Aplikasi Yang Sedang Berjalan

VB Code - Meng-capture Screen .bmp Atau .jpg (Ezcapture.dll)

Di bawah ini merupakan fungsi VB6 untuk meng-capture (mengambil) gambar screen dalam format .bmp atau format .jpg dengan menggunakan ActiveX ezCapture.dll. Untuk keperluan ini tentu saja Anda harus memiliki dll ezCapture.dll kemudian mereferensikan project Anda terhadapnya. Mengenai ezCapture.dll bisa Anda download di sini.

Fungsi VB6 untuk meng-Capture screen dalam format .bmp

Option Explicit

Sub CaptureScreenBMP()
Dim ezCapture As New CaptureScreen
On Error Resume Next
With ezCapture
.CaptureFullScreen "C:\screen.bmp"
End With
End Sub

Fungsi VB6 untuk meng-Capture screen dalam format .jpg
Sub CaptureScreenJPG()
Dim ezCapture As New CaptureScreen
With ezCapture
.CaptureFullScreen "C:\screen.jpg"
End With
End Sub

Contoh penggunaan fungsi capture screen .bmp
Private Sub Command1_Click()
CaptureScreenBMP
End Sub

Contoh penggunaan fungsi capture screen .jpg.
Untuk keperluan ini Anda membutuhkan satu file lagi yakni "ijl11.dll"
Private Sub Command2_Click()
CaptureScreenJPG
End Sub
READ MORE - VB Code - Meng-capture Screen .bmp Atau .jpg (Ezcapture.dll)