Страница: 1 |
Как апи-функциями вызвать диалоги: открыть файл, сохранить файл, обзор папок? если можно, покажите пример и как обработать возвращаемую строку! *потому что осх, которым я всё это делал, требует регистрацию на другом компе. спасибо)
Здравствуйте! Процедуры в форме выглядят так: Private Sub mnuFileOpen_Click() Private Sub mnuFileSave_Click() Private Sub mnuFileSaveAs_Click() API-функции у меня в отдельном модуле name=modComdlg32, а вот и его текст (тут еще много других возможностей, которые Вам могут не понадобится - найдите лишнее и удалите): Private Type BROWSEINFO Private Type OPENFILENAME Private Type CHOOSECOLOR Const LF_FACESIZE = 32 Private Type ChooseFont Const CF_INITTOLOGFONTSTRUCT = &H40& Private Type PrintDlg Const CCHDEVICENAME = 32 Private Type DEVNAMES Const DM_DUPLEX = &H1000& Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long хе ... круто), только я не думал, что так много писать надо будет ... спасиб, выручили ... Да уж, намусорил неслабо. Так вроде покороче будет Private Type BrowseInfo hwndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As String ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type Dim strPath As String Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String Const BIF_RETURNONLYFSDIRS = 1, MAX_PATH = 260 Dim intNull As Integer, lngIdList As Long Dim udtBI As BrowseInfo With udtBI .hwndOwner = hwndOwner .lpszTitle = sPrompt .ulFlags = BIF_RETURNONLYFSDIRS End With lngIdList = SHBrowseForFolder(udtBI) If lngIdList Then strPath = String$(MAX_PATH, 0) SHGetPathFromIDList lngIdList, strPath CoTaskMemFree lngIdList intNull = InStr(strPath, vbNullChar) If intNull Then strPath = Left$(strPath, intNull - 1) End If BrowseForFolder = strPath End Function Private Sub Command1_Click() BrowseForFolder Me.hWnd, "Hi, Select ... " Print strPath End Sub А вот ещё один: Private Type OPENFILENAME А вот ещё один: Private Type OPENFILENAME вот уже намного лучше) а как сделать чтобы при открытие обзора папок, была изначально открыта указанная папка? например, нужно чтобы всегда открывался такой путь "D:\Songs\0000-Temp\10-GB\Instrumental Music\Ennio Morricone" ... и немного неудобно каждый раз при открытии обзора 5-6 раз счёлкать, чтобы добраться до нужной папки ... если можно поясните кто нибудь, на этом примере: Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String Private Sub Command1_Click() извините за замусоривание), просто боюсь что не пойму, что к чему будет в другом случае .. Страница: 1 |
Вопрос: Open\Save\Browse Folder
Добавлено: 11.04.03 05:31
Автор вопроса: Champion | Web-сайт:
Ответы
Всего ответов: 8
Номер ответа: 1
Автор ответа:
mc-black
ICQ: 308-534-060
Вопросов: 20
Ответов: 1860
Web-сайт:
Профиль | | #1
Добавлено: 11.04.03 16:57
If Not bIsSaved Then
Dim nRes As VbMsgBoxResult
nRes = MsgBox("Файл был изменен." & vbCrLf & "Сохранить сохранить изменения?", vbYesNoCancel)
If nRes = vbYes Then
mnuFileSave_Click
ElseIf nRes = vbCancel Then
Exit Sub
End If
End If
modComdlg32.ShowOpen
If FileName <> "" Then FileOpen FileName
End Sub
If FileName = "" Then
mnuFileSaveAs_Click
Exit Sub
ElseIf Not bIsSaved Then
FileSave FileName
End If
End Sub
modComdlg32.ShowSave
If FileName <> "" Then FileSave FileName
End Sub
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
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
lStructSize As Long
hwndOwner As Long
hInstance As Long
RGBResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
lStructSize As Long
hwndOwner As Long
hdc As Long
lpLogFont As Long
iPointSize As Long
flags As Long
rgbColors As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
hInstance As Long
lpszStyle As String
nFontType As Integer
MISSING_ALIGNMENT As Integer
nSizeMin As Long
nSizeMax As Long
End Type
Const SCREEN_FONTTYPE = &H2000
Const BOLD_FONTTYPE = &H100
Const FW_BOLD = 700
Const LOGPIXELSY = 90
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hdc As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type
Const CCHFORMNAME = 32
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
extra As String * 100
End Type
Const DM_ORIENTATION = &H1&
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function ChooseColorAPI Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
Private Declare Function ChooseFont Lib "comdlg32.dll" Alias "ChooseFontA" (pChoosefont As ChooseFont) As Long
Private Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PrintDlg) As Long
Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hOwner As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
Private Declare Function SHShutDownDialog Lib "Shell32" Alias "#60" (ByVal YourGuess As Long) As Long
Private Declare Function SHRestartSystem Lib "Shell32" Alias "#59" (ByVal hOwner As Long, ByVal sPrompt As String, ByVal uFlags As Long) As Long
Private Declare Function SHRunDialog Lib "Shell32" Alias "#61" (ByVal hOwner As Long, ByVal hIcon As Long, ByVal sDir As Long, ByVal szTitle As String, ByVal szPrompt As String, ByVal uFlags As Long) As Long
Private Declare Function SHFormatDrive Lib "Shell32" (ByVal hwndOwner As Long, ByVal iDrive As Long, ByVal iCapacity As Long, ByVal iFormatType As Long) As Long
Private Declare Function SHBrowseForFolder Lib "Shell32" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHChangeIconDialog Lib "Shell32" Alias "#62" (ByVal hOwner As Long, ByVal szFilename As String, ByVal Reserved As Long, lpIconIndex As Long) As Long
Private Declare Function SHObjectProperties Lib "Shell32" Alias "#178" (ByVal hOwner As Long, ByVal uFlags As Long, ByVal sName As String, ByVal sParam As Strin
Номер ответа: 2
Автор ответа:
Champion
ICQ: 461506481
Вопросов: 38
Ответов: 88
Web-сайт:
Профиль | | #2
Добавлено: 11.04.03 19:16
Номер ответа: 3
Автор ответа:
Gravity
Вопросов: 6
Ответов: 120
Профиль | | #3
Добавлено: 11.04.03 22:31
да ......... Champion до фига тебе придётся удалять не нужного
Номер ответа: 4
Автор ответа:
CyRax
Разработчик Offline Client
ICQ: 204447456
Вопросов: 180
Ответов: 4229
Web-сайт:
Профиль | | #4
Добавлено: 11.04.03 23:08
Номер ответа: 5
Автор ответа:
Padre
ICQ: 346632205
Вопросов: 25
Ответов: 215
Web-сайт:
Профиль | | #5
Добавлено: 12.04.03 02:13
Номер ответа: 6
Автор ответа:
DeXTeR
Вопросов: 32
Ответов: 30
Профиль | | #6
Добавлено: 12.04.03 14:01
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 Sub Command1_Click()
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "Rich Text Files (*.rtf)" + Chr$(0) + "*.rtf" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = "Our File Open Title"
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If Then
MsgBox "File to Open: " + Trim$(ofn.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub
Номер ответа: 7
Автор ответа:
DeXTeR
Вопросов: 32
Ответов: 30
Профиль | | #7
Добавлено: 12.04.03 14:01
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 Sub Command1_Click()
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "Rich Text Files (*.rtf)" + Chr$(0) + "*.rtf" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = "Our File Open Title"
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If Then
MsgBox "File to Open: " + Trim$(ofn.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub
Номер ответа: 8
Автор ответа:
Champion
ICQ: 461506481
Вопросов: 38
Ответов: 88
Web-сайт:
Профиль | | #8
Добавлено: 15.04.03 06:04
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Dim strBrowse As String
Const BIF_RETURNONLYFSDIRS = 1, MAX_PATH = 260
Dim intNull As Integer, lngIdList As Long, udtBI As BrowseInfo
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = sPrompt
.ulFlags = BIF_RETURNONLYFSDIRS
End With
lngIdList = SHBrowseForFolder(udtBI):
strBrowse = String$(MAX_PATH, 0):
SHGetPathFromIDList lngIdList, strBrowse:
CoTaskMemFree lngIdList:
intNull = InStr(strBrowse, vbNullChar)
If intNull > 1 Then strBrowse = Left$(strBrowse, intNull - 1) Else strBrowse = "cansel"
If strBrowse <> "cansel" Then If Right(strBrowse, 1) <> "\" Then strBrowse = strBrowse & "\"
End Function
BrowseForFolder Me.hWnd, "Выберите папку"
End Sub