Привет эксперты: Скажите пожалуйста: 1) Как в Visual Basic получить окно Open Dialog. 2) С помощью каких функий производиться запись и чтение keys в Реестр Windows? C благодарностью, Оскар
Здравствуйте, oscar! Вот код, написал бы адрес было бы больше
Private Type OPENFILENAME lngStructSize As Long ' Size of structure hwndOwner As Long ' Owner window handle hInstance As Long ' Template instance handle strFilter As String ' Filter string strCustomFilter As String ' Selected filter string intMaxCustFilter As Long ' Len(strCustomFilter) intFilterIndex As Long ' Index of filter string strFile As String ' Selected filename & path intMaxFile As Long ' Len(strFile) strFileTitle As String ' Selected filename intMaxFileTitle As Long ' Len(strFileTitle) strInitialDir As String ' Directory name strTitle As String ' Dialog title
lngFlags As Long ' Dialog flags intFileOffset As Integer ' Offset of filename intFileExtension As Integer ' Offset of file extension strDefExt As String ' Default file extension lngCustData As Long ' Custom data for hook lngfnHook As Long ' LP to hook function strTemplateName As String ' Dialog template name End Type ' Open/Save dialog flags Global Const OFN_READONLY = &H1 Global Const OFN_OVERWRITEPROMPT = &H2 Global Const OFN_HIDEREADONLY = &H4 Global Const OFN_NOCHANGEDIR = &H8 Global Const OFN_SHOWHELP = &H10 Global Const OFN_NOVALIDATE = &H100 Global Const OFN_ALLOWMULTISELECT = &H200 Global Const OFN_EXTENSIONDIFFERENT = &H400 Global Const OFN_PATHMUSTEXIST = &H800 Global Const OFN_FILEMUSTEXIST = &H1000 Global Const OFN_CREATEPROMPT
= &H2000 Global Const OFN_SHAREAWARE = &H4000 Global Const OFN_NOREADONLYRETURN = &H8000 Global Const OFN_NOTESTFILECREATE = &H10000 Global Const OFN_NONETWORKBUTTON = &H20000 Global Const OFN_NOLONGNAMES = &H40000 ' Flags for hook functions and dialog templates 'Global Const OFN_ENABLEHOOK = &H20 'Global Const OFN_ENABLETEMPLATE = &H40 'Global Const OFN_ENABLETEMPLATEHANDLE = &H80 ' Windows 95 flags Global Const OFN_EXPLORER = &H80000 Global Const OFN_NODEREFERENCELINKS = &H100000 Global Const OFN_LONGNAMES = &H200000 ' Custom flag combinations Global Const OFN_OPENEXISTING = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Global Const OFN_SAVENEW = OFN_PATHMUSTEXIST Or OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY Global Const OFN_SAVENEWPATH = OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY Declare Function GetOpenFileName Lib "comdlg32.dll"
_ Alias "GetOpenFileNameA" (ofn As OPENFILENAME) As Boolean Declare Function GetSaveFileName Lib "comdlg32.dll" _ Alias "GetSaveFileNameA" (ofn As OPENFILENAME) As Boolean Private Declare Function GetActiveWindow Lib "user32" () As Long Function FileDialog( _ Optional strInitDir As String, _ Optional strFilter As String = _ "All files (*.*)" & vbNullChar & "*.*" & _ vbNullChar & vbNullChar, _ Optional intFilterIndex As Integer = 1, _ Optional strDefaultExt As String, _ Optional strFilename As String, _ Optional strDialogTitle As String = "Открыть", _ Optional hwnd As Long = -1, _ Optional fOpenFile As Boolean = True, _ Optional ByRef lngFlags As Long = _ OFN_OPENEXISTING) As String ' Wrapper function for the GetOpenFileName API function. '
Displays the common open/save as dialog and returns ' the file(s) selected by the user. Dim ofn As OPENFILENAME Dim strFileTitle As String Dim fResult As Boolean ' Fill in some of the missing arrguments If strInitDir = "" Then strInitDir = CurDir End If If hwnd = -1 Then hwnd = GetActiveWindow() End If ' Set up the return buffers strFilename = strFilename & String(255 - Len(strFilename), 0) strFileTitle = String(255, 0) ' Fill in the OPENFILENAME structure members With ofn .lngStructSize = Len(ofn) .hwndOwner = hwnd .strFilter = strFilter .intFilterIndex = intFilterIndex .strFile = strFilename .intMaxFile = Len(strFilename) .strFileTitle = strFileTitle .intMaxFileTitle = Len(strFileTitle)
.strTitle = strDialogTitle .lngFlags = lngFlags .strDefExt = strDefaultExt .strInitialDir = strInitDir .hInstance = 0 .strCustomFilter = String(255, 0) .intMaxCustFilter = 255 .lngfnHook = 0 End With ' Call the right function If fOpenFile Then fResult = GetOpenFileName(ofn) Else fResult = GetSaveFileName(ofn) End If ' If successful, return the filename, ' otherwise return Null If fResult Then ' Return any flags to the calling procedure lngFlags = ofn.lngFlags
' Return the result If (ofn.lngFlags And OFN_ALLOWMULTISELECT) = 0 Then FileDialog = TrimNull(ofn.strFile) Else FileDialog = ofn.strFile End If Else
FileDialog = "" End If End Function Function TrimNull(ByVal Source As String) As String ' Находит первый встречающийся нуль-символ ' и возвращает строку до него
Dim lngPos As Long
lngPos = InStr(Source, vbNullChar) Select Case lngPos Case 0 TrimNull = Source Case 1 TrimNull = "" Case Is > 1 TrimNull = Left$(Source, lngPos - 1) End Select End Function
Можно конечно с помощью элемента Common Dialog, но я думаю его стоит использовать, если в программе кроме работы с окнами открытия, закрытия файлов, нужно работать с цветовой палитрой и принтерами. Ответ отправлен: 25.05.2004, 20:45 Отправитель: Puma
Форма отправки вопроса
Внимание!
Мы рекомендуем открывать рассылку в программе Internet Explorer 5.0+
или отправлять вопросы с сайта по адресу:
http://rusfaq.ru/cgi-bin/Message.cgi.