Announcement

Collapse
No announcement yet.

multiline text in treeview

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

  • multiline text in treeview

    I've got as far as using %NM_CUSTOMDRAW under %WM_NOTIFY which gives me the control id and the NMLVCUSTOMDRAW stucture gives me - somehow - the treeview item. To get greater height for the item to display several lines of text, my guess is that a larger icon has to be specified? Am I on the right lines?

  • #2
    What happened when you tried? Did the vertical size of the supplied RECT change?

    Well, Ok. But I think the TVM_SETITEMHEIGHT message sure looks promising.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      It certainly sounds pretty good, missing from my popup Win32 help! Thanks!

      Comment


      • #4
        This is it, to set the height fo individual items, use the TVITEMEX structure:
        iIntegral
        Height of the item, in multiples of the standard item height (see TVM_SETITEMHEIGHT). For example, setting this member to 2 will give the item twice the standard height...

        Comment


        • #5
          So far, the treeviw item height adjustment is working fine as per the notes above. But nothing is displayed in the treeview control!

          Code:
                 CASE %WM_NOTIFY
                      pnmh = CBLPARAM
                      SELECT CASE @pnmh.code
                          IF LOWRD(CBWPARAM) <> %IDC_TV THEN EXIT SELECT
                          lpia=CBLPARAM
                          CASE %NM_CUSTOMDRAW
                              pnm = CBLPARAM
                              SELECT CASE @pnm.nmcd.dwDrawStage
                                  CASE %CDDS_PREPAINT
                                      FUNCTION=%CDRF_NOTIFYITEMDRAW
                                  CASE %CDDS_ITEMPREPAINT
                                      lResult=TreeView_GetItemRect(@pnm.nmcd.hdr.hwndFrom,@pnm.nmcd.dwItemSpec,rc,%TRUE)
                                      '*************** right stuff is in RECT structure!
                                      DIALOG SET TEXT CBHNDL, STR$(rc.nleft)+ "," + STR$(rc.ntop) + "," + STR$(rc.nright) + "," + STR$(rc.nbottom)
                                      IF ISTRUE(lResult) THEN
                                          szbuf = "AAAAAAAAAAAAAAAAAA" + $CRLF + "BBBBBBBBBBBBBBBBBB" + _
                                                  "CCCCCCCCCCCC," + $CRLF + "DDDDDDDDDDDDDDDDDDDDDDDD"
                                          hfont = SendMessage(CBHNDL, %WM_GETFONT, 0, 0)
                                          hfont2 = SelectObject(@pnm.nmcd.hdc, hfont)
                                          ' ***********reply from Drawtext looks correct
                                          lresult = DrawText (@pnm.nmcd.hdc, szbuf, LEN(szbuf), rc, %DT_LEFT OR %DT_WORDBREAK) '%DT_CALCRECT OR %DT_LEFT OR %DT_WORDBREAK)
                                          SelectObject @pnm.nmcd.hdc, hfont2
                                          FUNCTION=%CDRF_NOTIFYITEMDRAW
                                      ELSE
                                          FUNCTION=%CDRF_DODEFAULT
                                      END IF
                             END SELECT

          Comment


          • #6
            After you draw the item, you need to return CDRF_SKIPDEFAULT, not CDRF_NOTIFYITEMDRAW.

            Also, if this is not DDT, you are not returning the value correctly. You need either to EXIT FUNCTION after setting the return value (or the mesage will be processed by DefWindowProc) if in a 'regular' window procedure; or SetWindowLong hWnd, %DWL_MSGRESULT, %TRUE and EXIT FUNCTION if this is a dialog proc for a SDK-style dialog.

            But I 'assume' it's DDT because of the presence of a DIALOG SET TEXT statement.
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              MCM, thanks, the retval is not the problem though.

              To debug it (first time I thought of this) I used setbkcolor @pnm.nmcd.hdc, %CYAN so as to see where the RECT was located. That showed that the RECT was rather narrow. Calling DrawText with %DT_CALCRECT added in recalculated the RECT and the job is, in essence, done. I also focussed on the "correct" TV item by testing the iimage value, which dramatically reduced the confusion.

              Now all I have to fix is some cosmetics and this appalling sense of smugness..

              Code:
                     CASE %WM_NOTIFY
                          pnmh = CBLPARAM
                          SELECT CASE @pnmh.code
                              IF LOWRD(CBWPARAM) <> %IDC_arc_tv THEN EXIT SELECT
                              lpia=CBLPARAM
                              CASE %NM_CUSTOMDRAW
                                  pnm = CBLPARAM
                                  SELECT CASE @pnm.nmcd.dwDrawStage
                                      CASE %CDDS_PREPAINT
                                          FUNCTION=%CDRF_NOTIFYITEMDRAW
                                      CASE %CDDS_ITEMPREPAINT
                                          lResult=TreeView_GetItemRect(@pnm.nmcd.hdr.hwndFrom,@pnm.nmcd.dwItemSpec,rc,%true)
                                          tvi.mask = %TVIF_IMAGE OR %TVIF_HANDLE
                                          tvi.hitem = @pnm.nmcd.dwItemSpec
                                          Treeview_getItem(@pnm.nmcd.hdr.hwndFrom, BYVAL VARPTR(tvi))
                                          IF tvi.iimage <> %ico_dog THEN
                                              FUNCTION=%CDRF_DODEFAULT
                                              EXIT SELECT
                                          END IF
                                          IF ISTRUE(lResult) THEN
                                              szbuf = "AAAAAAAAA AAAAAAAAA " + $CRLF + "BBB BBBBBBBB BBBBBBB" + _
                                                      "CCCCCC CCCCCC," + $CRLF + "DDD DDDDDDDDD DDDDDD DDDDDD"
                                              hfont = SendMessage(CBHNDL, %WM_GETFONT, 0, 0)
                                              hfont2 = SelectObject(@pnm.nmcd.hdc, hfont)
                                              settextcolor @pnm.nmcd.hdc, %BLACK
                                              setbkcolor @pnm.nmcd.hdc, %CYAN
                                              lresult = DrawText (@pnm.nmcd.hdc, BYVAL VARPTR(szbuf), LEN(szbuf), BYVAL VARPTR(rc), _
                                                                  %DT_LEFT OR %DT_WORDBREAK OR %DT_CALCRECT)
                                              lresult = DrawText (@pnm.nmcd.hdc, BYVAL VARPTR(szbuf), LEN(szbuf), BYVAL VARPTR(rc), _
                                                                  %DT_LEFT OR %DT_WORDBREAK)
                                              SelectObject @pnm.nmcd.hdc, hfont2
                                              FUNCTION=%CDRF_NOTIFYITEMDRAW
                                          ELSE
                                              FUNCTION=%CDRF_DODEFAULT
                                          END IF
                                 END SELECT
                         END SELECT

              Comment

              Working...
              X