有段代码你看看: Option Explicit'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 = -2Private 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 .ColumnHeaders.Add , , "Caption" .ColumnHeaders.Add , , "Driver ver" .ColumnHeaders.Add , , "LogPixels" .ColumnHeaders.Add , , "PelsH" .ColumnHeaders.Add , , "PelsV" .ColumnHeaders.Add , , "Spec ver" .View = lvwReport .Sorted = False
End With
Command1.Caption = "Display Configuration"
End Sub Private Sub Command1_Click() ListView1.ListItems.Clear Call wmiDisplayConfiguration Call lvAutosizeControl(ListView1)
End Sub Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust As Long 'Size each column based on the maximum of 'wither the ColumnHeader text width, or, 'if the items below it are wider, the 'widest list item in the column lv.Visible = False For col2adjust = 0 To lv.ColumnHeaders.Count - 1
Option Explicit'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 = -2Private 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
.ColumnHeaders.Add , , "Caption"
.ColumnHeaders.Add , , "Driver ver"
.ColumnHeaders.Add , , "LogPixels"
.ColumnHeaders.Add , , "PelsH"
.ColumnHeaders.Add , , "PelsV"
.ColumnHeaders.Add , , "Spec ver"
.View = lvwReport
.Sorted = False
End With
Command1.Caption = "Display Configuration"
End Sub
Private Sub Command1_Click() ListView1.ListItems.Clear
Call wmiDisplayConfiguration
Call lvAutosizeControl(ListView1)
End Sub
Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust As Long 'Size each column based on the maximum of
'wither the ColumnHeader text width, or,
'if the items below it are wider, the
'widest list item in the column
lv.Visible = False
For col2adjust = 0 To lv.ColumnHeaders.Count - 1
Call SendMessage(lv.hwnd, _
LVM_SETCOLUMNWIDTH, _
col2adjust, _
ByVal LVSCW_AUTOSIZE_USEHEADER) Next
lv.Visible = True
End Sub
Private Sub wmiDisplayConfiguration() Dim dcSet As SWbemObjectSet
Dim dc As SWbemObject
Dim itmx As ListItem
Dim msg As String
Set dcSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_DisplayConfiguration")
On Local Error Resume Next
For Each dc In dcSet
Set itmx = ListView1.ListItems.Add(, , dc.Caption)
itmx.SubItems(1) = dc.DriverVersion
itmx.SubItems(2) = dc.LogPixels
itmx.SubItems(3) = dc.PelsHeight
itmx.SubItems(4) = dc.PelsWidth
itmx.SubItems(5) = dc.SpecificationVersion
Next
End Sub
InstancesOf("Win32_DisplayConfiguration")
这是个服务,如果在98或非2000系统会出错