retrieve directory (not file) info with an API (WinnNT4.0) 
Author Message
 retrieve directory (not file) info with an API (WinnNT4.0)

Alain,

(Think i first found this code on Dev Ashishs website)

Paste the following into a module and use the function fDialog to
call the explorer dialog. Believe the first two variables in the call
should be set to true for directory only...

' General Errors
Public Const adhcAccErrSuccess = 0
Public Const adhcAccErrUnknown = -1
' Common Dialogs
' GetFileName errors
Public Const adhcAccErrGFNCantOpenDialog = -301
Public Const adhcAccErrGFNUserCancelledDialog = -302

' GetFileNameInfo flags
Public Const adhcGfniConfirmReplace = &H1              ' Prompt if
overwriting a file?
Public Const adhcGfniNoChangeDir = &H2                ' Disable the
read-only option
Public Const adhcGfniAllowReadOnly = &H4                   ' Don't
change to the directory the user selected?
Public Const adhcGfniAllowMultiSelect = &H8            ' Allow
multiple-selection?
Public Const adhcGfniDirectoryOnly = &H20              ' Open as
directory picker?
Public Const adhcGfniInitializeView = &H40             ' Initialize
the view to the lView member or use last selected view?

' Views in the Office Find File dialog
Public Const adhcGfniViewDetails = 0                  ' Details
Public Const adhcGfniViewPreview = 1                  ' Preview
Public Const adhcGfniViewProperties = 2               ' Properties
Public Const adhcGfniViewList = 3                     ' List
(typical)

Type adh_accOfficeGetFileNameInfo
    hwndOwner As Long
    strAppName As String * 255
    strDlgTitle As String * 255
    strOpenTitle As String * 255
    strFile As String * 4096
    strInitialDir As String * 255
    strFilter As String * 255
    lngFilterIndex As Long
    lngView As Long
    lngFlags As Long
End Type

Declare Function adh_accOfficeGetFileName Lib "msaccess.exe" _
 Alias "#56" (gfni As adh_accOfficeGetFileNameInfo, ByVal fOpen As
Integer) As Long

Public Function fDialog(booOpen As Boolean, _
                        booDirOnly As Boolean, _
                        Optional strDialogTitle As String, _
                        Optional strButtonText As String, _
                        Optional strInitDir As String, _
                        Optional strFilters As String) As String
'on error GoTo err_handle
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'STANDARD FILE OPEN/SAVE DIALOG USED IN OFFICE
'---------------------------------------------------------------------------------------------
'EXAMPLE CALL
'Me!txtText = fDialog(True, False, "File Open Dialog", "Open File", ,
"Database File (*.mdb)")
'---------------------------------------------------------------------------------------------
'AVAILABLE FILTERS
'DELIMITED BY '|'
'HTML (*.html;*.htm)
'HTM Files (*.htm)
'HTX Files (*.htx)
'Database File (*.mdb)
'Text Files (*.txt)
'Ascii Files (*.asc)
'Spreadsheet Files (*.xls)
'Document Files (*.doc)
'All Files (*.*)"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim gfni As adh_accOfficeGetFileNameInfo
    With gfni
        .hwndOwner = Application.hWndAccessApp
        .strDlgTitle = strDialogTitle
        .strOpenTitle = strButtonText
        .strFile = ""
        .strInitialDir = strInitDir
        .strFilter = strFilters
        .lngFilterIndex = 1
        .lngView = adhcGfniViewList
        If booDirOnly Then
            .lngFlags = adhcGfniDirectoryOnly
        End If
    End With
    If adhOfficeGetFileName(gfni, booOpen) = adhcAccErrSuccess Then
         fDialog = Trim(gfni.strFile)
    End If
err_exit:
Exit Function
err_handle:
Call fLogError(err.Number, "fDialog: " & err.Source, err.description)
Resume err_exit
End Function

Function adhOfficeGetFileName(gfni As adh_accOfficeGetFileNameInfo, _
 ByVal fOpen As Integer) As Long

    ' Use the Office file selector common dialog
    ' exposed by Access.

    Dim lng As Long
    With gfni
        .strAppName = RTrim$(.strAppName) & vbNullChar
        .strDlgTitle = RTrim$(.strDlgTitle) & vbNullChar
        .strOpenTitle = RTrim$(.strOpenTitle) & vbNullChar
        .strFile = RTrim$(.strFile) & vbNullChar
        .strInitialDir = RTrim$(.strInitialDir) & vbNullChar
        .strFilter = RTrim$(.strFilter) & vbNullChar
        SysCmd acSysCmdClearHelpTopic
        lng = adh_accOfficeGetFileName(gfni, fOpen)
        .strAppName = RTrim$(adhTrimNull(.strAppName))
        .strDlgTitle = RTrim$(adhTrimNull(.strDlgTitle))
        .strOpenTitle = RTrim$(adhTrimNull(.strOpenTitle))
        .strFile = RTrim$(adhTrimNull(.strFile))
        .strInitialDir = RTrim$(adhTrimNull(.strInitialDir))
        .strFilter = RTrim$(adhTrimNull(.strFilter))
    End With
    adhOfficeGetFileName = lng
End Function

Function adhTrimNull(strVal As String) As String
    Dim intPos As Integer
    intPos = InStr(strVal, vbNullChar)
    If intPos > 0 Then
        adhTrimNull = Left$(strVal, intPos - 1)
    Else
        adhTrimNull = strVal
    End If
End Function

Hope this helps,

James

Quote:

> Dear all,

>    help on this matter will be greatly appreciated.

> I want to open an Explorer like window (see attached file)
> to retrieve the path of a directory, not of a file.

> I know that an API exists for Window2000, but I
> haven't found anything for NT.

>   ---------------------------------------------------------------------
>                    Name: Explorer.bmp
>    Explorer.bmp    Type: Bitmap Image (image/bmp)
>                Encoding: base64



Sat, 07 Feb 2004 22:21:56 GMT  
 retrieve directory (not file) info with an API (WinnNT4.0)
Much thanks,

    this is exactly what I needed.

Alain.

Quote:
>-----Original Message-----
>Alain,

>(Think i first found this code on Dev Ashishs website)

>Paste the following into a module and use the function
fDialog to
>call the explorer dialog. Believe the first two variables
in the call
>should be set to true for directory only...

>' General Errors
>Public Const adhcAccErrSuccess = 0
>Public Const adhcAccErrUnknown = -1
>' Common Dialogs
>' GetFileName errors
>Public Const adhcAccErrGFNCantOpenDialog = -301
>Public Const adhcAccErrGFNUserCancelledDialog = -302

>' GetFileNameInfo flags
>Public Const adhcGfniConfirmReplace = &H1              '
Prompt if
>overwriting a file?
>Public Const adhcGfniNoChangeDir = &H2                '
Disable the
>read-only option
>Public Const adhcGfniAllowReadOnly =

&H4                   ' Don't

- Show quoted text -

Quote:
>change to the directory the user selected?
>Public Const adhcGfniAllowMultiSelect = &H8            '
Allow
>multiple-selection?
>Public Const adhcGfniDirectoryOnly = &H20              '
Open as
>directory picker?
>Public Const adhcGfniInitializeView = &H40             '
Initialize
>the view to the lView member or use last selected view?

>' Views in the Office Find File dialog
>Public Const adhcGfniViewDetails = 0                  '
Details
>Public Const adhcGfniViewPreview = 1                  '
Preview
>Public Const adhcGfniViewProperties = 2               '
Properties
>Public Const adhcGfniViewList = 3                     '
List
>(typical)

>Type adh_accOfficeGetFileNameInfo
>    hwndOwner As Long
>    strAppName As String * 255
>    strDlgTitle As String * 255
>    strOpenTitle As String * 255
>    strFile As String * 4096
>    strInitialDir As String * 255
>    strFilter As String * 255
>    lngFilterIndex As Long
>    lngView As Long
>    lngFlags As Long
>End Type

>Declare Function adh_accOfficeGetFileName

Lib "msaccess.exe" _

- Show quoted text -

Quote:
> Alias "#56" (gfni As adh_accOfficeGetFileNameInfo, ByVal
fOpen As
>Integer) As Long

>Public Function fDialog(booOpen As Boolean, _
>                        booDirOnly As Boolean, _
>                        Optional strDialogTitle As
String, _
>                        Optional strButtonText As String,
_
>                        Optional strInitDir As String, _
>                        Optional strFilters As String) As
String
>'on error GoTo err_handle
>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''
Quote:
>'STANDARD FILE OPEN/SAVE DIALOG USED IN OFFICE
>'---------------------------------------------------------

------------------------------------
Quote:
>'EXAMPLE CALL
>'Me!txtText = fDialog(True, False, "File Open

Dialog", "Open File", ,
Quote:
>"Database File (*.mdb)")
>'---------------------------------------------------------

------------------------------------
Quote:
>'AVAILABLE FILTERS
>'DELIMITED BY '|'
>'HTML (*.html;*.htm)
>'HTM Files (*.htm)
>'HTX Files (*.htx)
>'Database File (*.mdb)
>'Text Files (*.txt)
>'Ascii Files (*.asc)
>'Spreadsheet Files (*.xls)
>'Document Files (*.doc)
>'All Files (*.*)"
>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''

- Show quoted text -

Quote:

>    Dim gfni As adh_accOfficeGetFileNameInfo
>    With gfni
>        .hwndOwner = Application.hWndAccessApp
>        .strDlgTitle = strDialogTitle
>        .strOpenTitle = strButtonText
>        .strFile = ""
>        .strInitialDir = strInitDir
>        .strFilter = strFilters
>        .lngFilterIndex = 1
>        .lngView = adhcGfniViewList
>        If booDirOnly Then
>            .lngFlags = adhcGfniDirectoryOnly
>        End If
>    End With
>    If adhOfficeGetFileName(gfni, booOpen) =

adhcAccErrSuccess Then
Quote:
>         fDialog = Trim(gfni.strFile)
>    End If
>err_exit:
>Exit Function
>err_handle:
>Call fLogError(err.Number, "fDialog: " & err.Source,
err.description)
>Resume err_exit
>End Function

>Function adhOfficeGetFileName(gfni As

adh_accOfficeGetFileNameInfo, _

- Show quoted text -

Quote:
> ByVal fOpen As Integer) As Long

>    ' Use the Office file selector common dialog
>    ' exposed by Access.

>    Dim lng As Long
>    With gfni
>        .strAppName = RTrim$(.strAppName) & vbNullChar
>        .strDlgTitle = RTrim$(.strDlgTitle) & vbNullChar
>        .strOpenTitle = RTrim$(.strOpenTitle) & vbNullChar
>        .strFile = RTrim$(.strFile) & vbNullChar
>        .strInitialDir = RTrim$(.strInitialDir) &
vbNullChar
>        .strFilter = RTrim$(.strFilter) & vbNullChar
>        SysCmd acSysCmdClearHelpTopic
>        lng = adh_accOfficeGetFileName(gfni, fOpen)
>        .strAppName = RTrim$(adhTrimNull(.strAppName))
>        .strDlgTitle = RTrim$(adhTrimNull(.strDlgTitle))
>        .strOpenTitle = RTrim$(adhTrimNull(.strOpenTitle))
>        .strFile = RTrim$(adhTrimNull(.strFile))
>        .strInitialDir = RTrim$(adhTrimNull
(.strInitialDir))
>        .strFilter = RTrim$(adhTrimNull(.strFilter))
>    End With
>    adhOfficeGetFileName = lng
>End Function

>Function adhTrimNull(strVal As String) As String
>    Dim intPos As Integer
>    intPos = InStr(strVal, vbNullChar)
>    If intPos > 0 Then
>        adhTrimNull = Left$(strVal, intPos - 1)
>    Else
>        adhTrimNull = strVal
>    End If
>End Function

>Hope this helps,

>James


>> Dear all,

>>    help on this matter will be greatly appreciated.

>> I want to open an Explorer like window (see attached
file)
>> to retrieve the path of a directory, not of a file.

>> I know that an API exists for Window2000, but I
>> haven't found anything for NT.

>>   ------------------------------------------------------
---------------
>>                    Name: Explorer.bmp
>>    Explorer.bmp    Type: Bitmap Image (image/bmp)
>>                Encoding: base64
>.



Sat, 07 Feb 2004 22:53:40 GMT  
 retrieve directory (not file) info with an API (WinnNT4.0)

Quote:

> (Think i first found this code on Dev Ashishs website)

> 'STANDARD FILE OPEN/SAVE DIALOG USED IN OFFICE

Sorry, I don't think that's a possibility. The code on my site is for the
Win32 dialog, and has been posted with the author's permissions. I wouldn't
be so careless about not giving credits to friends and colleagues. What you
posted is copyrighted code from Ken Getz's Developers Handbook, that too
without the credits. Please make sure that you ask for the author's
permission before doing something like this again (unless the code's been
posted to the public domain before).

 -- Dev



Sun, 08 Feb 2004 19:56:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. API call to retrieve Motherboard and Chip info?

2. Retrieve system info API's

3. How can I retrieve Info from NT users via APIs

4. Retrieving File Info

5. Retrieve File Owner Info (NT)

6. Writing & Retrieving Info from file

7. Retrieve info from an excel file

8. ExtendedProperty can't retrieve file summary info

9. Wave File Info: How to Retrieve

10. Getting Directory and File Info

11. retrieving file list from directory?

12. vb file and directory info

 

 
Powered by phpBB® Forum Software