Lionheart008
30-11-2009, 16:07
hi all, michael, eros.
ok, I have understood! Here's a good example using for example "kernel32.dll" with thinbasic: a disk information viewer example, very useful!
uses "File", "ui"
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 DWORD, _
lpVolumeSerialNumber AS DWORD, _
lpMaximumComponentLength AS DWORD, _
lpFileSystemFlags AS DWORD, _
lpFileSystemNameBuffer AS ASCIIZ, _
BYVAL nFileSystemNameSize AS DWORD _
) AS LONG
DECLARE FUNCTION GetDriveType LIB "KERNEL32.DLL" ALIAS "GetDriveTypeA" (nDrive AS ASCIIZ) AS DWORD
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
Dim VolInf(100) As VolInfoType
Dialog NEW 0 ,"Disk Volume Information Viewer",-1,-1,200,220,%DS_MODALFRAME Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX, 0, To HDlg
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,134, 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 modeless hDlg
dim Temp As String
dim lString As String
dim lRet As Long
dim lCnt As Long
dim lZ As Asciiz * %MAX_PATH
dim i, OldPause, AboutOn, OldPlay as long
dim Msg AS LONG
dim wParam AS LONG
dim lParam AS LONG
WHILE IsWindow(hDlg)
'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)
Select Case Msg
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 lowrd(wParam)
Case %CMB_DRIVES
If HIwrd(wParam) = %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$(Disk_Free(Left$(VolInf(lRet).lZ,2))\1024) + " Kb"
Control Set Text hDlg, %LBL_DT , Str$(Disk_Size(Left$(VolInf(lRet).lZ,2))\1024) + " Kb"
End If
End Select
CASE %WM_SYSCOMMAND
IF wParam = %SC_CLOSE THEN
EXIT WHILE
end if
End Select
wend
best regards, frank