H
HaiChengruo
Unregistered / Unconfirmed
GUEST, unregistred user!
函数GetDirectry用于取得桌面路径, 可有时行有时不行。请各位大虾帮忙看看代码哪里有误。
Function GetDirectry(handle:HWND;PromtStr:String):String;
var
m_strInitDir, szDirectorychar;
m_iImageIndex:integer;
hr:HRESULT;
chOlePathwidechar;
pchEatenWORD;
dwAttributesWORD;
pDesktopFolder:IShellFolder;
browseInfo:_BROWSEINFO;
// lpItemList:****EMID;
lpItemListITEMIDLIST;
lpM:IMalloc;
begin
// chOlePath:=nil;
m_strInitDir:=StrAlloc(255*sizeof(char));
szDirectory:=StrAlloc(255*sizeof(char));
new(chOlePath);
// new(lpItemList);
ZeroMemory(Pointer(@browseInfo),sizeof(browseInfo));
hr:= SHGetMalloc(lpM);
if (FAILED(hr) ) then exit;
hr:=SHGetDesktopFolder(pDesktopFolder);
if (FAILED(hr) ) then exit;
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir, -1,chOlePath, MAX_PATH);
hr:= pDesktopFolder.ParseDisplayName(handle,
nil,
chOlePath,
pchEaten,
lpItemList,
dwAttributes);
if (FAILED(hr)) then
begin
lpM.Free(lpItemList);
lpM._Release;
exit;
end;
browseInfo.pidlRoot:=nil;//lpItemList;
browseInfo.hwndOwner:=0;
browseInfo.pszDisplayName:=szDirectory;
browseInfo.lpszTitle:=pchar(PromtStr);
browseInfo.ulFlags:= BIF_RETURNFSANCESTORS and BIF_RETURNONLYFSDIRS;
browseInfo.lParam:=0;
lpItemList:=SHBrowseForFolder(browseInfo);
if (lpItemList= nil) then
begin
exit;;
end;
//szDirectory.ReleaseBuffer();
m_iImageIndex:= browseInfo.iImage;
if (SHGetPathFromIDList(lpItemList,szDirectory)) then
begin
// Get the selected directory name
// szDirectory.ReleaseBuffer();
end;
lpM.Free(lpItemList);
lpM:=nil;
Result:=String(szDirectory);
StrDispose(m_strInitDir);
StrDispose(szDirectory);
Dispose(chOlePath);
end;
Function GetDirectry(handle:HWND;PromtStr:String):String;
var
m_strInitDir, szDirectorychar;
m_iImageIndex:integer;
hr:HRESULT;
chOlePathwidechar;
pchEatenWORD;
dwAttributesWORD;
pDesktopFolder:IShellFolder;
browseInfo:_BROWSEINFO;
// lpItemList:****EMID;
lpItemListITEMIDLIST;
lpM:IMalloc;
begin
// chOlePath:=nil;
m_strInitDir:=StrAlloc(255*sizeof(char));
szDirectory:=StrAlloc(255*sizeof(char));
new(chOlePath);
// new(lpItemList);
ZeroMemory(Pointer(@browseInfo),sizeof(browseInfo));
hr:= SHGetMalloc(lpM);
if (FAILED(hr) ) then exit;
hr:=SHGetDesktopFolder(pDesktopFolder);
if (FAILED(hr) ) then exit;
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir, -1,chOlePath, MAX_PATH);
hr:= pDesktopFolder.ParseDisplayName(handle,
nil,
chOlePath,
pchEaten,
lpItemList,
dwAttributes);
if (FAILED(hr)) then
begin
lpM.Free(lpItemList);
lpM._Release;
exit;
end;
browseInfo.pidlRoot:=nil;//lpItemList;
browseInfo.hwndOwner:=0;
browseInfo.pszDisplayName:=szDirectory;
browseInfo.lpszTitle:=pchar(PromtStr);
browseInfo.ulFlags:= BIF_RETURNFSANCESTORS and BIF_RETURNONLYFSDIRS;
browseInfo.lParam:=0;
lpItemList:=SHBrowseForFolder(browseInfo);
if (lpItemList= nil) then
begin
exit;;
end;
//szDirectory.ReleaseBuffer();
m_iImageIndex:= browseInfo.iImage;
if (SHGetPathFromIDList(lpItemList,szDirectory)) then
begin
// Get the selected directory name
// szDirectory.ReleaseBuffer();
end;
lpM.Free(lpItemList);
lpM:=nil;
Result:=String(szDirectory);
StrDispose(m_strInitDir);
StrDispose(szDirectory);
Dispose(chOlePath);
end;