|
//代码名称: 浏览对话框
//类别: 控件 公用对话框
//关健字: 对话框 浏览
//作者: EasySL
//编译器: VC
//操作系统: windows
#include <windows.h>
#include <tchar.h>
#include <shlobj.h>
char *BrowseBox( HWND hWnd, char *s, int length )
{
if( length < MAX_PATH )
return NULL;
//char processdir[MAX_PATH];
HWND hwndOwner = hWnd;
LPCSTR lpszTitle = "BrowseBox";
//CString strSelIniDir;
//CString strDirPathSelected;
char strSelIniDir[MAX_PATH] = "";
char strDirPathSelected[MAX_PATH] = "";
/* Work's only if we're 95 capable or up*/
BOOL bRe = FALSE;
LPMALLOC pMalloc;
BROWSEINFO bi;
TCHAR pszBuffer[MAX_PATH];
LPITEMIDLIST pidl = NULL;
LPITEMIDLIST pidlIni = NULL;
LPSHELLFOLDER ppshf = NULL;
OLECHAR szOleChar[MAX_PATH];
ULONG ulEaten, ulAttribs;
//if(strSelIniDir.IsEmpty() == FALSE)
{
/* Get's the Shell's default allocator */
if (SHGetMalloc(&pMalloc) != NOERROR)
{
goto crash;
}
// Get's the Shell's desktop folder Interface
if(! SUCCEEDED(SHGetDesktopFolder(&ppshf)) )
{
goto crash;
}
// Conver to UNICODE string
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
strSelIniDir,
-1,
szOleChar,
sizeof(szOleChar));
//
if(! SUCCEEDED(ppshf-> arseDisplayName(hwndOwner,NULL,szOleChar,
&ulEaten,&pidlIni,&ulAttribs)))
goto crash;
}
// Get help on BROWSEINFO struct - it's got all the bit settings
bi.hwndOwner = hwndOwner;
bi.pidlRoot = pidlIni;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = lpszTitle;
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS
| BIF_RETURNONLYFSDIRS ;
bi.lpfn = NULL; bi.lParam = 0;
// This next call issues the dialog box
if ((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if (SHGetPathFromIDList(pidl, pszBuffer))
{
//At this point pszBuffer contains the selected path
//strDirPathSelected = pszBuffer;
strcpy( strDirPathSelected, pszBuffer );
strcpy(s,pszBuffer);
strcat(s,"\\");
}
bRe = TRUE;
}
return s;
crash:
return NULL;
} |
|