Search Tools Links Login

Dialog - file - using API

Visual Basic 6, or VB Classic

The following is reprinted for archival purposes from Gary Beene's Information Center, with permission from Mr. Beene himself.

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

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 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
    txtTemp.Text = OpenFile.lpstrFile
    txtTemp.Text = Mid $(txtTemp.Text, InStrRev(txtTemp.Text, "\") + 1)
  End If
End Sub

About this post

Posted: 2021-02-11
By: ArchiveBot
Viewed: 285 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.