win api :GetDiskFreeSpace(...)

解决方案 »

  1.   

    选择目录的对话框要自己编写的!
    包含#include <shlobj.h> 
    然后:
       实际上vc本身就有标准的选目录的方法:              BROWSEINFO bi;            //BROWSEINFO结构体
                  TCHAR Buffer[512]="";
                  TCHAR FullPath[512]="";
                  bi.hwndOwner = m_hWnd;  //m_hWnd你的程序主窗口
                  bi.pidlRoot = NULL;
                  bi.pszDisplayName = Buffer; //返回选择的目录名的缓冲区
                  bi.lpszTitle = "Selection"; //弹出的窗口的文字提示
                  bi.ulFlags = BIF_RETURNONLYFSDIRS ; //只返回目录。其他标志看MSDN
                  bi.lpfn = NULL;                        //回调函数,有时很有用
                  bi.lParam = 0;
                  bi.iImage = 0;
                  ITEMIDLIST* pidl = ::SHBrowseForFolder (&bi); 
                //显示弹出窗口,ITEMIDLIST很重要
                  if(::SHGetPathFromIDList (pidl,FullPath))    
                //在ITEMIDLIST中得到目录名的整个路径
                  {
                    //成功
                  }
                  else
                {
                    //失败
                        } 我只是粘在这里
      

  2.   

    1.
    LONG CMyAppDlg::FreeDiskSpace(char sDrive)
    {
    DWORD FreeSpace = 0;
    DWORD lpSectorsPerCluster,lpBytesPerSector,lpNumberOfFreeClusters,lpTotalNumberOfClusters;
    if(GetDiskFreeSpace(sDrive,&lpSectorsPerCluster,&lpBytesPerSector,&lpNumberOfFreeClusters,&lpTotalNumberOfClusters))
    FreeSpace = lpSectorsPerCluster * lpNumberOfFreeClusters / 1024L * lpBytesPerSector / 1024L;
    return FreeSpace;
    }2.
    BOOL CMyAppDlg::dirPick(CString title, CString &refDef, CString &driver)
    {
    LPMALLOC pMalloc;
    if (SHGetMalloc(&pMalloc) == E_FAIL) return FALSE;    BROWSEINFO bi;
        char pszBuffer[MAX_PATH];
        LPITEMIDLIST pidRoot;
        LPITEMIDLIST pidl;
    HWND hwnd = GetSafeHwnd();    // Get my computer folder pid
    if (!SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &pidRoot)))
    {
    return FALSE; 
    }  // Get help on BROWSEINFO struct - it's got all the bit settings  
    bi.hwndOwner = hwnd;
        bi.pidlRoot = pidRoot;
        bi.pszDisplayName = pszBuffer;
        bi.lpszTitle = title;
        bi.ulFlags = BIF_DONTGOBELOWDOMAIN|BIF_RETURNFSANCESTORS | 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
                //        AfxMessageBox(pszBuffer);

    driver = pszBuffer[0];
    return TRUE;
             }
             // Free the PIDL allocated by SHBrowseForFolder
             pMalloc->Free(pidl);
        }
        // Release the shell's allocator 
        pMalloc->Release();
    return FALSE;
    }
      

  3.   

    哪位能将各种文件系统的 SectorPerCluster、BytesPerSector 列出来。松紧带兄的方法我用了,还是有两个问题:
    1.我的硬盘分区是这样的C:NTFS,D:FAT32,E:FAT32,系统:W2k Server。但是E:的剩余空间计算老是出错,SectorPerCluster、BytesPerSector 都是极大的数858993460,实在搞不懂,另一台机器也是这样。
    2.SHBrowseForFolder中加入Edit框之后,如何在Edit框中显示选中目录的全路径。
      

  4.   

    上面第二个问题,如何在Edit框中显示选中目录的全路径。求教!