|
楼主 |
发表于 2023-8-21 19:29:54
|
显示全部楼层
#include <GDIPlus.au3>
#include <WinAPIEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Listview Custom Draw", 400, 300)
$ListView = GUICtrlCreateListView("Column 1|Column 2|Column 3|Column 4", 10, 50, 380, 220, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($ListView)
;创建单选框1
$Radio1 = GUICtrlCreateRadio("测试按钮", 40, 20, 85, 20)
; Add items
For $i = 1 To 30
GUICtrlCreateListViewItem("Row" & $i & ": Col 1|Row" & $i & ": Col 2|Row" & $i & ": Col 3|Row" & $i & ": Col 4", $ListView)
Next
;选中项目和焦点
_GUICtrlListView_SetItemState($ListView, 1, $LVIS_FOCUSED + $LVIS_SELECTED, $LVIS_FOCUSED + $LVIS_SELECTED)
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 ; Not in details mode
Local $tCustDraw, $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3
$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
; Not handled
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
$iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
$iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then ; Item to draw is selected
$hDC = _WinAPI_GetDC($hWndFrom)
$tRect = DllStructCreate($tagRECT)
; We draw the background when we draw the first item.
If $iSubitem = 0 Then
; We must send the message as we want to use the struct. _GUICtrlListView_GetSubItemRect returns an array.
_SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))
DllStructSetData($tRect, "Left", 2)
;===>
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWndFrom)
$hbrush = _GDIPlus_BrushCreateSolid("0xFF" & "0078D7")
_GDIPlus_GraphicsFillRect($hGraphic, DllStructGetData($tRect, 'Left'), DllStructGetData($tRect, 'Top'), _
DllStructGetData($tRect, 'Right') - DllStructGetData($tRect, 'Left'), DllStructGetData($tRect, 'Bottom') - DllStructGetData($tRect, 'Top'), $hbrush)
_GDIPlus_BrushDispose($hbrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
;===>
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) ; It uses the background drawn for the first item.
_WinAPI_SetTextColor($hDC, 0xFFFFFF)
; Select the font we want to use
_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 ; Don't do default processing
EndIf
Return $CDRF_NEWFONT ; Let the system do the drawing for non-selected items
Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)
; Not handled
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0x000000)
EndFunc ;==>RGB2BGR
;在本论坛找到了一个函数,如果没有选择默认,是可以高亮的,但是选择了默认后,当鼠标悬停在选择条目上就会遮住文字显示
|
|