Results 1 to 5 of 5

Thread: Open window

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    8

    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.

  2. #2
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Use a CommonDialog control e.g.
    VB Code:
    1. Private Sub Command1_Click()
    2.    
    3.     On Error Resume Next
    4.    
    5.     CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
    6.     CommonDialog1.FileName = ""
    7.     CommonDialog1.CancelError = True
    8.     CommonDialog1.ShowOpen
    9.    
    10.     'If OK was pressed
    11.     If Err <> 32755 Then
    12.         MsgBox "You selected " & CommonDialog1.FileName
    13.     End If
    14.    
    15. End Sub

  3. #3
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    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:
    1. Private Type OPENFILENAME
    2.     lStructSize As Long
    3.     hwndOwner As Long
    4.     hInstance As Long
    5.     lpstrFilter As String
    6.     lpstrCustomFilter As String
    7.     nMaxCustFilter As Long
    8.     nFilterIndex As Long
    9.     lpstrFile As String
    10.     nMaxFile As Long
    11.     lpstrFileTitle As String
    12.     nMaxFileTitle As Long
    13.     lpstrInitialDir As String
    14.     lpstrTitle As String
    15.     flags As Long
    16.     nFileOffset As Integer
    17.     nFileExtension As Integer
    18.     lpstrDefExt As String
    19.     lCustData As Long
    20.     lpfnHook As Long
    21.     lpTemplateName As String
    22. End Type
    23. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    24.  
    25. Private Sub Command1_Click()
    26.  
    27.     Dim tOFN As OPENFILENAME
    28.     tOFN.lStructSize = Len(tOFN)
    29.  
    30.     tOFN.hwndOwner = Me.hWnd
    31.     tOFN.lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt"
    32.     tOFN.nMaxFile = 255
    33.     tOFN.nMaxFileTitle = 255
    34.     tOFN.lpstrFile = Space$(254)
    35.     tOFN.lpstrFileTitle = Space$(254)
    36.    
    37.     'If OK was pressed
    38.     If GetOpenFileName(tOFN) Then
    39.         tOFN.lpstrFile = Left(tOFN.lpstrFile, InStr(1, tOFN.lpstrFile, vbNullChar))
    40.         MsgBox "You selected " & tOFN.lpstrFile
    41.     End If
    42.    
    43. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    8

    Thumbs up


    Excellent, thank you very much

  5. #5
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    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
  •  



Click Here to Expand Forum to Full Width