Announcement

Collapse
No announcement yet.

LVS_EX_FULLROWSELECT question

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

  • LVS_EX_FULLROWSELECT question

    On all my listviews with LVS_EX_FULLROWSELECT the blue background goes from the left margin of the listview to the edge of the last column.

    The latest listview I programmed doesn't go to the left margin of the listview but starts at the data and then goes to the right. The column is left aligned.

    On a selected row, there is whitespace to the left of the data in column 0. There shouldn't be any.

    This listview is different in that I'm using NM_CUSTOMDRAW with it to make negative numbers in cells have a red text color.

    Puzzled,

    Bob Mechler
    Attached Files
    Last edited by BOB MECHLER; 2 Jul 2009, 03:39 PM.

  • #2
    dugno...any code snippet?

    maybe you can see something you are missing...

    Code:
    '------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------
    SUB DDTReturnValue( BYVAL hWnd AS LONG, BYVAL V AS LONG )
        SetWindowLong hWnd, %DWL_MSGRESULT, V
    END SUB
    
    '------------------------------------------------------------------------------
    ' ListView Custom Draw handler...
    '------------------------------------------------------------------------------
    FUNCTION ListViewNotify(BYVAL hWndListView AS LONG, BYVAL lParam AS LONG) AS LONG
    
        LOCAL LvCd AS NMLVCUSTOMDRAW PTR
        LOCAL DispInfo AS LV_DISPINFO  PTR
    
        LOCAL TempSt AS ASCIIZ*255
        LOCAL Row AS LONG, Col AS LONG
        LOCAL clr AS LONG, test AS LONG
        LOCAL rc AS RECT
    
        REGISTER i AS LONG
    
        DispInfo = lParam
    
        SELECT CASE @DispInfo.Hdr.code
    
            '---
            CASE %NM_CUSTOMDRAW
    
                LvCd = lParam
    
             '--PAINT
                '--Let us know if we need to repaint any items...
                IF( @LvCd.nmcd.dwDrawStage = %CDDS_PREPAINT ) THEN
                    '--let the dialog engine have the return value
                    DDTReturnValue GetParent(hWndListView), %CDRF_NOTIFYITEMDRAW
                    FUNCTION = %CDRF_NOTIFYITEMDRAW :EXIT FUNCTION
                END IF
                '--Let us know that we need to repaint a sub item...
                IF( @LvCd.nmcd.dwDrawStage =  %CDDS_ITEMPREPAINT ) THEN
                    '--let the dialog engine have the return value
                    DDTReturnValue GetParent(hWndListView),%CDRF_NOTIFYSUBITEMDRAW
                    FUNCTION = %CDRF_NOTIFYSUBITEMDRAW  :EXIT FUNCTION
                END IF
    
    
                IF( @LvCd.nmcd.dwDrawStage = ( %CDDS_SUBITEM OR %CDDS_ITEMPREPAINT ) ) THEN
    
                    row = @LvCd.nmcd.dwItemSpec  'get Row #
                    col = @LvCD.iSubItem         'get Col #
    
                    IF row > gMaxRows OR col > gMaxCols THEN
                        '--let the dialog engine have the return value
                        DDTReturnValue GetParent(hWndListView), %FALSE
                        FUNCTION = %FALSE :EXIT FUNCTION
                    END IF
    
    
                    IF Col = 0 THEN
    
                        'clr = RGB(168,168,168)
    
                        ListView_GetSubItemRect hWndListView,Row,Col,%LVIR_LABEL,VARPTR(rc)
                        InflateRect rc, 2, 0
                        OffSetRect  rc,-2,-1
                        'DrawEdge @LvCd.nmcd.hdc,rc,%EDGE_RAISED,%BF_RECT
                        DrawFrameControl @LvCd.nmcd.hdc,rc,%DFC_BUTTON,%DFCS_BUTTONPUSH
    
                        'put text on Column 0 for all rows...
                        TempSt = gMyData(Row, Col)
                        DrawText @LvCd.nmcd.hdc,TempST,-1,rc ,%DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
    
                        '--let the dialog engine have the return value
                        DDTReturnValue GetParent(hWndListView),%CDRF_SKIPDEFAULT
                        FUNCTION = %CDRF_SKIPDEFAULT :EXIT FUNCTION
    
                    ELSE
                        clr = gMyFlag(Row, Col)
                    END IF
    
                    '--THIS IS OUR BACKGROUND COLOR FOR A CELL
                    @LvCd.clrtextBk = clr
    
                    '--THIS IS OUR TEXT COLOR FOR A CELL, ALWAYS BLACK
                    @LvCd.clrtext   = RGB(0,0,0)
    
                    '--let the dialog engine have the return value
                    DDTReturnValue GetParent(hWndListView),%CDRF_NEWFONT
                    FUNCTION = %CDRF_NEWFONT or %cdrf_notifysubitemdraw   :EXIT FUNCTION
    
                END IF
    
            ' here windows is asking you to tell it what to put in the listview
            CASE %LVN_GETDISPINFO
    
                DispInfo = lParam               ' it passed the pointer to the data structure in lParam
                test = @DispInfo.item.mask      ' get the mask so we know what windows is asking for
                test = test AND %LVIF_TEXT      ' filter out everything but the text request
                IF test = 0 THEN EXIT FUNCTION  ' not text?  Bye Bye...
    
                row = @DispInfo.Item.iItem
                col = @DispInfo.Item.iSubItem
    
    
                IF row > gMaxRows OR col > gMaxCols THEN
                    '--this following line is required for DDT engine...
                    DDTReturnValue GetParent(hWndListView), %FALSE
                    FUNCTION = %FALSE : EXIT FUNCTION
                END IF
    
                '--THIS IS WHERE WE GRAB TEXT...
                TempSt = gMyData(Row, Col)
    
                'note: depends on font used, what we show...
                IF bShowAscii = %TRUE THEN  'display ascii equivalent
                    IF Col > 0 THEN         'skip memory address column
                        TempSt = CHR$(VAL(TempSt))
                    END IF
                END IF
    
                @DispInfo.Item.pszText = VARPTR(TempSt) 'put the text into the cell
    
                '--this following line is required for DDT engine...
                DDTReturnValue GetParent(hWndListView), %TRUE
                FUNCTION = %TRUE :EXIT FUNCTION
    
        END SELECT
    
    
        '--this following line is required for DDT engine...
        'DDTReturnValue GetParent(hWndListView), %CDRF_DODEFAULT
        'FUNCTION = %CDRF_DODEFAULT
    
        '--this following line is required for DDT engine...
        DDTReturnValue GetParent(hWndListView), 0
        FUNCTION = 0
     
    END FUNCTION

    Comment


    • #3
      Thanks Jules,

      I've been patching the NM_CUSTOMDRAW stuff from different sample programs and as you can see got the thing to set the negative numbers to red so I'll review your code to see what I'll missing.

      Thanks,

      Bob Mechler

      Comment


      • #4
        Probably wont help, I just noticed you had an bitmap showing the problem and I'm afraid I don't have a solution. sorry.

        ...curious to know what your settings are? ie. LV_COLUMN
        lvc.mask = %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM
        lvc.fmt = %LVCFMT_LEFT
        Last edited by Jules Marchildon; 2 Jul 2009, 04:13 PM.

        Comment


        • #5
          Here is the NM_CUSTOMDRAW section of my program.

          Code:
                       my_LpLvNm = CBLPARAM                
                       SELECT CASE @my_LpLvNm.hdr.code
                         CASE %NM_CUSTOMDRAW
                            pnm = CBLPARAM
                            SELECT CASE @pnm.nmcd.dwDrawStage
                               CASE %CDDS_PREPAINT
                                  ' The following statement ensures that the relevant messages are coming back
                                  ' to Windows, so Windows can respond appropriately. This method may be useful
                                  ' in many other situations where the DDT engine may swallow the information.
                                  ' The following statement makes Windows happy:
                                  SetWindowLong CBHNDL, %DWL_MSGRESULT, %CDRF_NOTIFYITEMDRAW
                                  ' This statement makes the DDT engine happy:
                                  FUNCTION = %CDRF_NOTIFYITEMDRAW'1
                                  EXIT FUNCTION
                               CASE %CDDS_ITEMPREPAINT
                                  SetWindowLong CBHNDL, %DWL_MSGRESULT, %CDRF_NOTIFYSUBITEMDRAW
                                  FUNCTION = %CDRF_NOTIFYSUBITEMDRAW'1
                                  EXIT FUNCTION
                               CASE %CDDS_SUBITEM OR %CDDS_ITEMPREPAINT
                                  SelectObject @pnm.nmcd.hdc, hfonttext&
                                  ListView_GetItemText hctrl&, @pnm.nmcd.dwItemSpec, @pnm.isubitem, TmpAsciiz, SIZEOF(TmpAsciiz)
                                  IF @pnm.nmcd.dwItemSpec mod 2 = 0 THEN
                                    @pnm.clrTextBk = %white 
                                  ELSE
                                    @pnm.clrTextBk = rgb(223,223,223) 
                                  END IF                            
                                  IF VAL(TRIM$(TmpAsciiz)) < 0 THEN
                                    ShowRed = @pnm.isubitem
                                  ELSE
                                    ShowRed = -1
                                  END IF                       
                                  IF @pnm.isubitem = ShowRed THEN
                                    @pnm.clrText = %red 
                                  ELSE
                                    @pnm.clrText = %black 
                                  END IF 
                                  SetWindowLong CBHNDL, %DWL_MSGRESULT, (%CDRF_NEWFONT)
                                  FUNCTION = %CDRF_NEWFONT'1
                                  EXIT FUNCTION
                            END SELECT
          Bob Mechler

          Comment


          • #6
            Found the culprit code

            I remarked out the following code and got rid of the problem. Adding the sort diamond (triangle?) to the header evidently reserves space on the left of the first column. The example code I got this snippet from did have an image in the first column but I'm not sure how this code for the header affected column 0.

            Code:
                  'create imagelist for listview
                  ghlvImagelist = ImageList_Create(16, 16, %ILC_COLORDDB OR %ILC_MASK, 0, 1)
                  'ImageList_AddIcon ghlvImagelist, LoadIcon(ghInst, BYVAL %IDI_APPLE)
                  
                  'assign imagelist to listview
                  Listview_SetImageList LVhCtl&, ghlvImagelist, %LVSIL_SMALL
                  
                  'create imagelist for header (sort) icons
                  ghInst = GetModuleHandle(BYVAL 0&)
                  ghHdrImagelist = ImageList_Create(16, 16, %ILC_COLORDDB OR %ILC_MASK, 0, 1)
                  ImageList_AddIcon ghHdrImagelist, LoadIcon(ghInst, BYVAL %IDI_DESCENDING)
                  ImageList_AddIcon ghHdrImagelist, LoadIcon(ghInst, BYVAL %IDI_ASCENDING)
                  
                  'assign imagelist to header
                  ghLvHdr = ListView_GetHeader(LVhCtl&)
                  Header_SetImageList ghLvHdr, ghHdrImagelist
            Bob Mechler

            Comment


            • #7
              Ahhh... yes, it doesnt select the Icon, if an icon was there, it would dither it instead. You added icons to the listview using ''ImageList_AddIcon ghlvImagelist, LoadIcon(ghInst, BYVAL %IDI_APPLE)" not the header. Old code snippet I think you left behind.
              Last edited by Jules Marchildon; 2 Jul 2009, 04:56 PM.

              Comment


              • #8
                Found the problem after looking at the code a little bit. I had properly remarked out the code regarding the ImageList_AddItem ghlvImagelist but didn't remark out the ListView_SetImageList LVhCtl&, ghlvImagelist,%LVSIL_SMALL.

                The sample code had an image in column 0.

                When I remarked out the line starting with ListView_SetImageList, the program worked correctly.

                Maybe my trial and error methods will help somebody else.

                Bob Mechler

                Comment


                • #9
                  I tried your suggestion and of course all the text was red and the full row select was border to border. I think the code that I remarked out from the sample code I was using got rid of the space reserved for the icon in column 0.

                  Thanks, I think it's ok now.

                  Bob Mechler

                  Comment

                  Working...
                  X