Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/* Below used for listview column auto-resizing
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Private Const LVSCW_AUTOSIZE As Long = -1
Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Form_Load()
With ListView1
.ListItems.Clear
.ColumnHeaders.Clear
.View = lvwReport
.Sorted = False
End With
Command1.Caption = "Desktop Info"
End Sub
Private Sub Command1_Click()
ListView1.ListItems.Clear
Call wmiDesktopInfo
Call lvAutosizeControl(ListView1)
End Sub
Private Sub lvAutosizeControl(lv As ListView)
Dim col2adjust As Long
'Size each column based on the maximum of
'either the columnheader text width, or,
'if the items below it are wider, the
'widest list item in the column
For col2adjust = 0 To lv.ColumnHeaders.Count - 1
Call SendMessage(lv.hwnd, _
LVM_SETCOLUMNWIDTH, _
col2adjust, _
ByVal LVSCW_AUTOSIZE_USEHEADER)
Next
End Sub
Private Sub wmiDesktopInfo()
Dim DesktopSet As SWbemObjectSet
Dim desktop As SWbemObject
Dim thiscol As Long
'add a first column, and set lv initial parameters
With ListView1
.ListItems.Clear
.View = lvwReport
.Sorted = False
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "WMI Property"
'add class properties to column 1
.ListItems.Add , , "BorderWidth"
.ListItems.Add , , "CoolSwitch"
.ListItems.Add , , "CursorBlinkRate"
.ListItems.Add , , "DragFullWindows"
.ListItems.Add , , "GridGranularity"
.ListItems.Add , , "IconSpacing"
.ListItems.Add , , "IconTitleFaceName"
.ListItems.Add , , "IconTitleSize"
.ListItems.Add , , "IconTitleWrap"
.ListItems.Add , , "Pattern"
.ListItems.Add , , "ScrSaveActive"
.ListItems.Add , , "ScrSaveExecutable"
.ListItems.Add , , "ScrSaveSecure"
.ListItems.Add , , "ScrSaveTimeout"
.ListItems.Add , , "Wallpaper"
.ListItems.Add , , "WallpaperStretched"
.ListItems.Add , , "WallpaperTiled"
End With
Set DesktopSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_Desktop")
For Each desktop In DesktopSet
With ListView1
.ColumnHeaders.Add , , desktop.Name
thiscol = (.ColumnHeaders.Count - 1)
.ListItems(1).SubItems(thiscol) = desktop.BorderWidth
.ListItems(2).SubItems(thiscol) = desktop.CoolSwitch
.ListItems(3).SubItems(thiscol) = desktop.CursorBlinkRate
.ListItems(4).SubItems(thiscol) = desktop.DragFullWindows
.ListItems(5).SubItems(thiscol) = desktop.GridGranularity
.ListItems(6).SubItems(thiscol) = desktop.IconSpacing
.ListItems(7).SubItems(thiscol) = desktop.IconTitleFaceName
.ListItems(8).SubItems(thiscol) = desktop.IconTitleSize
.ListItems(9).SubItems(thiscol) = desktop.IconTitleWrap
.ListItems(10).SubItems(thiscol) = desktop.Pattern
.ListItems(11).SubItems(thiscol) = desktop.ScreenSaverActive
.ListItems(12).SubItems(thiscol) = desktop.ScreenSaverExecutable
.ListItems(13).SubItems(thiscol) = desktop.ScreenSaverSecure
.ListItems(14).SubItems(thiscol) = desktop.ScreenSaverTimeout
.ListItems(15).SubItems(thiscol) = desktop.Wallpaper
.ListItems(16).SubItems(thiscol) = desktop.WallpaperStretched
.ListItems(17).SubItems(thiscol) = desktop.WallpaperTiled
End With
Next
End Sub |