windows-nt/Source/XPSP1/NT/admin/activec/designer/samples/drivestats/drivestats.dsr
2020-09-26 16:20:57 +08:00

974 lines
37 KiB
Plaintext

VERSION 5.00
Begin {B3E55942-FFD8-11D1-9788-44A620524153} DriveStats
ClientHeight = 8970
ClientLeft = 0
ClientTop = 0
ClientWidth = 10515
_ExtentX = 18547
_ExtentY = 15822
m_iNextNodeNumber= 2
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ImageLists {FFF9A8F6-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty Menus {11517450-27FE-11D3-AA41-00104B880587}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 0
BeginProperty Item1 {91CC37D5-CE2B-11D1-B44D-7E92AF000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Caption = "Menu1"
Visible = -1
Checked = 0
Enabled = -1
Grayed = 0
MenuBreak = 0
MenuBarBreak = 0
Default = 0
Index = 1
Name = "mnuChooseDrive"
StatusBarText = ""
BeginProperty Children {11517450-27FE-11D3-AA41-00104B880587}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 0
BeginProperty Item1 {91CC37D5-CE2B-11D1-B44D-7E92AF000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Caption = "Choose drive"
Visible = -1
Checked = 0
Enabled = -1
Grayed = 0
MenuBreak = 0
MenuBarBreak = 0
Default = 0
Index = 1
Name = "mnuChooseTask"
StatusBarText = ""
BeginProperty Children {11517450-27FE-11D3-AA41-00104B880587}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
Key = "Menu1"
DISPID = 1001
EndProperty
EndProperty
Key = "Menu1"
DISPID = 1000
EndProperty
EndProperty
BeginProperty Toolbars {FFF9A8FA-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty ViewDefs {FFF9A8E1-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ListViews {FFF9A8FC-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 0
BeginProperty Item1 {FFF9A8EC-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Index = 1
Key = "lvDriveStats"
Name = "lvDriveStats"
AddToViewMenu = 0
ViewMenuText = ""
ViewMenuStatusBarText= ""
DefaultItemTypeGUID= "{BD7F7140-A8A4-11D2-97E5-00104B880587}"
Extensible = 0
BeginProperty ListView {87BC180F-C8FB-11D1-B44A-30F4BC000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ColumnHeaders {3B15D611-CD57-11D1-B44C-44750B000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 2
KeysOnly = 0
BeginProperty Item1 {3B15D613-CD57-11D1-B44C-44750B000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Index = 1
Key = "Stat"
Tag = 0
Text = "Stat"
Object.Width = 120
Alignment = 0
Hidden = 0
TextFilter = ""
TextFilterMaxLen= 260
NumericFilter = ""
EndProperty
BeginProperty Item2 {3B15D613-CD57-11D1-B44C-44750B000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Index = 2
Key = "Value"
Tag = 0
Text = "Value"
Object.Width = 120
Alignment = 0
Hidden = 0
TextFilter = ""
TextFilterMaxLen= 260
NumericFilter = ""
EndProperty
EndProperty
Icons = ""
SmallIcons = ""
Sorted = 0
SortKey = 0
SortOrder = 0
View = 3
Tag = 0
Virtual = 0
UseFontLinking = 0
MultiSelect = 0
HideSelection = 0
SortHeader = -1
SortIcon = -1
FilterChangeTimeout= 500
ShowChildScopeItems= -1
LexicalSort = 0
EndProperty
EndProperty
EndProperty
BeginProperty OCXViews {FFF9A8FF-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty URLViews {FFF9A902-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty TaskpadViews {FFF9A904-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 0
BeginProperty Item1 {FFF9A8F2-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = "StatsListpad"
Index = 1
Key = "StatsListpad"
AddToViewMenu = 0
ViewMenuText = ""
ViewMenuStatusBarText= ""
UseWhenTaskpadViewPreferred= 0
BeginProperty Taskpad {861481F2-D867-11D1-B450-C43058000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = "StatsListpad"
Type = 4
Title = "Drive Statistics"
URL = ""
DescriptiveText = "DriveStats Dynamic Namespace Extension"
BackgroundType = 0
MouseOverImage = ""
MouseOffImage = ""
FontFamily = ""
EOTFile = ""
SymbolString = ""
ListpadStyle = 1
ListpadTitle = ""
ListpadHasButton= -1
ListpadButtonText= "Change..."
ListView = "lvDriveStats"
BeginProperty Tasks {861481F4-D867-11D1-B450-C43058000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
EndProperty
EndProperty
EndProperty
EndProperty
BeginProperty DataFormats {91FE14C5-7370-11D2-97D8-00104B880587}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty SnapInDef {FFF9A8E4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = "DriveStats"
NodeTypeName = "DriveStats"
NodeTypeGUID = "{D42F4542-CD95-11d2-97ED-00104B880587}"
DisplayName = "DriveStats"
Type = 1
HelpFile = ""
LinkedTopics = ""
Description = "Description of your snap-in"
Provider = "Microsoft Corporation"
Version = "1.0"
SmallFolders = ""
SmallFoldersOpen= ""
LargeFolders = ""
Icon = "DriveStats.dsx":0000
Watermark = "DriveStats.dsx":005E
Header = "DriveStats.dsx":00BC
Palette = "DriveStats.dsx":011A
StretchWatermark= 0
StaticFolder = 0
DefaultView = ""
Extensible = 0
BeginProperty ViewDefs {FFF9A8E1-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ListViews {FFF9A8FC-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty OCXViews {FFF9A8FF-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty URLViews {FFF9A902-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty TaskpadViews {FFF9A904-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
EndProperty
BeginProperty Children {FFF9A8F4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
IID = "{AE9CA206-D929-466E-ADE1-CBBF0F9F1C84}"
Preload = 0
EndProperty
BeginProperty ExtensionDefs {FFF9A8E6-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
ExtendsNewMenu = 0
ExtendsTaskMenu = 0
ExtendsTopMenu = 0
ExtendsViewMenu = 0
ExtendsPropertyPages= 0
ExtendsToolbar = 0
ExtendsNameSpace= 0
BeginProperty ExtendedSnapIns {BDA4B9D1-0872-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 2
KeysOnly = 0
BeginProperty Item1 {FFF9A8E8-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = ""
Index = 1
Key = "{119067F7-4DBC-11D2-8873-0080C7E0ACE4}"
CLSID = "{119067F7-4DBC-11D2-8873-0080C7E0ACE4}"
DisplayName = "Directory"
Dynamic = -1
ExtendsNameSpace= -1
ExtendsNewMenu = 0
ExtendsTaskMenu = 0
ExtendsPropertyPages= 0
ExtendsToolbar = 0
ExtendsTaskpad = 0
EndProperty
BeginProperty Item2 {FFF9A8E8-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = ""
Index = 2
Key = "{119067B6-4DBC-11D2-8873-0080C7E0ACE4}"
CLSID = "{119067B6-4DBC-11D2-8873-0080C7E0ACE4}"
DisplayName = "MyComputer"
Dynamic = -1
ExtendsNameSpace= -1
ExtendsNewMenu = 0
ExtendsTaskMenu = 0
ExtendsPropertyPages= 0
ExtendsToolbar = 0
ExtendsTaskpad = 0
EndProperty
EndProperty
EndProperty
BeginProperty AutoCreateNodes {FFF9A8F4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty OtherNodes {FFF9A8F4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 2
KeysOnly = 0
BeginProperty Item1 {FFF9A8EA-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = "DriveStats"
Index = 1
Key = "DriveStats"
NodeTypeName = "DriveStats"
NodeTypeGUID = "{BD7F713F-A8A4-11D2-97E5-00104B880587}"
DisplayName = "<Stats>"
Folder = "0"
DefaultDataFormat= ""
AutoCreate = 0
DefaultView = "lvDriveStats"
HasChildren = -1
Extensible = 0
BeginProperty ViewDefs {FFF9A8E1-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ListViews {FFF9A8FC-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 1
Item1 = "lvDriveStats"
EndProperty
BeginProperty OCXViews {FFF9A8FF-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty URLViews {FFF9A902-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty TaskpadViews {FFF9A904-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
EndProperty
BeginProperty Children {FFF9A8F4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
Tag = 0
BeginProperty ColumnHeaders {3B15D611-CD57-11D1-B44C-44750B000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
EndProperty
BeginProperty Item2 {FFF9A8EA-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Name = "MyComputerStats"
Index = 2
Key = "MyComputerStats"
NodeTypeName = "MyComputerStats"
NodeTypeGUID = "{817721E0-2A99-11D3-AA41-00104B880587}"
DisplayName = "<Stats>"
Folder = ""
DefaultDataFormat= ""
AutoCreate = 0
DefaultView = "StatsListpad"
HasChildren = -1
Extensible = -1
BeginProperty ViewDefs {FFF9A8E1-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
BeginProperty ListViews {FFF9A8FC-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 1
Item1 = "lvDriveStats"
EndProperty
BeginProperty OCXViews {FFF9A8FF-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty URLViews {FFF9A902-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 1
EndProperty
BeginProperty TaskpadViews {FFF9A904-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 1
KeysOnly = 1
Item1 = "StatsListpad"
EndProperty
EndProperty
BeginProperty Children {FFF9A8F4-06CB-11D2-9791-50C320524153}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
BeginProperty ColumnHeaders {3B15D611-CD57-11D1-B44C-44750B000000}
Persistence.MajorVersion= 0
Persistence.MinorVersion= 12
Count = 0
KeysOnly = 0
EndProperty
EndProperty
EndProperty
TypeinfoCookie = 47
ProjectName = "DriveStatsProj"
End
Attribute VB_Name = "DriveStats"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
' ===========================================================================
' | THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF |
' | ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
' | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A |
' | PARTICULAR PURPOSE. |
' | Copyright (c) 1998-1999 Microsoft Corporation |
' ===========================================================================
' =============================================================================
' File: DriveStats.dsr
' Project: DriveStatsProj
' Type: SnapIn Designer
' =============================================================================
' =============================================================================
' Method: ExtensionSnapIn_Expand
' Type: Event
' Description: Fired when a context menu is about to be displayed to give the
' extension snap-in the opportunity to add items to MMC's "Task"
' sub-menu.
'
' Parameters: Data An MMCDataObject containing data exported by
' the expanding node owned by the extended snap-in.
' The extensions snap-in must interpret the data
' exported by the extended snap-in (in this case
' FileExplorer exports the data).
' ScopeNode Object representing the expanding node. Used
' as the parent node if the extension decides to
' extend the namespace by adding a child node.
' Output: None
' Notes: If the expanding node is a FileExplorer drive then adds a child
' node called "<Stats>".
' If the expanding node is FileExplorer's "My Computer" node then
' add our MyComputerStats node.
' =============================================================================
'
Private Sub ExtensionSnapIn_Expand(ByVal Data As SnapInLib.IMMCDataObject, _
ByVal ScopeNode As SnapInLib.IScopeNode)
On Error GoTo ErrTrap_ExtensionSnapIn_Expand
Dim DriveName As String
Dim DriveScopeItem As ScopeItem
Dim DrivesScopeItem As ScopeItem
' FileExplorer exports a format called "Drive" for drive nodes. If it is there
' then add our <Stats> node underneath it.
If Data.GetFormat("Drive") Then
' It is a drive node. Get the name of the drive from the exported data.
DriveName = Data.GetData("Drive")
' Add our scope item to the namespace and set its tag to the drive name
Set DriveScopeItem = ScopeItems.AddPreDefined("DriveStats", DriveName, ScopeNode, siParent)
DriveScopeItem.Tag = DriveName
' Add a single column called "<Stats>" for when this scope item is displayed
' in the result pane in report mode. In that case the designer runtime will use the
' column number to index ScopeItem.ListSubItems. This ensures that the word
' "<Stats>" will always appear in the first column. Other columns will not contain
' anything. Note also that unlike a standalone snap-in there is no need to define
' column headers for the scope item as the column names of the extended snap-in
' are not available to the runtime.
DriveScopeItem.ListSubItems.Add 1, 1, "<Stats>"
ElseIf Data.GetFormat("DriveNames") Then
' FileExplorer exports a format called "DriveNames" for its "My Computer" node
' Add our MyComputerStats node underneath it and set its tag to the drive name
' array exported from FileExplorer
Set DrivesScopeItem = ScopeItems.AddPreDefined("MyComputerStats", "MyComputerStats", ScopeNode, siParent)
DrivesScopeItem.Tag = FormatData(Data.GetData("DriveNames"), 1, siMultiString)
DrivesScopeItem.ListSubItems.Add 1, 1, "<Stats>"
End If
Exit Sub
' Error Handler for this method
ErrTrap_ExtensionSnapIn_Expand:
DisplayError "ExtensionSnapIn_Expand"
End Sub
' =============================================================================
' Method: ResultViews_Deactivate
' Type: Event
' Description: Fired when the result pane is being torn down.
'
' Parameters: ResultView The ResultView about to be destroyed.
' Keep Defaults to False to indicate that the ResultView
' object should be destroyed. Set to True to keep
' the object alive so that it can be reused if the
' scope pane item is ever reselected.
' Output: None
' Notes: As an example, keep the ResultView alive.
' =============================================================================
'
Private Sub ResultViews_Deactivate(ByVal ResultView As SnapInLib.IResultView, _
Keep As Boolean)
' It can be very expensive to populate the listview because certain drive stats
' take some time to gather (e.g. on net drives over a slow connection) so we keep
' the result view alive in case the user decides to look at it again. In order to
' make this work we also need to handle ScopePaneItems_GetResultView to tell the
' runtime to reuse the existing one.
Keep = True
End Sub
' =============================================================================
' Method: ResultViews_ListpadButtonClick
' Type: Event
' Description: Fired when the "Change..." button is clicked on the listpad
'
' Parameters: ResultView The ResultView about to be destroyed.
'
' Output: None
'
' Notes: Displays a form with a listbox of available drives and allows
' the user to select a drive. If the user selects a drive
' then clears out the listpad's list view and repopulates it
' with the drive's statistics.
' =============================================================================
'
Private Sub ResultViews_ListpadButtonClick(ByVal ResultView As SnapInLib.ResultView)
On Error GoTo ErrTrap_ResultViews_ListpadButtonClick
Dim frm As New frmChooseDrive
Dim DriveNames() As String
' Get the drive names array we stored in our MyComputerStats ScopeItem's
' Tag during ExtensionSnapIn_Expand.
DriveNames = ScopeItems("MyComputerStats").Tag
' Load the form, give it the list of drive names and the index of the
' currently displayed drive. Show the form as a modal dialog.
' Get the index of the currently displayed drive in the ResultView's Tag.
Load frm
frm.SetDriveNames DriveNames, ResultView.Tag
frm.Show vbModal
' If the user clicked OK then get the index of the chosen drive and
' check if it is ready. If it is ready then clear out the listpad's
' list view and repopulate it with the drive's statistics.
' Store the index of the chosen drive in the ResultView's Tag.
If frm.OK Then
ChangeDrive DriveNames(frm.DriveChosen), frm.DriveChosen
End If
Exit Sub
' Error Handler for this method
ErrTrap_ResultViews_ListpadButtonClick:
DisplayError "ResultViews_ListpadButtonClick"
End Sub
Private Sub ChangeDrive(DriveName As String, Index As Integer)
On Error GoTo ErrTrap_ChangeDrive
Dim drv As Scripting.Drive
Dim fs As New Scripting.FileSystemObject
Set drv = fs.GetDrive(DriveName)
If drv.IsReady Then
With CurrentResultView
.ListView.ListItems.Clear
DisplayDriveStats DriveName, .ListView.ListItems
.Tag = Index
End With
Else
ConsoleMsgBox "Drive " & DriveName & " is not ready. Please choose another drive", vbOK, "DriveStats"
End If
Exit Sub
' Error Handler for this method
ErrTrap_ChangeDrive:
DisplayError "ChangeDrive"
End Sub
' =============================================================================
' Method: ScopePaneItems_GetResultView
' Type: Event
' Description: Fired when the result pane is about to be shown. Allows the
' snap-in to reuse a ResultView kept alive in an earlier
' ResultViews_Deactivate event.
'
' Parameters: ScopePaneItem The ScopePaneItem that has been selected and
' for which the result pane is about to be shown.
' Index If the snap-in wishes to reuse an existing
' ResultView it should return its index within
' ScopePaneItem.ResultViews here.
' Output: None
' Notes: As an example, keep the ResultView alive.
' =============================================================================
'
Private Sub ScopePaneItems_GetResultView(ByVal ScopePaneItem As SnapInLib.IScopePaneItem, _
Index As Variant)
On Error GoTo ErrTrap_ScopePaneItems_GetResultView
' If there is an existing result view then use it. There can only be one so
' we know its index
If ScopePaneItem.ResultViews.Count > 0 Then
Index = 1
End If
Exit Sub
' Error Handler for this method
ErrTrap_ScopePaneItems_GetResultView:
DisplayError "ScopePaneItems_GetResultView"
End Sub
' =============================================================================
' Method: ResultViews_Initialize
' Type: Event
' Description: Fired when a new ResultView is created.
' Parameters: ResultView A reference to the specific ResultView object
' being initialized
' Output: None
' Notes: This is the event used to trigger population of the ResultView.
' It only occurs as a ResultView is being created. It is not
' fired in response to changing the view mode. However, in normal
' operation, a ResultView's ListItems are destroyed when a new
' ResultView is activated. ResultViews are not cached by default.
' =============================================================================
'
Private Sub ResultViews_Initialize(ByVal ResultView As SnapInLib.IResultView)
On Error GoTo ErrTrap_ResultViews_Initialize
Dim DriveName As String
Dim DriveNames() As String
Dim drv As Scripting.Drive
Dim fs As New Scripting.FileSystemObject
Dim i As Integer
' If this is a <Stats> node under a FileExplorer drive we stored the drive name as the
' scope item's tag. If it is a <Stats> node under FileExplorer's "My Computer" node
' then the scope item's tag contains the array of drive names that FileExplorer is
' displaying. Check for the first ready drive in the array and get its name.
With ResultView.ScopePaneItem.ScopeItem
If ResultView.ScopePaneItem.ScopeItem.Name = "MyComputerStats" Then
DriveNames = .Tag
For i = LBound(DriveNames) To UBound(DriveNames)
Set drv = fs.GetDrive(DriveNames(i))
If drv.IsReady Then
DriveName = DriveNames(i)
Exit For
End If
Next i
Else
DriveName = .Tag
End If
End With
' Populate the listview with the drive's statistics. Note that it doesn't matter
' which node is displaying the result view because both a list view and a listpad
' use ResultView.ListView to add their list items.
DisplayDriveStats DriveName, ResultView.ListView.ListItems
' Store the index of the drive being displayed in ResultView.Tag. This allows the
' listpad button click handler to set the initial selection in its listbox to
' to the currently selected drive.
ResultView.Tag = i
Exit Sub
' Error Handler for this method
ErrTrap_ResultViews_Initialize:
DisplayError "ResultViews_Initialize"
End Sub
' =============================================================================
' Method: DisplayDriveStats
' Type: Subroutine
' Description: Populates the list items with the drive's statistics
' Parameters: DriveBane Name of drive to show
' ListItems MMCListItems collection to populate
'
' Output: None
' Notes: None
' =============================================================================
'
Private Sub DisplayDriveStats(DriveName As String, ListItems As MMCListItems)
On Error GoTo ErrTrap_DispayDriveStats
Dim drv As Scripting.Drive
Dim fs As New Scripting.FileSystemObject
' Get the drive name and get a FileSystemObject Drive object so we can
' populate the listview with its properties.
Set drv = fs.GetDrive(DriveName)
' Add each of the fields from the Drive object to the list items
AddField ListItems, "DriveLetter", drv.DriveLetter
AddField ListItems, "AvailableSpace", Format(drv.AvailableSpace, "#,##0 bytes")
AddField ListItems, "DriveType", FormatDriveType(drv.DriveType)
AddField ListItems, "FileSystem", drv.FileSystem
AddField ListItems, "FreeSpace", Format(drv.FreeSpace, "#,##0 bytes")
AddField ListItems, "IsReady", drv.IsReady
AddField ListItems, "Path", drv.Path
AddField ListItems, "SerialNumber", Hex$(drv.SerialNumber)
AddField ListItems, "ShareName", drv.ShareName
AddField ListItems, "TotalSize", Format(drv.TotalSize, "#,##0 bytes")
AddField ListItems, "VolumeName", drv.VolumeName
Exit Sub
' Error Handler for this method
ErrTrap_DispayDriveStats:
DisplayError "DispayDriveStats"
End Sub
' =============================================================================
' Method: AddField
' Type: Subroutine
' Description: Adds a list item and its corresponding list subitems.
' Parameters: ListItems The MMCListItems collection being populated.
' Name Name of the Drive object field
' Value Value of the field
' Output: None
' Notes: None
' =============================================================================
'
Private Sub AddField(ListItems As MMCListItems, Name As String, Value As String)
On Error GoTo ErrTrap_AddField
Dim ListItem As MMCListItem
Set ListItem = ListItems.Add(, Name, Name)
ListItem.ListSubItems.Add 1, "Stat", Name
ListItem.ListSubItems.Add 2, "Value", Value
Exit Sub
' Error Handler for this method
ErrTrap_AddField:
DisplayError "AddField"
End Sub
' =============================================================================
' Method: FormatDriveType
' Type: Function
' Description: Returns a string describing the type of drive.
' Parameters: DriveType A Scripting library enumeration describing the
' drive type.
' Output: None
' Notes: None
' =============================================================================
'
Private Function FormatDriveType(DriveType As Scripting.DriveTypeConst) As String
On Error GoTo ErrTrap_FormatDriveType
Select Case DriveType
Case CDRom
FormatDriveType = "CD ROM"
Case Fixed
FormatDriveType = "Fixed"
Case RamDisk
FormatDriveType = "Ram Disk"
Case Remote
FormatDriveType = "Remote"
Case Removable
FormatDriveType = "Removable"
Case Unknown
FormatDriveType = "Unknown"
End Select
Exit Function
' Error Handler for this method
ErrTrap_FormatDriveType:
DisplayError "FormatDriveType"
End Function
' =============================================================================
' Method: DisplayError
' Type: Subroutine
' Description: A method to format and display a runtime error
' Parameters: szLocation A string identifying the source location
' (i.e. method name) where the error occurred
' Output: None
' Notes: The error will be displayed in a messagebox, with a format of
'
' Method: SomeMethodName
' Source: MMCListSubItems
' Error: 2527h (9511)
' Description: There is already an item in the collection that has the specified key
'
' =============================================================================
'
Private Sub DisplayError(szLocation As String)
ConsoleMsgBox "Method:" & vbTab & vbTab & szLocation & vbCrLf _
& "Source:" & vbTab & vbTab & Err.Source & vbCrLf _
& "Error:" & vbTab & vbTab & Hex(Err.Number) & "h (" & CStr(Err.Number) & ")" & vbCrLf _
& "Description:" & vbTab & Err.Description, _
vbCritical, "DriveStats Extension Runtime Error"
End Sub
Private Sub Views_AddTaskMenuItems(ByVal View As SnapInLib.View, _
ByVal Selection As SnapInLib.MMCClipboard, _
ByVal ContextMenu As SnapInLib.ContextMenu, _
InsertionAllowed As Boolean)
On Error GoTo ErrTrap_Views_AddTaskMenuItems
Dim DriveNames() As String
Dim MenuItem As MMCMenu
Dim i As Integer
' If this is not a single scope item then nothing to do
If Selection.SelectionType <> siSingleScopeItem Then
Exit Sub
End If
' If it is not the "<Stats>" node we added under FileExplorer's "My Computer" node
' then nothing to do
If Selection.ScopeItems(1).Name <> "MyComputerStats" Then
Exit Sub
End If
' Get the drive names array we stored in our MyComputerStats ScopeItem's
' Tag during ExtensionSnapIn_Expand.
DriveNames = ScopeItems("MyComputerStats").Tag
' Clear out the children of mnuChooseTask and then add new ones for each drive
mnuChooseTask.Children.Clear
' When adding the drives set Key to the drive name and set Tag to its index within
' the DriveNames array as we will need those if a drive is selected
For i = LBound(DriveNames) To UBound(DriveNames)
Set MenuItem = mnuChooseTask.Children.Add
MenuItem.Caption = DriveNames(i)
MenuItem.Key = DriveNames(i)
MenuItem.Tag = i
Next i
ContextMenu.AddMenu mnuChooseDrive
Exit Sub
' Error Handler for this method
ErrTrap_Views_AddTaskMenuItems:
DisplayError "Views_AddTaskMenuItems"
End Sub
Private Sub mnuChooseTask_Click(ByVal Index As Long, _
ByVal Selection As SnapInLib.MMCClipboard)
On Error GoTo ErrTrap_mnuChooseTask_Click
' Get the drive name from the click menu object's Key and get its index in DriveNames
' from the object's Tag
With mnuChooseTask.Children(Index)
ChangeDrive .Key, .Tag
End With
Exit Sub
' Error Handler for this method
ErrTrap_mnuChooseTask_Click:
DisplayError "mnuChooseTask_Click"
End Sub