Selasa, 02 Agustus 2011

Get Default Program By Extension VB6

Berikut ini adalah cara menampilkan nama program default untuk membuka suatu file berdasarkan ekstensinya di visual basic 6, untuk mempraktekannya siapkan :
1. Buat 1 Project baru dengan 1 Form, 1 Module, dan 1 ComboBox.
2. Copy-kan coding berikut ke editor form & module yang bertalian.

          '--- Coding ini di Module...
          Declare Function FindExecutable Lib _
              "shell32.dll" Alias "FindExecutableA" _
              (ByVal lpFile As String, ByVal lpDirectory _
              As String, ByVal lpResult As String) As Long

          Declare Function GetTempFileName Lib _
              "kernel32" Alias "GetTempFileNameA" (ByVal _
              lpszPath As String, ByVal lpPrefixString _
              As String, ByVal wUnique As Long, ByVal _
              lpTempFileName As String) As Long


          Declare Function GetTempPath Lib _
              "kernel32" Alias "GetTempPathA" (ByVal _
              nBufferLength As Long, ByVal lpBuffer As _
              String) As Long

          '--- Akhir coding di Module...

          '--- Coding ini di Form...
          Public Function GetAssociatedProgram(ByVal _

              Extension As String) As String
              Dim Path As String
              Dim FileName As String
              Dim nRet As Long
              Const MAX_PATH As Long = 260  

              'Buat sebuah file temporal
              Path = String$(MAX_PATH, 0)   
              If GetTempPath(MAX_PATH, Path) Then
                  FileName = String$(MAX_PATH, 0)   

                  If GetTempFileName(Path, "~", 0, FileName) Then
                      FileName = Left$(FileName, _
                          InStr(FileName, vbNullChar) - 1)       
                      'Rename file untuk menambahkan ekstensi

                      Name FileName As Left$(FileName, _
                          InStr(FileName, ".")) & Extension
                          FileName = Left$(FileName, _
                          InStr(FileName, ".")) & Extension       
                      'Ambil assosiasi ekstensi EXE

                      Path = String$(MAX_PATH, 0)       
                      Call FindExecutable(FileName, _
                          vbNullString, Path)
                      GetAssociatedProgram = Left$( _

                          Path, InStr(Path, vbNullChar) - 1)       
                      'Hapus file temporal
                      Kill FileName       
                  End If

              End If
          End Function

          Private Sub Command1_Click()
              MsgBox GetAssociatedProgram(Combo1.Text)

          End Sub

          Private Sub Form_Load()
            With Combo1
              .AddItem "TXT"
              .AddItem "DOC"
              .AddItem "XLS"
              .AddItem "JPG"
              .AddItem "BMP"
              .AddItem "GIF"
              .AddItem "DAT"
              .AddItem "MP3"
              .Text = "TXT"

            End With
          End Sub
          '--- Akhir coding di Form...

Tags:
contoh program vb6, contoh fungsi di vb6, cara penggunaan fungsi vb, tutorial vb6, download tutorial vb6, vb6 tutorial download, dasar dasar vb6, belajar vb6, cara mudah belajar vb6, vb6 artikel download, vb6 blog, contoh program vb6, artikel vb6, semua tentang vb6, vb6 api, cara menggunakan module, cara menggunakan class module

Ditulis Oleh : Wahyu Aji // 18.23
Kategori:

0 komentar:

Posting Komentar