VC中如何使用"浏览对话框"

本文介绍了一个使用C++实现的文件选择对话框功能,该功能允许用户浏览并选择文件夹作为保存位置。代码详细展示了如何利用Windows Shell API创建自定义的文件选择对话框,并设置了相应的标题和回调函数。
 CString CaaDlg::OnBrowse(void) //打开浏览对话框
{
 // TODO: Add your control notification handler code here
 LPMALLOC pMalloc;
 /* Gets the Shell's default allocator */
 if (::SHGetMalloc(&pMalloc) == NOERROR)   //获得pMalloc
 {       
  BROWSEINFO bi;
  char pszBuffer[MAX_PATH];       
  LPITEMIDLIST pidl;
  // Get help on BROWSEINFO struct - it's got all the bit settings.
  //设定Browse的属性
  bi.hwndOwner = GetSafeHwnd();       
  bi.pidlRoot = NULL;
  bi.pszDisplayName = pszBuffer;
  bi.lpszTitle = _T( "请选择保存的位置" );  //
  bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
  bi.lpfn = NULL;       
  bi.lParam = 0;
  // This next call issues the dialog box.
  if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)  //显示浏览窗口  SHBrowseForFolder   
  {
   if (::SHGetPathFromIDList(pidl, pszBuffer)) //把路径存进pszBuffer中
   {
    // At this point pszBuffer contains the selected path */.
    // Free the PIDL allocated by SHBrowseForFolder.
    pMalloc->Free(pidl);     
    // Release the shell's allocator.  
    pMalloc->Release();
    /************这个有什么作用吗?******************
    RECT re;
    re.bottom=100;
    re.left=50;
    re.right=300;
    re.top=50;
    InvalidateRect(&re,TRUE);//清除路径中的上次的文字
    *******************************************/
    return bi.pszDisplayName;
    //SetDlgItemText(IDC_PATH, bi.pszDisplayName);//填写路径名字
   }
   else
    return "";
  }
  else
   return "";
 }
 else
  return "";
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值