listview选中样式问题
点击listview的某一行的时候,这一行会变为蓝色背景,如何不改变背景而用虚线框代替呢?或者什么都不改变? 直接发给你, P版关于的ListView多样式的码.我只看过一回, 但印象很深. 里面肯定有达到你要求的方法...
最好自己也搜下去看看原帖...#include <WinAPI.au3>
#include <GUIButton.au3>
#include <GUIListView.au3>
#include <GUIImageList.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("Test", 400, 300)
$sColumn = "Test|of|Mutiple Controls"
$iStyle = bitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER)
$iExStyle = bitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE)
$iListView = GUICtrlCreateListView($sColumn, 5, 5, 390, 290, $iStyle, $iExStyle)
$hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetColumnWidth($hListView, 0, 120)
_GUICtrlListView_SetColumnWidth($hListView, 1, 165)
_GUICtrlListView_SetColumnWidth($hListView, 2, 105)
$hCall = DllCallbackRegister("_ListViewProc", "int", "hWnd;uint;wparam;lparam")
$pCall = DllCallbackGetPtr($hCall)
$hOldC = _WinAPI_SetWindowLong($hListView, -4, $pCall)
GUICtrlCreateIcon("Shell32.dll", 3, 0, 20, 16, 16)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateLabel(" HKLM\Software\Microsoft\...", 16, 20, 390, 16)
GUICtrlSetFont(-1, 10, 800, "", "Garamond")
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
$hImage = _GUIImageList_Create(14, 14, 5, 3)
For $i = 1 to 7
_GUIImageList_AddIcon($hImage, "Shell32.dll", 130)
Next
GUICtrlCreateCheckBox(" ctfmon.exe", 0, 38, 120, 16)
_GUICtrlButton_SetImageList(-1, $hImage)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateInput("Microsoft Corporation", 120, 39, 160, 16, 0, 4)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateCheckBox(" AutoIt3.exe", 0, 55, 120, 16)
_GUICtrlButton_SetImageList(-1, $hImage)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateInput(" N/A", 285, 55, 25, 16, 0, 4)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateIcon("Shell32.dll", 21, 0, 72, 16, 16)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateLabel(" HKLM\Software\Microsoft\...", 16, 72, 390, 16)
GUICtrlSetFont(-1, 10, 800, "", "Garamond")
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
$hImage = _GUIImageList_Create(14, 14, 5, 3)
For $i = 1 to 7
_GUIImageList_AddIcon($hImage, "Shell32.dll", 131)
Next
GUICtrlCreateRadio(" KavPFW", 0, 90, 120, 16)
_GUICtrlButton_SetImageList(-1, $hImage)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateRadio(" lsass.exe", 122, 90, 120, 16)
_GUICtrlButton_SetImageList(-1, $hImage)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateRadio(" csrss.exe", 287, 90, 120, 16)
_GUICtrlButton_SetImageList(-1, $hImage)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUICtrlCreateInput("Input some text here.", 3, 108, 380, 16)
_WinAPI_SetParent(GUICtrlGetHandle(-1), $hListView)
GUISetState()
Do
Until guiGetMsg() = -3
Func _ListViewProc($hWnd, $iMsg, $wparam, $lparam)
If $iMsg = $WM_NOTIFY Then Return 1
Return _WinAPI_CallWindowProc($hOldC, $hWnd, $iMsg, $wparam, $lparam)
EndFunc ;==>_ListViewProc #include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIex.au3>
#include <StructureConstants.au3>
#include <GDIPlus.au3>
$GUI = GUICreate("Listview Custom Draw", 400, 300)
$cListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)
For $i = 1 To 30
GUICtrlCreateListViewItem("Row" & $i & ": Col 1|Row" & $i & ": Col 2|Row" & $i & ": Col 3", $cListView)
Next
;~ GUICtrlCreateInput("Click here to test focus", 50, 275, 200, 18)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_CUSTOMDRAW
If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
Local $tCustDraw, $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $Color, $Fram
$tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
$iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
Switch $iDrawStage
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
Return $CDRF_NOTIFYSUBITEMDRAW
Case $CDDS_ITEMPOSTPAINT
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
$iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
$iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then
$hDC = _WinAPI_GetDC($hWndFrom)
$tRect = DllStructCreate($tagRECT)
If $iSubitem = 0 Then
_SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))
DllStructSetData($tRect, "Left", 2)
$Color = _WinAPI_GetStockObject($DC_BRUSH)
$Fram = _WinAPI_GetStockObject($BLACK_BRUSH)
_WinAPI_SetDCBrushColor($hDC, 0xFFFFFF)
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $Color)
_WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $Fram)
EndIf
DllStructSetData($tRect, "Left", 2)
DllStructSetData($tRect, "Top", $iSubitem)
_SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))
Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_SelectObject($hDC, _SendMessage($hWndFrom, $WM_GETFONT))
If $iSubitem = 0 Then
DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 2)
Else
DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 6)
EndIf
_WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_VCENTER, $DT_END_ELLIPSIS, $DT_SINGLELINE))
_WinAPI_ReleaseDC($hWndFrom, $hDC)
Return $CDRF_SKIPDEFAULT
EndIf
Return $CDRF_NEWFONT
Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY 回复 2# user3000
P版这个原文的地址是什么来,我也看过,忘记标题名字了。 一定要搞懂三英里的帖子
页:
[1]