自动调整 ListView 栏位宽度
2012-06-29 15:49
211 查看
'添加 Command1和ListView1 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Const GW_HWNDNEXT = 2 Const LVM_FIRST As Long = &H1000 Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30) Const LVSCW_AUTOSIZE_USEHEADER As Long = -2 Private Sub Form_Load() With ListView1 .ListItems.Clear .ColumnHeaders.Clear .ColumnHeaders.Add , , "名称" .ColumnHeaders.Add , , "进程ID" .ColumnHeaders.Add , , "句 柄" .View = lvwReport End With End Sub Private Sub lvAutosizeControl(lv As ListView) Dim col2adjust& For col2adjust = 0 To lv.ColumnHeaders.Count - 1 Call SendMessage(lv.hwnd, LVM_SETCOLUMNWIDTH, col2adjust, ByVal LVSCW_AUTOSIZE_USEHEADER) Next End Sub Private Sub Command1_Click() strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process") i = 1 For Each objProcess In colProcesses Set itm = ListView1.ListItems.Add(1, "Row" & CStr(i), objProcess.Name) itm.SubItems(1) = CStr(objProcess.processid) itm.SubItems(2) = CStr(InstanceToWnd(objProcess.processid)) i = i + 1 Next Call lvAutosizeControl(ListView1) '把这行拿掉就可以看出Autosize是否生效 End Sub Function InstanceToWnd(ByVal target_pid As Long) As Long Dim test_hwnd&, test_pid&, test_thread_id& test_hwnd = FindWindow(ByVal 0&, ByVal 0&) Do While test_hwnd <> 0 If GetParent(test_hwnd) = 0 Then test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then InstanceToWnd = test_hwnd Exit Do End If End If test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT) Loop End Function
相关文章推荐
- ListView控件演示02:如何自动调整列宽度
- 自动调整listview标题头宽度的二种方法
- 自动调整listview标题头宽度的二种方法
- c# listView中列宽随列中的内容自动调整
- delphi自动调整combobox下拉列表宽度(PostMessage CB_SETDROPPEDWIDTH)
- Vi||Vim显示行号,自动缩进,调整tab键宽度技巧
- Delphi实现DBGrid列宽度自动调整
- delphi自动调整combobox下拉列表宽度
- Delphi中实现DBGrid列宽度自动调整
- CSS实现块宽度随浏览器大小自动调整&获取随机颜色(前端面试题)
- listview根据列名自动调整列宽教程
- C# ListView控件的间隔色和自动适应宽度
- ComboBox 自动调整组合框下拉部分的宽度
- 为ListView添加自动列宽调整和点击列表头自动排序功能
- CListCtrl根据列标题或者列的内容自动调整列宽度
- 网页宽度自动调整
- Axure实现Toast效果——使用动态面板实现自动调整宽度的效果
- jtable 根据内容自动调整表格宽度
- 自动调整datagrid列宽(根据行、列长度比较自动调整宽度)
- 根据表格内容,自动调整VB.NET中Datagrid控件单元格宽度