Announcement

Collapse
No announcement yet.

manifest nonsense

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • manifest nonsense

    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:
    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

  • #2
    You might try using an underline font instead of separately drawing the line..

    Here is what I use if a text item in an owner-draw listview is a "link" and I want it underlined...

    Code:
                                                 FillRect  @plvu.lvcd.nmcd.hdc, R, GetStockobject (%WHITE_BRUSH)
                                                 IF bIsLink THEN
                                                    ' this will also be a FONT thing here
                                                    hFontNormal = SendMessage (@plvu.nmhdr.hwndFrom, %WM_GETFONT,%NULL,%NULL)
    
                                                    GetObject      hFontNormal, SIZEOF(lf), lf
    [b]
                                                    lf.lfUnderline = 1
                                                    hfontLink      = CreateFontIndirect (lf)
                                                    SelectObject @plvu.lvcd.nmcd.hdc, hFontLink
    [/b]
                                                    SetTextColor  @plvu.lvcd.nmcd.hdc, %BLUE
                                                 ELSE
                                                    SetTextColor @plvu.lvcd.nmcd.hdc, %BLACK
                                                 END IF
                                                 SetBkColor    @plvu.lvcd.nmcd.hdc, %WHITE
                                                   ' add the text in the assigned area, with ellipses if necessary..
                                                   ' for puposes of indenting DrawText text to match Windows' indenting
                                                 R.nLeft = R.nLeft + 4
                                                 DrawText  @plvu.lvcd.nmcd.hdc, _
                                                          szText, _
                                                          lstrlen(szText), _
                                                          R, _
                                                          %DT_NOPREFIX OR %DT_END_ELLIPSIS
                                                 ' if this was a link, then we created a font and selected it into hDC
                                                 ' so we have to restore that.
                                                 IF bIslink THEN
    [b]
                                                     deleteObject Selectobject (@plvu.lvcd.nmcd.hdc, hFontNormal)
    [/b]
                                                 END IF
    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Michael Mattias View Post
      You might try using an underline font instead of separately drawing the line..
      Thanks! I'll try it.

      Comment

      Working...
      X