vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevDataGrid - Gönnen Sie Ihrem SQL-Kommando diesen krönenden Abschluß!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB & Windows API
speichern dialog 
Autor: sui
Datum: 24.11.04 08:41

Hallo,

ich benutze die API GetSaveFileName und GetOpenFilename.

Gibt es hier die Möglichkeit außer dem Pfad auch die Datei anzugeben.
Des heißt, wenn der Dialog aufgeht, dass schon ein vorgegebener Dateiname
drin steht?

Vielen Dank im voraus!

Sui

Nur ein toter Bug ist ein guter Bug!

Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: speichern dialog 
Autor: wincnc
Datum: 24.11.04 09:53

Beispiel:
Option Explicit
 
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 Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
 
Dim OFName As OPENFILENAME
 
Private Sub Command1_Click()
    Dim sFile As String
    sFile = ShowOpen
    If sFile <> "" Then
        MsgBox "You chose this file: " + sFile
    Else
        MsgBox "You pressed cancel"
    End If
End Sub
 
Private Sub Command2_Click()
    Dim sFile As String
    sFile = ShowSave
    If sFile <> "" Then
        MsgBox "You chose this file: " + sFile
    Else
        MsgBox "You pressed cancel"
    End If
End Sub
 
Private Sub Form_Load()
    Command1.Caption = "ShowOpen"
    Command2.Caption = "ShowSave"
End Sub
 
Private Function ShowOpen() As String
    ' Set the structure size
    OFName.lStructSize = Len(OFName)
    ' Set the owner window
    OFName.hwndOwner = Me.hWnd
    ' Set the application's instance
    OFName.hInstance = App.hInstance
    ' Set the filet
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + _
      "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    ' Create a buffer
    OFName.lpstrFile = Space$(254)
    ' Set the maximum number of chars
    OFName.nMaxFile = 255
    ' Create a buffer
    OFName.lpstrFileTitle = Space$(254)
    ' Set the maximum number of chars
    OFName.nMaxFileTitle = 255
    ' Set the initial directory
    OFName.lpstrInitialDir = "D:\"
    ' Set the dialog title
    OFName.lpstrTitle = "Open File"
    ' no extra flags
    OFName.flags = 0
    ' Show the 'Open File'-dialog
    If GetOpenFileName(OFName) Then
        ShowOpen = Trim$(OFName.lpstrFile)
    Else
        ShowOpen = ""
    End If
End Function
 
Private Function ShowSave() As String
    ' Set the structure size
    OFName.lStructSize = Len(OFName)
    ' Set the owner window
    OFName.hwndOwner = Me.hWnd
    ' Set the application's instance
    OFName.hInstance = App.hInstance
    ' Set the filet
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + _
      "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    ' Create a buffer
    OFName.lpstrFile = Space$(254)
    ' Set the maximum number of chars
    OFName.nMaxFile = 255
    ' Create a buffer
    OFName.lpstrFileTitle = Space$(254)
    ' Set the maximum number of chars
    OFName.nMaxFileTitle = 255
    ' Set the initial directory
    OFName.lpstrInitialDir = "C:\"
    ' Set the dialog title
    OFName.lpstrTitle = "Save File"
    ' no extra flags
    OFName.flags = 0
 
    ' Filename
    OFName.lpstrFile = "Test.txt"
 
    ' Show the 'Save File'-dialog
    If GetSaveFileName(OFName) Then
        ShowSave = Trim$(OFName.lpstrFile)
    Else
        ShowSave = ""
    End If
End Function
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: speichern dialog 
Autor: sui
Datum: 24.11.04 10:03

danke!
War genau das was ich gebraucht hab!

Nur ein toter Bug ist ein guter Bug!

Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel