唉,水平低,我是看了Delphi的win32sdk帮助文档的,但还是错,怎么办,谁帮我想想吧。
问题变成了SHGetPathFromIDList怎么用,怎么也出错,不用SHGetPathFromIDList是不会
出错,但得到的路径又不对。
多谢dcsdcs等,SelectDirectory我会用,但这是win16的风格,我要的是win32风格的。
use shlobj;
procedure TForm1.Button1Click(Sender: TObject);
var
; ; udtBI:browseinfo;
; ; lpIDList
ointer;
; ; dn
char;
; ; ddd
char;
begin
; ; udtBI.hWndOwner := Handle ;
; ; udtBI.iImage :=0;
; ; udtBI.lParam :=0;
; ; udtBI.lpfn :=nil;
; ; udtBI.lpszTitle := 'ssss';
; ; udtBI.pidlRoot:=nil;
; ; udtBI.pszDisplayName:=dn;
; ; udtBI.ulFlags :=BIF_RETURNONLYFSDIRS ;
; ; lpIDList := SHBrowseForFolder(udtBI);
{到这里都ok}
; ; if lpIDList=nil then
; ; ; ; ShowMessage('取消')
; ; else begin
; ; ; ; SHGetPathFromIDList(lpIDList,ddd);
{VB中是用这个函数得到路径的,但Delphi中就出错,}
; ; ; ; Application.MessageBox(dn,'消息',MB_OK);
; ; end;
end;
以下是VB的程序,谁能翻译一下吗?
Private Type BrowseInfo
; ; hWndOwner As Long
; ; pIDLRoot As Long
; ; pszDisplayName As Long
; ; lpszTitle As Long
; ; ulFlags As Long
; ; lpfnCallback As Long
; ; lParam As Long
; ; iImage As Long
End Type
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
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
Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String
'打开选择目录对话框,返回路径
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
With udtBI
; ; .hWndOwner = hWndOwner
; ; .lpszTitle = lstrcat(sPrompt, "")
; ; .ulFlags = BIF_RETURNONLYFSDIRS
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
; ; sPath = String$(MAX_PATH, 0)
; ; lResult = SHGetPathFromIDList(lpIDList, sPath)
; ; Call CoTaskMemFree(lpIDList)
; ; iNull = InStr(sPath, vbNullChar)
; ; If iNull Then
; ; ; ; sPath = Left$(sPath, iNull - 1)
; ; End If
End If
BrowseForFolder = sPath
End Function
to hotplayboy:
不好意思,借你的问题发挥一下。