ListIconGadget - Multiline Entry

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: ListIconGadget - Multiline Entry

Post by Sparkie »

This is as thin as it gets for API induced multiline text. :wink:

Code: Select all

Enumeration
  #window_jor
  #list_jor_errors
EndEnumeration

; --> Get system brushes 
Global hiLightBrush = GetSysColorBrush_(#COLOR_HIGHLIGHT)
Global defaultBrush = GetSysColorBrush_(#COLOR_WINDOW)

Procedure myWindowCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *nmhdr.NMHEADER = lParam 
      *lvCD.NMLVCUSTOMDRAW = lParam 
      If *lvCD\nmcd\hdr\hwndFrom=GadgetID(#list_jor_errors) And *lvCD\nmcd\hdr\code = #NM_CUSTOMDRAW    
        Select *lvCD\nmcd\dwDrawStage 
          Case #CDDS_PREPAINT 
            result = #CDRF_NOTIFYITEMDRAW 
          Case #CDDS_ITEMPREPAINT 
            result = #CDRF_NOTIFYSUBITEMDRAW; 
          Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM 
            thisItem = *lvCD\nmcd\dwItemSpec 
            ; --> Define rect for text 
            subItemRect.RECT\left = #LVIR_LABEL 
            subItemRect.RECT\top = *lvCD\iSubItem 
            ; --> Get the subitem rect 
            SendMessage_(GadgetID(#list_jor_errors), #LVM_GETSUBITEMRECT, thisItem, @subItemRect) 
            subItemText$ = GetGadgetItemText(#list_jor_errors, *lvCD\nmcd\dwItemSpec, *lvCD\iSubItem) 
            sitLen = Len(subItemText$) 
            Select *lvCD\iSubItem 
              Case 0 
                ; --> Define text and background colors for column 0 and set Drawtext_() flags 
                lvFlags =  #DT_END_ELLIPSIS | #DT_WORDBREAK
                ; --> Paint over unused icon rect 
                subItemRect\left = 0 
                If GetGadgetState(#list_jor_errors) = thisItem 
                  ; --> If item is selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, hiLightBrush)
                Else 
                  ; --> If item is not selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, defaultBrush)
                EndIf 
                ; --> Text color for column 0 
                ;SetTextColor_(*lvCD\nmcd\hdc, #Green)
              Case 1 
                ; --> Define text and background colors for column 1 and set Drawtext_() flags 
                lvFlags = #DT_END_ELLIPSIS | #DT_WORDBREAK 
                If GetGadgetState(#list_jor_errors) = thisItem 
                  ; --> If item is selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, hiLightBrush)
                Else 
                  ; --> If item is not selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, defaultBrush)
                EndIf 
                ; --> Text color for column 1 
                ;SetTextColor_(*lvCD\nmcd\hdc, #Black)
            EndSelect 
            ; --> Adjust rect for text margins 
            subItemRect\left +3 
            subItemRect\right -3 
            subItemRect\bottom -3 
            ; --> Draw our text 
            DrawText_(*lvCD\nmcd\hdc, subItemText$, sitLen, subItemRect, lvFlags) 
            result = #CDRF_SKIPDEFAULT 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
If OpenWindow(#window_jor, #PB_Any, #PB_Any, 420, 240, "PW Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Invisible)
  SetWindowCallback(@myWindowCallback())
  ListIconGadget(#list_jor_errors, 5, 5, 410, 230, "Time", 60, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#list_jor_errors, 1, "Text", 340)
  
  imageList = ImageList_Create_(1, 30, #ILC_COLOR32, 0, 30)
  SendMessage_(GadgetID(#list_jor_errors), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList)
  
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  AddGadgetItem(#list_jor_errors, -1, FormatDate("%hh:%ii:%ss", Date() + 10) + Chr(10) + "String" + Chr(13) + "String")
  
  HideWindow(#window_jor, 0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        CloseWindow(#window_jor)
        Break
    EndSelect
  ForEver
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

Re: ListIconGadget - Multiline Entry

Post by Phantomas »

Sparkie wrote:No API needed for Windows 7 with XP skins Enabled.

@Phantomas: What version(s) of windows are you targeting?
I'm use WinXP, style does not affect... Windows 7 is strange.

Thank you for code!
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: ListIconGadget - Multiline Entry

Post by captain_skank »

Sorry to bump this thread.

Using the code above is there a way to show the dividing lines ( grid ) ??

Cheers
Post Reply