超级博客 Win32 设备管理(1)

来源:互联网 发布:淘宝订单能保存多久 编辑:程序博客网 时间:2024/05/06 03:25

点击打开链接

一.获得物理内存参数

使用GlobalMemoryStatus函数

复制代码
void CDemoDlg::OnTest() 
{
    CListBox
* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
    pListBox
->ResetContent();

    
//获得物理内存参数
    MEMORYSTATUS MemoryStatus;
    GlobalMemoryStatus(
&MemoryStatus);

    CString strText 
= _T("");
    strText.Format(_T(
"物理内存使用率:%d%s"), 
        MemoryStatus.dwMemoryLoad, _T(
"%"));
    pListBox
->AddString(strText);
    strText.Format(_T(
"物理内存总数:  %dK"), 
        MemoryStatus.dwTotalPhys 
/ 1024);
    pListBox
->AddString(strText);
    strText.Format(_T(
"物理内存可用数:%dK"), 
        MemoryStatus.dwAvailPhys 
/ 1024);
    pListBox
->AddString(strText);
    strText.Format(_T(
"页文件总数:    %dK"), 
        MemoryStatus.dwTotalPageFile 
/ 1024);
    pListBox
->AddString(strText);
    strText.Format(_T(
"页文件用数:    %dK"), 
        MemoryStatus.dwAvailPageFile 
/ 1024);
    pListBox
->AddString(strText);
    strText.Format(_T(
"虚拟内存总数:  %dK"), 
        MemoryStatus.dwTotalVirtual 
/ 1024);
    pListBox
->AddString(strText);
    strText.Format(_T(
"虚拟内存可用数:%dK"), 
        MemoryStatus.dwAvailVirtual 
/ 1024);
    pListBox
->AddString(strText);
}
复制代码


二.获取驱动器

使用GetLogicalDrives方法,使用位掩码方式获得驱动器

 

View Code

 

三.获取驱动器类型

使用GetDriveType函数,输入参数如C:\,根据返回的值判别类型

View Code

 

四.获得驱动器卷标

使用GetVolumeInformation函数,即硬盘分区的名字(卷标)

 

View Code

 

五.设置驱动器卷标

 使用SetVolumeLabel函数,需要管理员权限

 

View Code

 

 六.获得驱动器序列号

还是使用GetVolumeInformation函数,第4个参数为输出结果,第一个参数是必须的

 

                //获得驱动器序列号
                DWORD dwSerialNumber = 0;
                GetVolumeInformation(strDiriveName, NULL,
                    NULL, 
&dwSerialNumber, NULL, NULL, NULL, 0);

 

七.获得驱动器文件系统

用GetVolumeInformation函数,最后两个参数填充,即获取装载文件系统的名称(如FAT,NTFS以及其他)

 

复制代码
                //获得驱动器文件系统
                CString strFileSystemName = _T("");
                GetVolumeInformation(strDiriveName, NULL, 
0, NULL, NULL, NULL, 
                    strFileSystemName.GetBuffer(
1024), 1024);
                strFileSystemName.ReleaseBuffer();
                pList
->SetItemText(n, 1, strFileSystemName);
复制代码

 

八.获取驱动器磁盘空间信息

使用GetDiskFreeSpaceEx函数

 

复制代码
                //获得磁盘空间信息
                ULARGE_INTEGER FreeBytes;
                ULARGE_INTEGER TotalBytes;
                
if (!GetDiskFreeSpaceEx(strDiriveName, &FreeBytes,
                    
&TotalBytes, NULL))
                {
                    FreeBytes.QuadPart
=0;
                    TotalBytes.QuadPart
=0;
                }

                UINT nFreeSize 
= (UINT)(FreeBytes.QuadPart / 1024 / 1024);
                UINT nTotalSize 
= (UINT)(TotalBytes.QuadPart / 1024 / 1024);

                CString strText 
= _T("");
                strText.Format(_T(
"%d MB"), nFreeSize);
                pList
->SetItemText(n, 1, strText);
                strText.Format(_T(
"%d MB"),nTotalSize);
                pList
->SetItemText(n, 2, strText);
复制代码

 


0 0