Common dialog

i980565 Messages postés 4 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 25 juillet 2003 - 24 juil. 2003 à 16:31
i980565 Messages postés 4 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 25 juillet 2003 - 25 juil. 2003 à 11:27
Hi you all,

I've got a question regarding the common dialog box. I know how to open the common dialog, but when selecting the file, it does not open. When clicking the open button, it only shows the path of the file. This is the code I used:

Option Explicit

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

Private Sub Command1_Click()
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = Form1.hWnd
OpenFile.hInstance = App.hInstance
sFilter = "all Files (*.*)" & Chr(0) & "*.*" & 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 = "d:\database\brieven"
OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "The User pressed the Cancel Button"
Else
MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
End If

End Sub

It probably has to do with the last part. So if somebody could help me with this, I would really appreciate it!!

Thanx

2 réponses

cs_kramp Messages postés 13 Date d'inscription mardi 7 mai 2002 Statut Membre Dernière intervention 5 novembre 2004
24 juil. 2003 à 17:23
common dialog only give you the file name & path. It doesn't open anything. You have to open your file with an adapted method (depending on the file type)

KRAMP
0
i980565 Messages postés 4 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 25 juillet 2003
25 juil. 2003 à 11:27
thanx for your reply
0
Rejoignez-nous