Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create a form display only drives/attached network folde
Message
From
20/10/2006 13:30:57
 
 
To
20/10/2006 13:00:36
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01163638
Message ID:
01163701
Views:
8
Try this:
oform = CREATEOBJECT('driveform')
oform.show()
read events


DEFINE CLASS driveform AS form


	Top = 0
	Left = 0
	Height = 250
	Width = 473
	DoCreate = .T.
	Caption = "Drives"
	driveselected = "' '"
	Name = "frmDrives"
	DIMENSION ladrives[1]


	ADD OBJECT combo1 AS combobox WITH ;
		ColumnCount = 2, ;
		ColumnWidths = "50,350", ;
		RowSourceType = 5, ;
		RowSource = "thisform.ladrives", ;
		ControlSource = "thisform.driveselected", ;
		Height = 24, ;
		Left = 12, ;
		Style = 2, ;
		Top = 48, ;
		Width = 444, ;
		BoundTo = .T., ;
		Name = "Combo1"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 156, ;
		Left = 144, ;
		Height = 48, ;
		Width = 168, ;
		Caption = "Show Selected Value", ;
		Name = "Command1"


	PROCEDURE getuncfordriveletter
		*FUNCTION GetUNCForDriveLetter
		LPARAMETER cDriveLetterToCheck
		LOCAL cBuffer, nResult, lcunc
		IF TYPE('cDriveLetterToCheck') # 'C' OR ;
				LEN(cDriveLetterToCheck) < 2 OR ;
				SUBSTR(cDriveLetterToCheck,2,1) # ':' OR ;
				! BETWEEN(UPPER(LEFT(cDriveLetterToCheck,1)),'A','Z')
			RETURN ''
		ENDIF
		DECLARE INTEGER WNetGetConnection IN Win32API ;
			STRING   @cLocalDrive, ;
			STRING   @cRemoteUNCBuffer, ;
			INTEGER  @nSizeOfBuffer
		cBuffer = SPACE(511)
		nResult = WNetGetConnection(LEFT(cDriveLetterToCheck,2), ;
			@cBuffer, ;
			511)
		IF nResult # 0
		*  Failed - it's probably not a mapped drive,
		*  or nothing is mapped to it
			RETURN ''
		ELSE
			lcunc=LEFT(cBuffer,AT(CHR(0),cBuffer)-1)
			RETURN lcunc
		*RETURN LEFT(cBuffer,AT(CHR(0),cBuffer)-1)
		ENDIF
	ENDPROC


	PROCEDURE Destroy
		CLEAR EVENTS
		DODEFAULT()
	ENDPROC
	
	PROCEDURE Init
		* Constants for drive types.
		ON ERROR return

		#DEFINE DRIVE_UNKNOWN 0
		#DEFINE DRIVE_NO_ROOT_DIR 1
		#DEFINE DRIVE_REMOVABLE 2
		#DEFINE DRIVE_FIXED 3
		#DEFINE DRIVE_REMOTE 4
		#DEFINE DRIVE_CDROM 5
		#DEFINE DRIVE_RAMDISK 6
		#DEFINE CR CHR(13)

		DECLARE INTEGER GetLogicalDrives IN Win32API
		DECLARE INTEGER GetDriveType IN Win32API STRING RootPath

		PRIVATE lcDrivestring, lcDriveRoot, liDrivelist, lcDrives, i
		lcDrives = ""

		* GetLogicalDrives returns a 32-bit value containing a list of
		* available drives. If the specific bit is ON, the drive letter
		* corresponding to that position exists.
		liDrivelist = GetLogicalDrives()

		* Check each of the bits
		dimension ladrives(1,2)
		idrives = 0
		FOR i = 0 TO 31
			IF BITTEST(liDrivelist, i)
				idrives = idrives + 1
				* If the 0th bit is ON, that means drive 'A:',
				* the 2nd bit is 'C:", etc.
				lcDriveRoot = CHR(65 + i) + ":\"
				dimension ladrives(idrives,2)
				ladrives(idrives,1) = lcDriveRoot
				* Perform a GetDriveType to determine if it is a floppy, CD, etc.
				lcDrivetype = GetDriveType(lcDriveRoot)
				DO CASE
					CASE lcDrivetype = DRIVE_UNKNOWN
						lcDrivestring = "Cannot be determined"
					CASE lcDrivetype = DRIVE_NO_ROOT_DIR
						lcDrivestring = "Root directory does not exist"
					CASE lcDrivetype = DRIVE_REMOVABLE
						lcDrivestring = "Floppy/removable drive"
					CASE lcDrivetype = DRIVE_FIXED
						lcDrivestring = "Hard drive/nonremovable drive"
					CASE lcDrivetype = DRIVE_REMOTE
						lcDrivestring = "Remote/Network drive"
						lcunc=thisform.GetUNCForDriveLetter(LEFT(lcDriveRoot,2))
						IF TYPE('lcunc')="C" .AND. !EMPTY(lcunc)
							lcDrivestring = lcunc
						ENDIF
					CASE lcDrivetype = DRIVE_CDROM
						lcDrivestring = "CD-ROM drive"
					CASE lcDrivetype = DRIVE_RAMDISK
						lcDrivestring = "RAM disk"
				ENDCASE
				lcDrives = lcDrives + lcDriveRoot + " " + lcDrivestring + CR
				ladrives(idrives,2) = " " + lcDriveString
			ENDIF
		NEXT

		*=ALINES(ladrives,lcDrives,CHR(13))

		IF TYPE('ALEN(ladrives,1)') = 'N' .and. ALEN(ladrives,1) >=1 .and. TYPE('ladrives(1)') = "C"
			DIMENSION thisform.ladrives(ALEN(ladrives,1),2)
			=ACOPY(ladrives,thisform.ladrives)
		ELSE
			dimension thisform.ladrives(1)
			thisform.ladrives(1,1) = 'No drives found'
			thisform.ladrives(1,2) = ''
		ENDIF
		this.combo1.requery()
		lnpos=ASCAN(thisform.ladrives,'C:\')
		IF Lnpos > 0
			this.driveselected = thisform.ladrives(lnpos)
		ELSE
			this.driveselected = thisform.ladrives(1,1)
		ENDIF
		DODEFAULT()
	ENDPROC


	PROCEDURE command1.Click
		=MESSAGEBOX(thisform.driveselected+' is currently selected',0+64+4096,'Selected Drive')
	ENDPROC


ENDDEFINE
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform