Chinaunix首页 | 论坛 | 博客
  • 博客访问: 561713
  • 博文数量: 97
  • 博客积分: 5090
  • 博客等级: 大校
  • 技术积分: 969
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-01 14:56
文章分类

全部博文(97)

文章存档

2011年(1)

2009年(1)

2008年(14)

2007年(37)

2006年(44)

我的朋友

分类: WINDOWS

2008-04-14 11:38:46

void CDlgClientSingalCPJG::OnOK() 

//指定文件存放位置
 CWnd* pMainCWnd = NULL; 
 pMainCWnd = GetActiveWindow(); 
 CString csFolder = _T( "" );
 HWND pMainHWnd = pMainCWnd->GetSafeHwnd(); 
 SelectFolder( pMainHWnd, csFolder );

.........

}

int CDlgClientSingalCPJG::SelectFolder(HWND hWnd,CString& strFolder)
{
    strFolder.Empty(); 
    LPMALLOC lpMalloc; 
    if (::SHGetMalloc(&lpMalloc) != NOERROR)
         return 0; 
    char szDisplayName[_MAX_PATH];
    char szBuffer[_MAX_PATH]; 
    BROWSEINFO browseInfo; 
    browseInfo.hwndOwner = hWnd; 
    browseInfo.pidlRoot = NULL; // set root at Desktop
    browseInfo.pszDisplayName = szDisplayName; 
    browseInfo.lpszTitle = "选择一个文件夹";
    browseInfo.ulFlags = BIF_USENEWUI;
    browseInfo.lpfn = NULL; 
    browseInfo.lParam = 0; 
    LPITEMIDLIST lpItemIDList;
    if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo)) != NULL)
    {
        // Get the path of the selected folder from the item ID list.
        if (::SHGetPathFromIDList(lpItemIDList, szBuffer)) 
        {  // At this point, szBuffer contains the path the user chose. 
           if (szBuffer[0] == '\0') 
                 return 0;
             // We have a path in szBuffer! Return it. 
           strFolder = szBuffer; 
           return 1; 
        } 
       else
              return 1; // strResult is empty 
        lpMalloc->Free(lpItemIDList);
        lpMalloc->Release();
    } 
    return 1;
}

 

阅读(1865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~