Сайт Алексея Муртазина (Star Cat) E-mail: starcat-rus@yandex.ru
Мои программы Новости сайта Мои идеи Мои стихи Форум Об авторе Мой ЖЖ
VB коды Статьи о VB6 API функции Самоучитель по VB.NET
Собрания сочинений Обмен ссылками Все работы с фото и видео
О моём деде Муртазине ГР Картинная галерея «Дыхание души»
Звёздный Кот

69 Показывает программу,
с помощью которой запускается файл
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

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 Sub cFindExecutable()
Dim OpenFile As OPENFILENAME
Dim Success As Long, FileTitleLength%, Filter$
Dim Result$, x&, DirLen#, FileLen#, Dir$
On Error GoTo OpenError
'Открыть окно для выбора файла
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = hWnd
OpenFile.hInstance = App.hInstance
Filter = "Все файлы (*.*)" & Chr(0) & "*.*" & Chr(0)
OpenFile.lpstrFilter = Filter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrTitle = "Функции API"
OpenFile.flags = 0
Success = GetOpenFileName(OpenFile)

If Success = 0 Then
Exit Sub
Else:
'The next 4 lines remove null length strings.
'Trim does not work. Anyone got a better idea?
Caption = Trim(OpenFile.lpstrFile)
OpenFile.lpstrFile = Caption
Caption = Trim(OpenFile.lpstrFileTitle)
OpenFile.lpstrFileTitle = Caption

'These lines find path without filetitle
FileLen = Len(OpenFile.lpstrFile)
DirLen = Len(OpenFile.lpstrFileTitle)
Dir = Left(OpenFile.lpstrFile, FileLen - DirLen - 1)
Result = Space(128)

x = FindExecutable(OpenFile.lpstrFileTitle, Dir, Result)
If x < 32 Then GoTo OpenError
MsgBox "The application used to open " & OpenFile.lpstrFileTitle & " is " & vbCrLf & vbCrLf _
Result, vbOKOnly + vbInformation
End If
Exit Sub OpenError:
MsgBox "Не могу найти приложение,сопоставленное с файлом.", vbOKOnly + vbEx>End Sub

Инфо
Сайт создан: 20 июня 2015 г.
Рейтинг@Mail.ru
Главная страница