i980565
Messages postés4Date d'inscriptionmardi 22 juillet 2003StatutMembreDernière intervention25 juillet 2003
-
24 juil. 2003 à 16:31
i980565
Messages postés4Date d'inscriptionmardi 22 juillet 2003StatutMembreDernière intervention25 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!!
cs_kramp
Messages postés13Date d'inscriptionmardi 7 mai 2002StatutMembreDerniè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)