|
楼主 |
发表于 2023-9-13 10:45:41
|
显示全部楼层
本帖最后由 h111666b 于 2023-9-13 10:53 编辑
感谢回复,但是还是没达到要求,当点击了列表以外按钮焦点高亮消失,而原先的是不会失去高亮显示的
使用_GUICtrlListView_SetItemDropHilited($cListView, 3, True) 此项可以保持高亮,现在有个问题就是,当点击其它项目后怎么取消已经选中的高亮项目3
代码如下
lude <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, 150, -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)
;设置选中项目高亮显示
_GUICtrlListView_SetItemDropHilited($cListView, 3, True)
$Button1 = GUICtrlCreateButton("测试按钮", 100, 154, 60, 27)
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, 0x0078D7)
_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
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|