Two years ago I copied code from these forums (I think it was MCM's) to create a listview which had different background colors on alternate lines and underlined the selected item. Recently I cut and pasted this code into a new application and behold, it did not work. Specifically, the subitem under the cursor vanished then re-emerged when the cursor went away.
Eventually I found that deleting the manifest which I had created for the executable solved the problem.
I was rather counting on the manifest to tart up the UI a bit, so I am still investigating.
This is the code which doesn't work properly:
Eventually I found that deleting the manifest which I had created for the executable solved the problem.
I was rather counting on the manifest to tart up the UI a bit, so I am still investigating.
This is the code which doesn't work properly:
Code:
'------------------------------------------------------------------------------ FUNCTION arcLViewCustomDraw ( BYVAL ptlvcd AS NMLVCUSTOMDRAW PTR ) AS LONG LOCAL szItem AS ASCIIZ * %MAX_PATH ' item text LOCAL trcItem AS RECT ' bounding rectangle of item/subitem LOCAL tlv_item AS LV_ITEM ' listview item information LOCAL tlb AS LOGBRUSH ' specifies information used to create background brush LOCAL hWndHdr AS DWORD ' handle of header child control LOCAL hBrush AS DWORD LOCAL hBrushOld AS DWORD LOCAL hPenOld AS DWORD LOCAL dwBackColor AS DWORD LOCAL nBkModeOld AS INTEGER LOCAL hwin AS DWORD LOCAL lresult AS LONG ' Get the item or subitem info tlv_item.mask = %LVIF_TEXT OR %LVIF_IMAGE OR %LVIF_STATE tlv_item.stateMask = %LVIS_FOCUSED OR %LVIS_SELECTED tlv_item.iItem = @ptlvcd.nmcd.dwItemSpec tlv_item.iSubItem = @ptlvcd.iSubItem tlv_item.pszText = VARPTR(szItem) tlv_item.cchTextMax = %MAX_PATH SendMessage @ptlvcd.nmcd.hdr.hwndFrom, %LVM_GETITEM, 0, BYVAL VARPTR(tlv_item) ' Get the bounding rectangle of the subitem(cell) trcItem.nLeft = %LVIR_BOUNDS trcItem.nTop = @ptlvcd.iSubItem lresult = SendMessage( @ptlvcd.nmcd.hdr.hwndFrom, %LVM_GETSUBITEMRECT, @ptlvcd.nmcd.dwItemSpec, BYVAL VARPTR(trcItem)) ' Color the background IF @ptlvcd.nmcd.dwItemSpec MOD 2 = 0 THEN dwBackColor = RGB(200,255,255) ' green background ELSE dwBackColor = %WHITE ' white background END IF tlb.lbStyle = %BS_SOLID tlb.lbColor = dwBackColor tlb.lbHatch = 0 hBrush = CreateBrushIndirect(tlb) FillRect @ptlvcd.nmcd.hdc, trcItem, hBrush DeleteObject hBrush ' Draw the text nBkModeOld = SetBkMode(@ptlvcd.nmcd.hdc, %TRANSPARENT) DrawTextEx @ptlvcd.nmcd.hdc, szItem, LEN(szItem), trcItem, %DT_SINGLELINE OR %DT_LEFT OR %DT_VCENTER OR %DT_END_ELLIPSIS, BYVAL %NULL SetBkMode @ptlvcd.nmcd.hdc, nBkModeOld ' underline the currently selected row ' i.e. the one that has been clicked! ' Note: it is drawn when the last column is painted. IF (tlv_item.STATE AND %LVIS_FOCUSED) = %LVIS_FOCUSED THEN hWndHdr = SendMessage(@ptlvcd.nmcd.hdr.hwndFrom, %LVM_GETHEADER, 0, 0) IF @ptlvcd.iSubItem = SendMessage(hWndHdr, %HDM_GETITEMCOUNT, 0, 0) - 1 THEN ' Get the bounding rectangle of the entire item(this includes all subitems) trcItem.nLeft = %LVIR_BOUNDS SendMessage @ptlvcd.nmcd.hdr.hwndFrom, %LVM_GETITEMRECT, @ptlvcd.nmcd.dwItemSpec, BYVAL VARPTR(trcItem) hPenOld = SelectObject(@ptlvcd.nmcd.hdc, CreatePen(%PS_SOLID, 4 * GetSystemMetrics(%SM_CXBORDER), &H8c08c08c0???)) ' A hollow brush is used to avoid erasing what was painted already hBrushOld = SelectObject(@ptlvcd.nmcd.hdc, GetStockObject(%NULL_BRUSH)) rectangle @ptlvcd.nmcd.hdc, trcItem.nLeft, trcItem.nbottom-1, trcItem.nRight, trcItem.nBottom SelectObject @ptlvcd.nmcd.hdc, hBrushOld DeleteObject SelectObject(@ptlvcd.nmcd.hdc, hPenOld) END IF END IF FUNCTION = %CDRF_SKIPDEFAULT END FUNCTION
Comment