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