有効なドライブの取得 <TOP>
GetLogicalDriveStrings 有効なドライブ名の取得
GetDriveType ドライブタイプを取得
ComboBoxでドライブを指定し『取得』をクリックします。有効なドライブが表示されます。
'================================================================ '= 有効なドライブ名の取得 '= (GetLogicalDriveStrings.bas) '================================================================ #include "Windows.bi" ' 有効なドライブ名の取得 Declare Function Api_GetLogicalDriveStrings& Lib "Kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength&, ByVal lpBuffer$) ' ドライブのタイプを取得 Declare Function Api_GetDriveType& Lib "Kernel32" Alias "GetDriveTypeA" (ByVal nDrive$) #define DRIVE_NODETERMINE_DRIVEType 0 'ドライブが不明 #define DRIVE_NOEXIST_ROOTDIRECTORY 1 'ルートディレクトリなし #define DRIVE_REMOVABLE 2 '取り外し可能タイプ−リムーバブルディスク(FD,MO) #define DRIVE_FIXED 3 '固定タイプ−主にハードディスク #define DRIVE_REMOTE 4 'ネットワーク #define DRIVE_CDROM 5 'CD-ROMドライブ #define DRIVE_RAMDISK 6 'RAMドライブ Var Shared drvNo As Integer Var Shared Drv$(20) As String Var Shared drvNam$(4) As String Var Shared List1 As Object Var Shared Combo1 As Object Var Shared Button1 As Object List1.Attach GetDlgItem("List1") : List1.SetFontSize 14 Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub Mainform_Start edecl () Sub Mainform_Start() For i = 0 To 4 Read drvNam$(i) Combo1.AddString drvNam$(i) Next i data DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_REMOTE, DRIVE_CDROM, DRIVE_RAMDISK End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Buf$ As String Var Ret As Long Var ct As Integer Var i As Integer ct = 0 Buf$ = String$(255, Chr$(0)) Ret = Api_GetLogicalDriveStrings(255, Buf$) Do until Left$(Buf$, 1) = Chr$(0) If Api_GetDriveType(Left$(Buf$, InStr(1, Buf$, Chr$(0)) - 1)) = drvNo Then ct = ct + 1 Drv$(ct) = Left$(Buf$, 3) End If Buf$ = Right$(Buf$, Len(Buf$) - 4) Loop If ct = 0 Then Exit Sub For i = 1 To ct List1.AddString "Found : " & Str$(i) & " = " & Drv$(i) Next End Sub '================================================================ '= '================================================================ Declare Sub Combo1_Change edecl () Sub Combo1_Change() drvNo = Combo1.GetCursel + 2 List1.ResetContent End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End