两个问题请教 win api :GetDiskFreeSpace(...) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 选择目录的对话框要自己编写的!包含#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 { //失败 } 我只是粘在这里 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;} 哪位能将各种文件系统的 SectorPerCluster、BytesPerSector 列出来。松紧带兄的方法我用了,还是有两个问题:1.我的硬盘分区是这样的C:NTFS,D:FAT32,E:FAT32,系统:W2k Server。但是E:的剩余空间计算老是出错,SectorPerCluster、BytesPerSector 都是极大的数858993460,实在搞不懂,另一台机器也是这样。2.SHBrowseForFolder中加入Edit框之后,如何在Edit框中显示选中目录的全路径。 上面第二个问题,如何在Edit框中显示选中目录的全路径。求教! 我要这个计算器实现循环运算 该怎么改啊 谢谢了 socket编程中的recv函数 删除记录后怎么立即更新? 在static控件上显示位图问题。(缩放和显示) 我写的DLL为什么不能注册?ASP下如何调用DLL 发消息的一个小问题! 使用ADO连接数据库的问题 如何把DWORD传换为CString ?? 怎样把一个控件包到另外一个控件中去? 请问虾们:DLL,COM,ACTIVEX,ATL都是干啥子用的?有何区别?学习VC必须掌握这些东东吗?多谢!!! 谁用ddk做过视频捕获没有?分数不是问题,我会不断加分! 《深入浅出》 问题7 隆重出炉, 快来呀
包含#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
{
//失败
} 我只是粘在这里
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;
}
1.我的硬盘分区是这样的C:NTFS,D:FAT32,E:FAT32,系统:W2k Server。但是E:的剩余空间计算老是出错,SectorPerCluster、BytesPerSector 都是极大的数858993460,实在搞不懂,另一台机器也是这样。
2.SHBrowseForFolder中加入Edit框之后,如何在Edit框中显示选中目录的全路径。