#include #include #include Global $hGui, $idListView, $hListView, $fListViewHasFocus = 0, $iImages, $aRecord[1][1] ; Rows, subitems, text lines Example() Func Example() $hGui = GUICreate( "test", 770, 220 ) $idListView = GUICtrlCreateListView( "", 10, 10, 750, 192, -1,$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES );$LVS_EX_DOUBLEBUFFER+$WS_EX_CLIENTEDGE GUICtrlSetBkColor($idListView, $GUI_BKCOLOR_LV_ALTERNATE) GUICtrlSetFont($idListView, 10, 400, 1) _GUICtrlListView_SetBkColor($idListView,$COLOR_MEDGRAY) _GUICtrlListView_SetTextColor($idListView, $CLR_BLACK) _GUICtrlListView_SetTextBkColor($idListView, $COLOR_MEDGRAY) Local $hImageList = _GUIImageList_Create( 10, 40) _GUICtrlListView_SetImageList( $idListView, $hImageList, 1 ) ; 1 = Image list with small icons, works also for large images ; Add columns to ListView _GUICtrlListView_AddColumn( $idListView, "", 0 ) ; Must not be too small _GUICtrlListView_AddColumn( $idListView, "ID", 50 ) _GUICtrlListView_AddColumn( $idListView, "DATA", 675 ) ReDim $aRecord[5][2] For $i = 1 To Ubound($aRecord)-1 $iIndex = _GUICtrlListView_AddItem( $idListView, "") _GUICtrlListView_SetItemParam( $idListView, $iIndex, $i + 1000 ) ; 1000 => See remarks for _GUICtrlListView_SetItemParam in helpfile $aRecord[$i][0] = $i Next $aRecord[1][1] = "This can be a long description over several lines. Word wrap is enabled (DT_WORDBREAK). " & _ ; Description "Lines can be divided between words or with @CRLF character combination." $aRecord[2][1] = "gCVDFFB GG RG R GRTGTRGTRGRTRGHRTE" $aRecord[3][1] = "fesfeqgq egr rtgtrrtrt grtgrttrr hhethtehtehteyh hhyh thttyh tyhtyhtyh tytrhty htyhjty htyty htryrty jryj" $aRecord[4][1] = "FGBFGBN F RTG TR GRTE HTH TEH TYEH TEYHTEYHTYHTEYHTYE H THTEY HTYHTYHTY HTYTH HTYHTYHTYHTYHTYHTH HTYHHHJ" GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc ;************************************************************************************************************************************************************ ; WM_NOTIFY message handler Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) ;************************************************************************************************************************************************************ #forceref $hWnd, $iMsg, $wParam Local Static $iLvIndex, $iArrayIdx, $iSelected, $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ), $hDC Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Local $iCode = DllStructGetData( $tNMHDR, "Code" ) $hListView = GUICtrlGetHandle( $idListView ) Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tNMLVCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Specifies the drawing stage ; Stage 1 Case $CDDS_PREPAINT ; Before the paint cycle begins $hDC = DllStructGetData( $tNMLVCustomDraw, "hDC" ) ; Device context ;_WinAPI_SetBkMode( $hDC, $TRANSPARENT ) ; Transparent background Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window before an item is painted ; Stage 2 Case $CDDS_ITEMPREPAINT ; Before an item is painted $iLvIndex = DllStructGetData( $tNMLVCustomDraw, "dwItemSpec" ) ; Item index $iArrayIdx = DllStructGetData( $tNMLVCustomDraw, "lItemlParam" ) - 1000 ; Array index $iSelected = GUICtrlSendMsg( $idListView, $LVM_GETITEMSTATE, $iLvIndex, $LVIS_SELECTED ) ; Item state Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window before a subitem is painted ; Stage 3 Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before a subitem is painted: Default painting of checkbox, image, icon Return $CDRF_NOTIFYPOSTPAINT ; Notify the parent window after a subitem is painted ; Stage 4 Case BitOR( $CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM ) ; After a subitem has been painted: Custom painting of text lines Local $iSubItem = DllStructGetData( $tNMLVCustomDraw, "iSubItem" ) ; Subitem index If Not $iSubItem Then Return $CDRF_NEWFONT ; Image painted by default code ; Subitem rectangle DllStructSetData( $tRect, "Top", $iSubItem ) DllStructSetData( $tRect, "Left", $LVIR_BOUNDS ) GUICtrlSendMsg( $idListView, $LVM_GETSUBITEMRECT, $iLvIndex, $pRect ) DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" )+5) ; Left margin DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) +3) ; Top margin _WinAPI_DrawText($hDC, $aRecord[$iArrayIdx][$iSubItem-1], $tRect, $DT_WORDBREAK) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch Case $NM_KILLFOCUS If $fListViewHasFocus Then GUICtrlSendMsg( $idListView, $LVM_REDRAWITEMS, 0, $iImages - 1 ) $fListViewHasFocus = 0 EndIf Case $NM_SETFOCUS If Not $fListViewHasFocus Then _ GUICtrlSendMsg( $idListView, $LVM_REDRAWITEMS, 0, $iImages - 1 ) $fListViewHasFocus = 2 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc