Caranya Hanya Dengan Mengganti Activex Dengan ClassModules
Yang Sudah Ada Pada Visual Basic Sendiri...!!! Yuk Kita Belajar!!
Klik Menu Project Lalu Add ClassModules (Name : "CommonDialog"
Lalu Coding Di ClassModules Itu :
'#########Start Here#########
'Created by Wheldt
'Name ClassModule: CommonDialog
'Catatan: ClassModule ini dapat disertakan diberbagai aplikasi
'VB6, jadi tidak perlu lagi menggunakan file COMDLG32.OCX untuk
'membuat CommonDialog.
'GNU General Public License : Wheldthacker.blogspot.com
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenFileName As Any) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenFileName As Any) As Long
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Dim OFName As OPENFILENAME
Public Sub ShowOpen()
If (GetOpenFileName(OFName) <> 0) Then
'Berhasil jika tidak bernilai 0
End If
End Sub
Public Sub ShowSave()
If (GetSaveFileName(OFName) <> 0) Then
'Berhasil jika tidak bernilai 0
End If
End Sub
Property Let FileName(ByVal lpFileName As String)
'Selesai (Untuk memasukan nama file yang dipilih)
OFName.lpstrFile = Trim$(lpFileName)
End Property
Property Get FileName() As String
'Selesai (Untuk mendapatkan nama file yang dipilih)
FileName = Trim$(OFName.lpstrFile)
End Property
Property Let InitDir(ByVal lpDirectory As String)
'Selesai (Untuk menginisialisasikan Directory yang akan
'dibuka pertama kali)
If (Right$(lpDirectory, 1) <> "\") Then
lpDirectory = lpDirectory & "\"
End If
OFName.lpstrInitialDir = lpDirectory
End Property
Property Let DialogTitle(ByVal lpTitle As String)
'Selesai (Judul Dialog)
OFName.lpstrTitle = lpTitle
End Property
Property Let Filter(ByVal lpExtension As String)
'Selesai (Penyaring [Filter] untuk ekstensi file)
lpExtension = Replace(lpExtension, "|", Chr$(0))
OFName.lpstrFilter = lpExtension
End Property
Private Sub Class_Initialize()
'Menginisialisasikan Class untuk dipakai pada
'fungsi ShowOpen dan ShowSave.
OFName.hwndOwner = GetForegroundWindow
OFName.lStructSize = Len(OFName)
OFName.hInstance = App.hInstance
OFName.nMaxFile = 255
OFName.lpstrFileTitle = Space$(254)
OFName.lpstrFile = Space$(254)
OFName.nMaxFileTitle = 255
OFName.flags = 0
End Sub
'########End Here#########
Lalu Tambahkan Object Command Button ("Command1 Dan Command2")
Coding :
'#########Start Here#########
Private Sub Command1_Click()
Dim CD As New CommonDialog
CD.DialogTitle = "Buka file"
CD.Filter = "Semua file (*.*)|*.*"
'CD.InitDir = "C:"
CD.ShowOpen
If (CD.FileName <> vbNullString) Then
Text1.Text = CD.FileName
End If
End Sub
Private Sub Command2_Click()
Dim CD As New CommonDialog
CD.DialogTitle = "Simpan file"
CD.Filter = "File teks (*.txt)|*.txt|Semua file (*.*)|*.*"
'CD.InitDir = "C:"
CD.ShowSave
If (CD.FileName <> vbNullString) Then
Text1.Text = CD.FileName
End If
End Sub
'########End Here#########
Nah Tinggal Compile Deh...!!!
Yang Sudah Ada Pada Visual Basic Sendiri...!!! Yuk Kita Belajar!!
Klik Menu Project Lalu Add ClassModules (Name : "CommonDialog"
Lalu Coding Di ClassModules Itu :
'#########Start Here#########
'Created by Wheldt
'Name ClassModule: CommonDialog
'Catatan: ClassModule ini dapat disertakan diberbagai aplikasi
'VB6, jadi tidak perlu lagi menggunakan file COMDLG32.OCX untuk
'membuat CommonDialog.
'GNU General Public License : Wheldthacker.blogspot.com
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenFileName As Any) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenFileName As Any) As Long
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Dim OFName As OPENFILENAME
Public Sub ShowOpen()
If (GetOpenFileName(OFName) <> 0) Then
'Berhasil jika tidak bernilai 0
End If
End Sub
Public Sub ShowSave()
If (GetSaveFileName(OFName) <> 0) Then
'Berhasil jika tidak bernilai 0
End If
End Sub
Property Let FileName(ByVal lpFileName As String)
'Selesai (Untuk memasukan nama file yang dipilih)
OFName.lpstrFile = Trim$(lpFileName)
End Property
Property Get FileName() As String
'Selesai (Untuk mendapatkan nama file yang dipilih)
FileName = Trim$(OFName.lpstrFile)
End Property
Property Let InitDir(ByVal lpDirectory As String)
'Selesai (Untuk menginisialisasikan Directory yang akan
'dibuka pertama kali)
If (Right$(lpDirectory, 1) <> "\") Then
lpDirectory = lpDirectory & "\"
End If
OFName.lpstrInitialDir = lpDirectory
End Property
Property Let DialogTitle(ByVal lpTitle As String)
'Selesai (Judul Dialog)
OFName.lpstrTitle = lpTitle
End Property
Property Let Filter(ByVal lpExtension As String)
'Selesai (Penyaring [Filter] untuk ekstensi file)
lpExtension = Replace(lpExtension, "|", Chr$(0))
OFName.lpstrFilter = lpExtension
End Property
Private Sub Class_Initialize()
'Menginisialisasikan Class untuk dipakai pada
'fungsi ShowOpen dan ShowSave.
OFName.hwndOwner = GetForegroundWindow
OFName.lStructSize = Len(OFName)
OFName.hInstance = App.hInstance
OFName.nMaxFile = 255
OFName.lpstrFileTitle = Space$(254)
OFName.lpstrFile = Space$(254)
OFName.nMaxFileTitle = 255
OFName.flags = 0
End Sub
'########End Here#########
Lalu Tambahkan Object Command Button ("Command1 Dan Command2")
Coding :
'#########Start Here#########
Private Sub Command1_Click()
Dim CD As New CommonDialog
CD.DialogTitle = "Buka file"
CD.Filter = "Semua file (*.*)|*.*"
'CD.InitDir = "C:"
CD.ShowOpen
If (CD.FileName <> vbNullString) Then
Text1.Text = CD.FileName
End If
End Sub
Private Sub Command2_Click()
Dim CD As New CommonDialog
CD.DialogTitle = "Simpan file"
CD.Filter = "File teks (*.txt)|*.txt|Semua file (*.*)|*.*"
'CD.InitDir = "C:"
CD.ShowSave
If (CD.FileName <> vbNullString) Then
Text1.Text = CD.FileName
End If
End Sub
'########End Here#########
Nah Tinggal Compile Deh...!!!
0 komentar:
Posting Komentar