Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Disk Info

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disk Info

    This is a translation of the diskinfo program in Jeffrey Richters
    Advanced windows programming book.

    NOTE: Please check if following declares are correct in win32api:
    Code:
    =================================================================
    These constants can be missing:
    
      %FS_FILE_COMPRESSION   = %FILE_FILE_COMPRESSION
      %FS_VOL_IS_COMPRESSED  = %FILE_VOLUME_IS_COMPRESSED
    
    These declares are incorrect:
    
      Declare Function GetLogicalDriveStrings Lib "KERNEL32.DLL" Alias "GetLogicalDriveStringsA" _
                      (ByVal nBufferLength As Long, _
                       lpBuffer As Asciiz) As Long
      Declare Function GetVolumeInformation Lib "KERNEL32.DLL" Alias "GetVolumeInformationA" _
                      (lpRootPathName As Asciiz, _
                       lpVolumeNameBuffer As Asciiz, _
                       ByVal nVolumeNameSize As Long, _
                       lpVolumeSerialNumber As Long, _
                       lpMaximumComponentLength As Long, _
                       lpFileSystemFlags As Long, _
                       lpFileSystemNameBuffer As Asciiz, _
                       ByVal nFileSystemNameSize As Long) As Long
    
    Should be:
    
      Declare Function GetLogicalDriveStrings Lib "KERNEL32.DLL" Alias "GetLogicalDriveStringsA" _
                      (ByVal nBufferLength As Long, _
                       lpBuffer As Any) As Long
      Declare Function GetVolumeInformation Lib "KERNEL32.DLL" Alias "GetVolumeInformationA" _
                      (lpRootPathName As Asciiz, _
                       lpVolumeNameBuffer As Asciiz, _
                       ByVal nVolumeNameSize As Dword, _
                       lpVolumeSerialNumber As Dword, _
                       lpMaximumComponentLength As Dword, _
                       lpFileSystemFlags As Dword, _
                       lpFileSystemNameBuffer As Asciiz, _
                       ByVal nFileSystemNameSize As Dword) As Long
    =================================================================
    Code:
    #Compile Exe
    #Include "win32api.inc"
    #Include "commctrl.inc"
    
    Global hDlg     As Long
    Global lZStr    As String * 1024
    
    %CMB_DRIVES           = %WM_USER + 1
    %LBL_DRIVETYPE        = %WM_USER + 2
    %CHK_CASE_PRESERVED   = %WM_USER + 3
    %CHK_CASE_SENSITIVE   = %WM_USER + 4
    %CHK_UNICODE          = %WM_USER + 5
    %CHK_ACLS             = %WM_USER + 6
    %CHK_FILE_COMPRESSION = %WM_USER + 7
    %CHK_VOL_COMPRESSED   = %WM_USER + 8
    %LBL_VOLNAME          = %WM_USER + 9
    %LBL_VOLSERIAL        = %WM_USER + 10
    %LBL_MAXFILEN         = %WM_USER + 11
    %LBL_FILFLAGS         = %WM_USER + 12
    %LBL_FILESYS          = %WM_USER + 13
    %LBL_DF               = %WM_USER + 14
    %LBL_DT               = %WM_USER + 15
    
    Type VolInfoType
      VolName       As Asciiz * %MAX_PATH
      VolSerial     As Dword
      FileLength    As Dword
      FileSysFlags  As Dword
      FileSysName   As Asciiz * %MAX_PATH
      DriveType     As Asciiz * %MAX_PATH
      lZ            As Asciiz * %MAX_PATH
    End Type
    
    Declare CallBack Function DlgProc()
    
    Function WinMain (ByVal CurInst As Long, ByVal PrvInst As Long, CmdLine As Asciiz Ptr, ByVal CmdShow As Long) Export As Long
      Dim VolInf(100) As Global VolInfoType
      Dialog New 0 ,"Disk Volume Information Viewer",,,200,220,%DS_MODALFRAME Or %WS_CAPTION Or _
                                                               %WS_SYSMENU Or %WS_MINIMIZEBOX, 0, To HDlg
      InitCommonControls
    
      Control Add Label   , hDlg, -1, "Logical drive strings:", 4, 5, 80, 12
      Control Add ComboBox, hDlg, %CMB_DRIVES,, 85, 4, 100, 60, %CBS_DROPDOWNLIST Or %WS_GROUP Or %WS_TABSTOP Or %WS_VSCROLL
      Control Add Label   , hDlg, -1, "Drive type:", 4, 20, 40,12
      Control Add Label   , hDlg, %LBL_DRIVETYPE, "", 45, 20, 80,12
      Control Add Frame   , hDlg, -1, "Volume Information"  ,  4, 35, 192, 130
      Control Add Label   , hDlg, -1, "Volume name:"        , 10, 50, 75, 12
      Control Add Label   , hDlg, -1, "Serial number:"      , 10, 60, 75, 12
      Control Add Label   , hDlg, -1, "Max length filename:", 10, 70, 75, 12
      Control Add Label   , hDlg, -1, "Flags:"              , 10, 80, 75, 12
      Control Add Label   , hDlg, -1, "File system:"        , 10,150, 75, 12
      
      Control Add Label   , hDlg, %LBL_VOLNAME      , "-", 90, 50, 90, 12
      Control Add Label   , hDlg, %LBL_VOLSERIAL    , "", 90, 60, 90, 12
      Control Add Label   , hDlg, %LBL_MAXFILEN     , "", 90, 70, 90, 12
      Control Add Label   , hDlg, %LBL_FILFLAGS     , "", 90, 80, 90, 12
      Control Add Label   , hDlg, %LBL_FILESYS      , "-", 90,150, 90, 12
    
      Control Add CheckBox, hDlg, %CHK_CASE_PRESERVED   , "Case is preserved"   , 90, 80, 90, 12
      Control Add CheckBox, hDlg, %CHK_CASE_SENSITIVE   , "Case sensitive"      , 90, 90, 90, 12
      Control Add CheckBox, hDlg, %CHK_UNICODE          , "Can store unicode"   , 90,100, 90, 12
      Control Add CheckBox, hDlg, %CHK_ACLS             , "Persistent ACLS"     , 90,110, 90, 12
      Control Add CheckBox, hDlg, %CHK_FILE_COMPRESSION , "File compression"    , 90,120, 90, 12
      Control Add CheckBox, hDlg, %CHK_VOL_COMPRESSED   , "Volume is compressed", 90,130, 90, 12
      
      Control Add Frame   , hDlg, -1, "Disk free space"     ,  4,170,192, 40
      Control Add Label   , hDlg, -1, "Disk free:"          , 10,185, 75, 12
      Control Add Label   , hDlg, -1, "Disk total:"         , 10,195, 75, 12
    
      Control Add Label   , hDlg, %LBL_DF, "-"              , 90,185, 90, 12
      Control Add Label   , hDlg, %LBL_DT, "-"              , 90,195, 90, 12
    
      Dialog Show Modal hDlg, Call DlgProc
    
    End Function
    
    '==================================================================================================
    CallBack Function DlgProc()
      Local Temp As String, lString As String, lRet As Long, lCnt As Long, lZ As Asciiz * %MAX_PATH
      Static i&,OldPause&,AboutOn&, OldPlay&
      Select Case CbMsg
        Case %WM_INITDIALOG
          lZStr = String$(1024,0)
          lRet = GetLogicalDriveStrings (SizeOf(lzStr), lZStr)
          lZStr = Left$(lzStr, lRet)
          For lCnt = 1 To ParseCount (lZStr, Chr$(0)) -1
            lZ = Parse$(lzStr, Chr$(0), lCnt)
            ComboBox Add hDlg, %CMB_DRIVES, lZ
            lRet = GetDriveType (lZ)
            Select Case lRet
              Case %DRIVE_UNKNOWN     : Temp$ = "Cannot be determined"
              Case %DRIVE_NO_ROOT_DIR : Temp$ = "Path does not exist"
              Case %DRIVE_REMOVABLE   : Temp$ = "Removable disk"
              Case %DRIVE_FIXED       : Temp$ = "Fixed"
              Case %DRIVE_REMOTE      : Temp$ = "Remote(Network)"
              Case %DRIVE_CDROM       : Temp$ = "CD-Rom"
              Case %DRIVE_RAMDISK     : Temp$ = "RAM Drive"
              Case Else               : Temp$ = "Unknown"
            End Select
            VolInf(lCnt).DriveType = Temp$
            GetVolumeInformation lZ, _
                                 VolInf(lCnt).VolName, _
                                 SizeOf (VolInf(lCnt).VolName), _
                                 VolInf(lCnt).VolSerial, _
                                 VolInf(lCnt).FileLength, _
                                 VolInf(lCnt).FileSysFlags, _
                                 VolInf(lCnt).FileSysName, _
                                 SizeOf(VolInf(lCnt).FileSysName)
             VolInf(lCnt).lZ = lZ
          Next
        Case %WM_COMMAND
          Select Case CbCtl
            Case %CMB_DRIVES
              If CbCtlMsg = %CBN_SELENDOK Then
                 ComboBox Get Text hDlg, %CMB_DRIVES To lString
                 Control Send hDlg, %CMB_DRIVES, %CB_GETCURSEL, 0, 0 To lRet
                 Incr lRet
                 Control Set Text hDlg, %LBL_VOLNAME  , VolInf(lRet).VolName
                 Control Set Text hDlg, %LBL_DRIVETYPE  , VolInf(lRet).DriveType
                 Control Set Text hDlg, %LBL_VOLSERIAL, Hex$(VolInf(lRet).VolSerial, 8)
                 Control Set Text hDlg, %LBL_FILESYS  , VolInf(lRet).FileSysName
                 Control Set Text hDlg, %LBL_MAXFILEN  , Format$(VolInf(lRet).FileLength, "") + " Bytes"
                 Control Set Check hDlg, %CHK_CASE_PRESERVED   , (VolInf(lRet).FileSysFlags And %FS_CASE_IS_PRESERVED)
                 Control Set Check hDlg, %CHK_CASE_SENSITIVE   , (VolInf(lRet).FileSysFlags And %FS_CASE_SENSITIVE)
                 Control Set Check hDlg, %CHK_UNICODE          , (VolInf(lRet).FileSysFlags And %FS_UNICODE_STORED_ON_DISK)
                 Control Set Check hDlg, %CHK_ACLS             , (VolInf(lRet).FileSysFlags And %FS_PERSISTENT_ACLS)
                 Control Set Check hDlg, %CHK_FILE_COMPRESSION , (VolInf(lRet).FileSysFlags And %FS_FILE_COMPRESSION)
                 Control Set Check hDlg, %CHK_VOL_COMPRESSED   , (VolInf(lRet).FileSysFlags And %FS_VOL_IS_COMPRESSED)
    
                 Control Set Text hDlg, %LBL_DF , Str$(DiskFree(Left$(VolInf(lRet).lZ,2))\1024) + " Kb"
                 Control Set Text hDlg, %LBL_DT , Str$(DiskSize(Left$(VolInf(lRet).lZ,2))\1024) + " Kb"
              End If
          End Select
      End Select
     End Function
    
    '--------------------------------------------------------------------------------------------------
    ------------------
    Peter.
    mailto[email protected][email protected]</A>
    Regards,
    Peter

  • #2
    Thanks

    That is what I was looking for, thanks!

    Apparently the "magic word" is "serial number", not "disk ID".

    Comment


    • #3
      Volumn Number <> Serial Number

      JFYI, The volume number is assigned by the partition utility used, whereas the serial number is factory coded. They are not the same.
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        direction to code giving serial number of drive

        pardon me, i walking lightly here with my head low.

        i found Jose Roca's great code work that gives the serial number.

        http://powerbasic.com/support/pbforu...ad.php?t=23879

        i have been looking for that myself
        p purvis

        Comment

        Working...
        X