Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Dialog - file - using API


Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) 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


Sub SelectFile()
  Dim OpenFile As OPENFILENAME
  Dim lReturn As Long
  Dim sFilter As String
  Dim BackImage As String

 OpenFile.lStructSize = Len(OpenFile)
 OpenFile.hwndOwner = frmMain.hwnd
 OpenFile.hInstance = App.hInstance
 sFilter = "Image Files (*.jpg)" & Chr (0) & "*.jpg" & Chr (0)
 OpenFile.lpstrFilter = sFilter
 OpenFile.nFilterIndex = 1
 OpenFile.lpstrFile = String (257, 0)
 OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
 OpenFile.lpstrFileTitle = OpenFile.lpstrFile
 OpenFile.nMaxFileTitle = OpenFile.nMaxFile
 OpenFile.lpstrInitialDir = App.path    '"C:\"
 OpenFile.lpstrTitle = "Select Background (Tile) Image File"
 OpenFile.Flags = 0
 lReturn = GetOpenFileName(OpenFile)
  If lReturn = 0 Then
     'no action
  Else
    txtTemp.Text = OpenFile.lpstrFile
    txtTemp.Text = Mid $(txtTemp.Text, InStrRev(txtTemp.Text, "\") + 1)
  End If
End Sub