Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003

    Question Unanswered: winapi functions

    Are there any guides or help files on the internet detailing WinAPI functions? I have found them very useful and would like to see what else is 'out there'.

    Thank you,


  2. #2
    Join Date
    Sep 2002
    South Wales

    One resource

    Sub forum for APIs
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    Is there a specific call you're interested in? I don't really know any fully comprehensive WinAPI reference sources off the top of my head. If you find one please post it!!

    But anywho, if there's something specific you'd like to do, feel free to ask. Someone here has probably used the call in question.

  4. #4
    Join Date
    Mar 2003
    I am looking for the function that allows the user to designate a file through the 'open file dialog' typical in windows apps, and returns a pointer to the selected file. I have used it before but it was a while ago. Surely there are other useful functions in Win32.

  5. #5
    Join Date
    Oct 2003
    Provided Answers: 1
    Originally posted by pd9n
    I am looking for the function that allows the user to designate a file through the 'open file dialog' typical in windows apps, and returns a pointer to the selected file. I have used it before but it was a while ago. Surely there are other useful functions in Win32.
    Here is one

    Option Compare Database
    Option Explicit

    Public Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    strFilter As String
    strCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    strFile As String
    nMaxFile As Long
    strFileTitle As String
    nMaxFileTitle As Long
    strInitialDir As String
    strTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    strDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Public Const OFN_ALLOWMULTISELECT = &H200
    Public Const OFN_CREATEPROMPT = &H2000

    Public Const OFN_EXPLORER = &H80000 ' new look commdlg
    Public Const OFN_FILEMUSTEXIST = &H1000
    Public Const OFN_HIDEREADONLY = &H4
    Public Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
    Public Const OFN_NOCHANGEDIR = &H8
    Public Const OFN_NODEREFERENCELINKS = &H100000
    Public Const OFN_NOREADONLYRETURN = &H8000
    Public Const OFN_NOTESTFILECREATE = &H10000
    Public Const OFN_NOVALIDATE = &H100
    Public Const OFN_OVERWRITEPROMPT = &H2
    Public Const OFN_PATHMUSTEXIST = &H800
    Public Const OFN_READONLY = &H1
    Public Const OFN_SHAREAWARE = &H4000
    Public Const OFN_SHOWHELP = &H10

    Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
    Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    Public Declare Function GetOpenClipboardWindow Lib "user32" () As Long

    Function CommonFileOpenSave( _
    Optional ByRef flags As Variant, _
    Optional ByVal InitialDir As Variant, _
    Optional ByVal Filter As Variant, _
    Optional ByVal FilterIndex As Variant, _
    Optional ByVal DefaultExt As Variant, _
    Optional ByVal FileName As Variant, _
    Optional ByVal DialogTitle As Variant, _
    Optional ByVal hWnd As Variant, _
    Optional ByVal OpenFile As Variant) As Variant
    ' This is the entry point you'll use to call the common
    ' file open/save dialog. The parameters are listed
    ' below, and all are optional.
    ' In:
    ' Flags: one or more of the OFN_* constants, OR'd together.
    ' InitialDir: the directory in which to first look
    ' Filter: a set of file filters, set up by calling
    ' AddFilterItem. See examples.
    ' FilterIndex: 1-based integer indicating which filter
    ' set to use, by default (1 if unspecified)
    ' DefaultExt: Extension to use if the user doesn't enter one.
    ' Only useful on file saves.
    ' FileName: Default value for the file name text box.
    ' DialogTitle: Title for the dialog.
    ' hWnd: parent window handle
    ' OpenFile: Boolean(True=Open File/False=Save As)
    ' Out:
    ' Return Value: Either Null or the selected filename
    Dim strFileName As String
    Dim strFileTitle As String
    Dim fResult As Boolean
    ' Give the dialog a caption title.
    If IsMissing(InitialDir) Then InitialDir = CurDir
    If IsMissing(Filter) Then Filter = ""
    If IsMissing(FilterIndex) Then FilterIndex = 1
    If IsMissing(flags) Then flags = 0&
    If IsMissing(DefaultExt) Then DefaultExt = ""
    If IsMissing(FileName) Then FileName = ""
    If IsMissing(DialogTitle) Then DialogTitle = ""
    If IsMissing(hWnd) Then hWnd = Application.hWndAccessApp
    If IsMissing(OpenFile) Then OpenFile = True
    ' Allocate string space for the returned strings.
    strFileName = Left(FileName & String(256, 0), 256)
    strFileTitle = String(256, 0)
    ' Set up the data structure before you call the function
    With OFN
    .lStructSize = Len(OFN)
    .hwndOwner = hWnd
    .strFilter = Filter
    .nFilterIndex = FilterIndex
    .strFile = strFileName
    .nMaxFile = Len(strFileName)
    .strFileTitle = strFileTitle
    .nMaxFileTitle = Len(strFileTitle)
    .strTitle = DialogTitle
    .flags = flags
    .strDefExt = DefaultExt
    .strInitialDir = InitialDir
    ' Didn't think most people would want to deal with
    ' these options.
    .hInstance = 0
    .strCustomFilter = ""
    .nMaxCustFilter = 0
    .lpfnHook = 0
    'New for NT 4.0
    .strCustomFilter = String(255, 0)
    .nMaxCustFilter = 255
    End With
    ' This will pass the desired data structure to the
    ' Windows API, which will in turn it uses to display
    ' the Open/Save As Dialog.
    If OpenFile Then
    fResult = GetOpenFileName(OFN)
    fResult = GetSaveFileName(OFN)
    End If

    ' The function call filled in the strFileTitle member
    ' of the structure. You'll have to write special code
    ' to retrieve that if you're interested.
    If fResult Then
    ' You might care to check the Flags member of the
    ' structure to get information about the chosen file.
    ' In this example, if you bothered to pass in a
    ' value for Flags, we'll fill it in with the outgoing
    ' Flags value.
    If Not IsMissing(flags) Then flags = OFN.flags
    CommonFileOpenSave = TrimNull(OFN.strFile)
    CommonFileOpenSave = vbNullString
    End If
    End Function

    Private Function TrimNull(ByVal strItem As String) As String
    Dim intPos As Integer
    intPos = InStr(strItem, vbNullChar)
    If intPos > 0 Then
    TrimNull = Left(strItem, intPos - 1)
    TrimNull = strItem
    End If
    End Function

    Function AddFilterItem(strFilter As String, strDescription As String, Optional varItem As Variant) As String
    ' Tack a new chunk onto the file filter.
    ' That is, take the old value, stick onto it the description,
    ' (like "Databases"), a null character, the skeleton
    ' (like "*.mdb;*.mda") and a final null character.

    If IsMissing(varItem) Then varItem = "*.*"
    AddFilterItem = strFilter & strDescription & vbNullChar & varItem & vbNullChar
    End Function

    Function DBSuchen(DBName As String, Optional tabName As Variant)
    On Error Resume Next
    Dim strFilter As String
    Dim strInputFileName As String

    strFilter = AddFilterItem(strFilter, "Access (*.mdb)", "*.MDB;*.MDE;*.MDA")
    'strFilter = AddFilterItem(strFilter, "Text (*.txt)", "*.csv;*.dat")
    'strFilter = AddFilterItem(strFilter, "Access (*.xls)", "*.xls;*.xlc")
    strFilter = AddFilterItem(strFilter, "Alle Dateien (*.*)", "*.*")
    If IsMissing(tabName) Then
    strInputFileName = CommonFileOpenSave(InitialDir:=DBName, Filter:=strFilter, OpenFile:=True, DialogTitle:="Datenbank öffnen ...", _
    strInputFileName = CommonFileOpenSave(InitialDir:=DBName, Filter:=strFilter, OpenFile:=True, FileName:=tabName, DialogTitle:="Datenbank öffnen ...", _
    End If

    DBSuchen = strInputFileName
    End Function
    'Note that in order to call the Save As dialog box, you can use the same wrapper function by just setting the OpenFile option as False. For example,

    Function DBSpeichern(DBName As String)
    On Error Resume Next
    Dim strFilter As String
    Dim strSaveFileName As String

    strFilter = AddFilterItem(strFilter, "Access (*.mdb)", "*.MDB")
    strFilter = AddFilterItem(strFilter, "Alle Dateien (*.*)", "*.*")
    strSaveFileName = CommonFileOpenSave(InitialDir:=DBName, OpenFile:=False, Filter:=strFilter, DialogTitle:="Datenbank speichern ...", _
    If IsNull(strSaveFileName) Then
    DBSpeichern = ""
    DBSpeichern = strSaveFileName
    End If
    End Function

    in your form you can call it like that

    dim urFileName as string
    urFilename=(DBSuchen(CurDir & "\*.mdb"))

    And that was all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts