|
本帖最后由 renxiaoyao 于 2010-7-26 10:46 编辑
我按照netegg大大这个帖 http://www.autoitx.com/forum.php ... ;highlight=listview 的例子,改写成了这样一个东东
head.au3Global $fListView, $fSubItemStart, $fSubItemEnd, $fSubItemBkClr
Func _GUICtrlListView_SetColumnBkClr($mListView, $mColumnStart, $mColumnEnd, $mColumnBkClr) ;传递listview,开始列,结束列,底色
$fListView = $mListView
$fSubItemStart = $mColumnStart
$fSubItemEnd = $mColumnEnd
$fSubItemBkClr = $mColumnBkClr
GUIRegisterMsg($WM_NOTIFY, "fSetColumnBkClr")
EndFunc
Func RGB2BGR($iColor) ;RGB倒置
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR()
Func fSetColumnBkClr($hWnd, $Msg, $wParam, $lParam) ;设置listview指定列底色
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $fListView
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
If $iSubItem = $fSubItemStart Then ;设置子项, 即列索引大于fSubItemStart时
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR($fSubItemBkClr)) ;设置文本背景色
ElseIf $iSubItem = $fSubItemEnd + 1 Then
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(Dec(StringMid(_GUICtrlListView_GetBkColor($fListView), 3)))) ;改回系统底色
EndIf
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
当使用时_GUICtrlListView_Create和_GUICtrlListView_AddItem、_GUICtrlListView_AddSubItem来创建控件和项目时,是可以达到效果的:
main.au3#include <GuiListView.au3>
#include "head.au3"
$hGUI = GUICreate("Test", 400, 200)
$ListTest = _GUICtrlListView_Create($hGUI, "Items|SubItems||", 10, 10, 380, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)
For $i = 1 To 10
_GUICtrlListView_AddItem($ListTest, "Item|a|b" & $i)
_GUICtrlListView_AddSubItem($ListTest, $i - 1, "SubItem" & $i, 1)
_GUICtrlListView_AddSubItem($ListTest, $i - 1, "SubItemb" & $i, 2)
Next
_GUICtrlListView_SetColumnBkClr($ListTest, 1, 1, 0xFFFF80)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
但是,当我改用GUICtrlCreateListView和GUICtrlCreateListViewItem来创建控件时,却没有效果
main2.au3#include <GuiListView.au3>
#include "head.au3"
$hGUI = GUICreate("Test2", 400, 200)
$ListTest = GUICtrlCreateListView("Items|SubItems||", 0, 10, 380, 180, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
For $i = 1 To 10
GUICtrlCreateListViewItem("Item" & $i & "|a|b", $ListTest)
Next
_GUICtrlListView_SetColumnBkClr($ListTest, 1, 1, 0xFFFF80)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
请问怎样修改能使它生效呢?
另外,哪位能解答下,为什么两种方法做出来的表,字体大小都不一样了……
谢谢!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
评分
-
查看全部评分
|