Code : Tout sélectionner
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <File.au3>
#include <Array.au3>
#include <SliderConstants.au3>
#include <ListviewConstants.au3>
#include <ScreenCapture.au3>
#include <GuiTreeView.au3>
#include <FTPEx.au3>
#include <String.au3>
#include <Date.au3>
#include <ArrayEx.au3>
#include <EditConstants.au3>
;Opt( "MustDeclareVars", 1 )
Global $hGui, $hLV, $hLVfont, $hLVfontBold, $aColors[1][1], $hListView2, $sString
MainFunc()
Func MainFunc()
$hGui = GUICreate("ListView with a few colored and bold cells", 549, 310, 400, 200)
; Create ListView control
Local $idLV = GUICtrlCreateListView("", 10, 10, 529, 290, $GUI_SS_DEFAULT_LISTVIEW, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT))
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$hLV = ControlGetHandle($hGui, "", $idLV)
_GUICtrlListView_AddColumn($hLV, "Column 0")
local $File = FileRead("test.1")
Local $aString = _StringToArray2D($File, @CRLF, ";", 1)
ReDim $aColors[UBound($aString) - 1]
For $i = 0 To UBound($aString) - 1
Local $sString = ""
For $j = 0 To UBound($aString, 2) - 1
$sString &= " " & $aString[$i][$j]
Next
$sString = StringRegExpReplace($sString, "'", "" )
If StringInStr($sString, "NIO") Or StringInStr($sString, "nicht auswertbar") Then
$aColors[$i] = ColorConvert(0xFF0000)
EndIf
_GUICtrlListView_AddItem($hLV, $sString)
Next
Local $hDC = _WinAPI_GetDC($hLV)
Local $hFont = _SendMessage($hLV, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $lvLOGFONT = DllStructCreate($tagLOGFONT)
Local $aRet = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($lvLOGFONT), 'ptr', DllStructGetPtr($lvLOGFONT))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hLV, $hDC)
$hLVfont = _WinAPI_CreateFontIndirect( $lvLOGFONT )
Local $iWeight = BitOR( DllStructGetData( $lvLOGFONT, "Weight" ), $FW_BOLD )
DllStructSetData( $lvLOGFONT, "Weight", $iWeight )
$hLVfontBold = _WinAPI_CreateFontIndirect( $lvLOGFONT )
_GUICtrlListView_SetColumnWidth($hLV, 0, $LVSCW_AUTOSIZE)
; Use WM_NOTIFY events to draw the cells
GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )
; Show GUI
GUISetState( @SW_SHOW, $hGui )
; Message loop
Local $iMsg
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete( $hGui )
Exit
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hLV
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT
; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
Case $CDDS_ITEMPREPAINT
; Before painting an item
Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations
Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM )
; Before painting a subitem
Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
Local $hDC = DllStructGetData($tNMLVCUSTOMDRAW, "HDC") ; Handle to the item's device context
If $aColors[$dwItemSpec] Then ;[$iSubItem]
_WinAPI_SelectObject($hDC, $hLVfontBold) ; Bold font
Else
_WinAPI_SelectObject($hDC, $hLVfont) ; Normal font
EndIF
DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", $aColors[$dwItemSpec]) ; Forecolor of item text[$iSubItem]
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
;RGB to BGR or BGR to RGB
Func ColorConvert($iColor)
Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc