Results 1 to 5 of 5

Thread: GetOpenFileName ???

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    10
    Thanks Hack!
    This works very well but i want use GetOpenFileName API and not the COMMON DIALOG object.

    JoshT thanks for your replies, i've not understand very well...

    if you have a complete example....

    However THANKS ALL!!

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Can you follow this? I snipped the API declarations for brevity - you proably already have them or can look them up.


    VB Code:
    1. Public Function ShowOpen(hwndOwner As Long) As String
    2.     Dim OFN As OPENFILENAME 'struct
    3.     Dim retval As Long 'API return value
    4.    
    5.     strFileName = "" 'make sure this doesn't stay in memory
    6.     lngPrevProc = 0
    7.  
    8.     With OFN
    9.         .lStructSize = Len(OFN)
    10.         .hwndOwner = hwndOwner
    11.         .hInstance = 0
    12.         .lpstrFilter = "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
    13.         '.lpstrCustomFilter = vbNullChar
    14.         .nMaxCustFilter = 0
    15.         .nFilterIndex = 1
    16.         .lpstrFile = String$(257, vbNullChar)
    17.         .nMaxFile = Len(.lpstrFile)
    18.         .lpstrFileTitle = String$(257, vbNullChar)
    19.         .nMaxFileTitle = Len(.lpstrFileTitle)
    20.         .lpstrInitialDir = "C:\" & vbNullChar
    21.         .lpstrTitle = "Select a file to open:" & vbNullChar
    22.         .flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or OFN_EXPLORER _
    23.             Or OFN_ENABLEHOOK
    24.         .nFileOffset = 0
    25.         .nFileExtension = 0
    26.         '.lpstrDefExt = vbNullChar
    27.         .lCustData = 0
    28.         .lpfnHook = Wrap(AddressOf OFNHookProc)
    29.         '.lpTemplateName = vbNullChar
    30.     End With
    31.  
    32.     retval = GetOpenFileName(OFN)
    33.    
    34.     If retval <> 0 Then
    35.         ShowOpen = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, vbNullChar) - 1)
    36.     End If
    37. End Function
    38.  
    39. 'function to hook the common dialog
    40. Private Function OFNHookProc(ByVal hwnd As Long, _
    41.                             ByVal uMsg As Long, _
    42.                             ByVal wParam As Long, _
    43.                             ByVal lParam As Long) As Long
    44.     Static c As Long
    45.     Dim hwndParent As Long 'handle to the parent window
    46.     Dim retval As Long 'api return value
    47.    
    48.     c = c + 1
    49.     Debug.Print "OFNHookProc Called " & c
    50.    
    51.     Select Case uMsg
    52.         Case WM_INITDIALOG 'initilization of the file open dialog box
    53.             hwndParent = GetParent(hwnd)
    54.             'set custom text
    55.             If hwndParent <> 0 Then
    56.                 retval = SendMessage(hwndParent, CDM_SETCONTROLTEXT, IDFILENAMETEXT, ByVal "File Name:")
    57.                 retval = SendMessage(hwndParent, CDM_SETCONTROLTEXT, IDFILEOFTYPETEXT, ByVal "Files of Type:")
    58.             End If
    59.            
    60.         Case WM_DESTROY 'sent before any child windows are destroyed yet
    61.         Case Else
    62.             OFNHookProc = 0
    63.     End Select
    64. End Function
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    10
    Perfect works very well!

    only two constants....
    IDFILENAMETEXT = ???
    IDFILEOFTYPETEXT =???

    THANKS!

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    VB Code:
    1. Private Const IDFILEOFTYPETEXT As Long = &H441&
    2. Private Const IDFILENAMETEXT As Long = &H442&
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    10

    Thanks JoshT!
    your are very good friend!

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