For i = 0 To m_lvw.ColumnHeaders.Count SendMessage m_lvw.hWnd,LVM_SETCOLUMNWIDTH,i,LVSCW_AUTOSIZE_USEHEADER Next i
在标准模块里要写如下声明和常量:
'API声明 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,lParam As Any) As Long Public Const LVM_SETCOLUMNWIDTH = &H1000 + 30 Public Const LVSCW_AUTOSIZE_USEHEADER = -2
另外,C++中十六进制用0x打头,VB中使用&H打头。