|
-
Aug 8th, 2002, 07:31 AM
#1
Thread Starter
New Member
Open window
Well this could be a stupid question, but who cares.
I would like to make a kind of browse window, like you have for example in the internet explorer file menu and the option open.
I know there is a site somewhere where I could download the sample code, but I don't know which one it is anymore.
The second problem is that I don't know how to call this 'open file window' in english, so that makes searching very difficult.
So if someone knows a site where I could download this sample code or how I could search this in english, I would be gratefull.
-
Aug 8th, 2002, 07:37 AM
#2
Software Eng.
Use a CommonDialog control e.g.
VB Code:
Private Sub Command1_Click()
On Error Resume Next
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
CommonDialog1.FileName = ""
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
'If OK was pressed
If Err <> 32755 Then
MsgBox "You selected " & CommonDialog1.FileName
End If
End Sub
-
Aug 8th, 2002, 07:44 AM
#3
Software Eng.
You could also use the GetOpenFileName API. It's a little longer, but it saves you from having to include the CommonDialog OCX with your project.
VB Code:
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 Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Sub Command1_Click()
Dim tOFN As OPENFILENAME
tOFN.lStructSize = Len(tOFN)
tOFN.hwndOwner = Me.hWnd
tOFN.lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt"
tOFN.nMaxFile = 255
tOFN.nMaxFileTitle = 255
tOFN.lpstrFile = Space$(254)
tOFN.lpstrFileTitle = Space$(254)
'If OK was pressed
If GetOpenFileName(tOFN) Then
tOFN.lpstrFile = Left(tOFN.lpstrFile, InStr(1, tOFN.lpstrFile, vbNullChar))
MsgBox "You selected " & tOFN.lpstrFile
End If
End Sub
-
Aug 8th, 2002, 07:55 AM
#4
Thread Starter
New Member
-
Aug 8th, 2002, 08:00 AM
#5
Software Eng.
Your welcome
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|