Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.236.100.210] |
|
Сообщ.
#1
,
|
|
|
Вот так:
uses activeX; function GetFileNameFromBrowse(hOwner: LongInt; var sFile: string; sInitDir, sDefExt, sFilter, sTitle: string): Boolean; implementation function SHGetFileNameFromBrowse(hOwner: LongInt; sFile: LPWSTR; nMaxFile: LongInt; sInitDir: LPWSTR; sDefExt, sFilter, sTitle: LPWSTR): Boolean; stdcall; external 'Shell32.dll' index 63; //*************************** Код функций **************************************** function GetFileNameFromBrowse(hOwner: LongInt; var sFile: string; sInitDir, sDefExt, sFilter, sTitle: string): Boolean; var sFileW, sInitDirW, sDefExtW, sFilterW, sTitleW: PWideChar; sFileL, sInitDirL, sDefExtL, sFilterL, sTitleL: Integer; begin sFileW := CoTaskMemAlloc(255 * sizeof(WideChar)); StringToWideChar(SFile, SFileW, 255); SInitDirL := Length(sInitDir) + 1; sInitDirW := CoTaskMemAlloc(SInitDirL * sizeof(WideChar)); StringToWideChar(SInitDir, SInitDirW, sInitDirL); SDefExtL := Length(sDefExt) + 1; sDefExtW := CoTaskMemAlloc(SDefExtL * sizeof(WideChar)); StringToWideChar(SDefExt, SDefExtW, sDefExtL); SFilterL := Length(sFilter) + 1; sFilterW := CoTaskMemAlloc(SFilterL * sizeof(WideChar)); StringToWideChar(SFilter, SFilterW, sFilterL); STitleL := Length(sTitle) + 1; sTitleW := CoTaskMemAlloc(STitleL * sizeof(WideChar)); StringToWideChar(STitle, STitleW, sTitleL); Result := SHGetFileNameFromBrowse(hOwner, sFileW, Integer(sFileW), sInitDirW, sDefExtW, sFilterW, sTitleW); SFile := sFileW; CoTaskMemFree(sFileW); CoTaskMemFree(sInitDirW); CoTaskMemFree(sDefExtW); CoTaskMemFree(sFilterW); CoTaskMemFree(sTitleW); end; Вот пример использования: if GetFileNameFromBrowse(handle, b1, 'c:\Install', '*.txt', 'Текстовые файлы'#0'*.txt'#0'Все файлы'#0'*.*'#0#0 , 'Название') then begin end; Эта тема была разделена из темы "OpenDialog без "uses Dialog"" |
Сообщ.
#2
,
|
|
|
program opd; uses windows,commdlg; var ofn:TOpenFileName; s:string; f:array[0..MAX_PATH-1] of char; begin FillChar(f,sizeof(f),0); FillChar(ofn,sizeof(ofn),0); ofn.lStructSize := sizeof(OPENFILENAME); ofn.hwndOwner := 0; ofn.hInstance := hInstance; ofn.lpstrFilter:='Text Files (*.txt)'#0'*.txt'#0'Executables (*.EXE)'#0'*.exe'#0'All files (*.*)'#0'*.*'#0#0; ofn.lpstrTitle := 'Select My File!'; ofn.lpstrFile := f; ofn.nMaxFile := MAX_PATH; ofn.Flags := OFN_EXPLORER or OFN_CREATEPROMPT or OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_ENABLESIZING; if GetOpenFileName(ofn) then s:=ofn.lpstrFile; MessageBox(0,pchar(s),'My file',0); end. |