Get the disk drive letter getlogicaldrivestrings, heapalloc

Source: Internet
Author: User
Tags 04x

: Findalldrivers ()
{
Ccombobox * driver = (ccombobox *) getdlgitem (idc_driver );
DWORD dwnumbytesfordrivestrings; // String Length of the actual storage drive letter
Handle hheap;
Lpstr LP;
Cstring strlogdrive;

// Obtain the string length of the actual storage drive letter
Dwnumbytesfordrivestrings = getlogicaldrivestrings (0, null) * sizeof (tchar );

// If the string is not empty, a normal drive exists.
If (dwnumbytesfordrivestrings! = 0 ){
// Allocate string Space
Hheap = getprocessheap ();
Lp = (lpstr) heapalloc (hheap, heap_zero_memory,
Dwnumbytesfordrivestrings );

// Obtain the string indicating all drives
Getlogicaldrivestrings (heapsize (hheap, 0, LP), LP );

// Place the drives one by one in the drop-down box
While (* lp! = 0 ){
Driver-> addstring (LP );
Lp = _ tcschr (LP, 0) + 1;
}
}
Else
Afxmessagebox ("can't use the function getlogicaldrivestrings! ");
}

 

Clistctrl * plist = (clistctrl *) getdlgitem (idc_list );
Plist-> modifystyle (lvs_icon | lvs_smallicon | lvs_list, lvs_report );
Plist-> setextendedstyle (lvs_ex_gridlines | lvs_ex_fullrowselect );
Plist-> insertcolumn (0, _ T ("drive name"), lvcfmt_left, 100 );
Plist-> insertcolumn (1, _ T ("drive type"), lvcfmt_left, 100 );
Plist-> insertcolumn (2, _ T ("drive volume label"), lvcfmt_left, 100 );
Plist-> insertcolumn (3, _ T ("drive serial number"), lvcfmt_left, 100 );
Plist-> insertcolumn (4, _ T ("drive file system"), lvcfmt_left, 100 );
Plist-> insertcolumn (5, _ T ("available space"), lvcfmt_left, 100 );
Plist-> insertcolumn (6, _ T ("total space"), LV cfmt_left, 100 );

Clistctrl * plist = (clistctrl *) getdlgitem (idc_list );
Plist-> deleteallitems ();

// Obtain the drive bit mask
DWORD dwbitmask =: getlogicaldrives ();
If (dwbitmask! = 0)
{
Int n = 0;

Tchar CH = 'a ';

While (dwbitmask> 0)
{
If (dwbitmask % 2 = 1)
{
// Drive name
Cstring strdirivename = _ T ("");
Strdirivename. Format (_ T ("% C: \"), ch );
Plist-> insertitem (n, strdirivename );

// Obtain the drive type
Uint ndrivetype = getdrivetype (strdirivename );
Cstring strdirivetype = _ T ("");
If (ndrivetype = drive_unknown)
{
Strdirivetype = _ T ("unknown ");
}
Else if (ndrivetype = drive_no_root_dir)
{
Strdirivetype = _ T ("invalid path ");
}
Else if (ndrivetype = drive_removable)
{
Strdirivetype = _ T ("Removable Drive ");
}
Else if (ndrivetype = drive_fixed)
{
Strdirivetype = _ T ("fixed drive ");
}
Else if (ndrivetype = drive_remote)
{
Strdirivetype = _ T ("remote (network) Drive ");
}
Else if (ndrivetype = drive_cdrom)
{
Strdirivetype = _ T ("CDROM Drive ");
}
Else if (ndrivetype = drive_ramdisk)
{
Strdirivetype = _ T ("RAM disk ");
}
Plist-> setitemtext (n, 1, strdirivetype );

// Obtain the drive volume label
Cstring strvolumename = _ T ("");
Getvolumeinformation (strdirivename, strvolumename. getbuffer (1024 ),
1024, null, 0 );
Strvolumename. releasebuffer ();
Plist-> setitemtext (n, 2, strvolumename );

// Obtain the drive serial number
DWORD dwserialnumber = 0;
Cstring strvolumename = _ T ("");
Getvolumeinformation (strdirivename, null,
0, & dwserialnumber, null, 0 );
Cstring strserialnumber = _ T ("");
Strserialnumber. Format (_ T ("% 04x-% 04x "),
Hiword (dwserialnumber), loword (dwserialnumber ));
Plist-> setitemtext (n, 3, strserialnumber );

// Obtain the drive File System
Cstring strfilesystemname = _ T ("");
Getvolumeinformation (strdirivename, null, 0, null,
Strfilesystemname. getbuffer (1024), 1024 );
Strfilesystemname. releasebuffer ();
Plist-> setitemtext (n, 1, strfilesystemname );

// Obtain disk space information
Ularge_integer freebytes;
Ularge_integer totalbytes;
If (! Getdiskfreespaceex (strdirivename, & freebytes,
& Totalbytes, null ))
{
Return;
}

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, 5, strtext );
Strtext. Format (_ T ("% d MB"), ntotalsize );
Plist-> setitemtext (n, 6, strtext );

N ++;
}

Dwbitmask/= 2;

Ch ++;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.