Custom color in TreeGadget

Just starting out? Need help? Post your questions and find answers here.
Searhin
User
User
Posts: 41
Joined: Mon May 26, 2003 10:53 am
Location: Germany

Custom color in TreeGadget

Post by Searhin »

Hi there,

aren't the following messages supposed to change the color in TreeGadgets?

SendMessage_(GadgetID(tree),#LVM_SETBKCOLOR,0,color)
SendMessage_(GadgetID(tree),#LVM_SETTEXTCOLOR,0,color)

This was shown in several posts in this forums some time ago and it seemed to work... Now, in my codes this doesn't work at all :?

BTW: constants like #TVM_SETBKCOLOR for TreeViews don't exist (according to the Win32 help)

Could somebody comment on this issue??
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Searhin,

If the following code does not work ... then you have a bug somewhere.

Code: Select all

#CDDS_ITEM = $10000 
#CDDS_PREPAINT = $1 
#CDDS_ITEMPREPAINT = #CDDS_ITEM | #CDDS_PREPAINT 
#CDRF_DODEFAULT = $0 
#CDRF_NOTIFYITEMDRAW = $20 

Enumeration
  #Window_Main
  #Gadget_ListIcon
EndEnumeration

#ListIconTextColor1 = $400000
#ListIconBackgroundColor1 = $C0FFFF
#ListIconTextColor2 = $C0FFFF
#ListIconBackgroundColor2 = $400000

Global hListIconGadget

Procedure MyWindowCallback(Handle, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_NOTIFY
      *LVCDHeader.NMLVCUSTOMDRAW = lParam
      If *LVCDHeader\nmcd\hdr\hWndFrom = hListIconGadget And *LVCDHeader\nmcd\hdr\code = #NM_CUSTOMDRAW
          Select *LVCDHeader\nmcd\dwDrawStage
            Case #CDDS_PREPAINT
              ProcedureReturn #CDRF_NOTIFYITEMDRAW
            Case #CDDS_ITEMPREPAINT
              Row.l = *LVCDHeader\nmcd\dwItemSpec
              If (Row / 2) * 2 = Row
                  *LVCDHeader\clrText = #ListIconTextColor1
                  *LVCDHeader\clrTextBk = #ListIconBackgroundColor1
                Else
                  *LVCDHeader\clrText = #ListIconTextColor2
                  *LVCDHeader\clrTextBk = #ListIconBackgroundColor2
              EndIf
              ProcedureReturn #CDRF_DODEFAULT
          EndSelect
      EndIf
  EndSelect
  ProcedureReturn Result
EndProcedure

;
; Main starts here
;
  Quit = #FALSE
  WindowXSize = 320
  WindowYSize = 240
  If OpenWindow(#Window_Main, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      If CreateGadgetList(WindowID())
          hListIconGadget = ListIconGadget(#Gadget_ListIcon, 10, 10, WindowXSize - 20, WindowYSize - 20, "Col1", 120, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
          AddGadgetColumn(#Gadget_ListIcon, 1, "Col2", 120)
          AddGadgetColumn(#Gadget_ListIcon, 1, "Col2", 120)
      EndIf
      SetWindowCallback(@MyWindowCallBack())
      For i = 0 To 10
        Text.s = ""
        For j = 0 To 3
          For k = 3 To Random(8)
            Text = Text + Chr(Random(26) + 65)
          Next
          Text = Text + Chr(10)
        Next
        AddGadgetItem(#Gadget_ListIcon, -1, Text)
        While WindowEvent()
        Wend
      Next
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Quit = #TRUE
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
          Case #PB_EventGadget
            Select EventGadgetID()
            EndSelect
          Case #WM_LBUTTONDOWN
            ReleaseCapture_()
            SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
          Default
        EndSelect
      Until Quit
  EndIf
End
Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Searhin
User
User
Posts: 41
Joined: Mon May 26, 2003 10:53 am
Location: Germany

Post by Searhin »

fweil,

your code works fine, but i need to set the colors for TreeGadgets..
(i used the LVM constants for a tree as I saw this on the forum some time ago)

but thank you anyway!
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Well,

This one should help :

Code: Select all

#Window_Main = 0
#Gadget_Explorer = 0
#Gadget_TreeGadget = 1

#TVM_INSERTITEMA = #TV_FIRST + 0
#TVM_INSERTITEMW = #TV_FIRST + 50
#TVM_DELETEITEM = #TV_FIRST + 1
#TVM_EXPAND = #TV_FIRST + 2
#TVM_GETITEMRECT = #TV_FIRST + 4
#TVM_GETCOUNT = #TV_FIRST + 5
#TVM_GETINDENT = #TV_FIRST + 6
#TVM_SETINDENT = #TV_FIRST + 7
#TVM_GETIMAGELIST = #TV_FIRST + 8
#TVM_SETIMAGELIST = #TV_FIRST + 9
#TVM_GETNEXTITEM = #TV_FIRST + 10
#TVM_SELECTITEM = #TV_FIRST + 11
#TVM_GETITEMA = #TV_FIRST + 12
#TVM_GETITEMW = #TV_FIRST + 62
#TVM_SETITEMA = #TV_FIRST + 13
#TVM_SETITEMW = #TV_FIRST + 63
#TVM_EDITLABELA = #TV_FIRST + 14
#TVM_EDITLABELW = #TV_FIRST + 65
#TVM_GETEDITCONTROL = #TV_FIRST + 15
#TVM_GETVISIBLECOUNT = #TV_FIRST + 16
#TVM_HITTEST = #TV_FIRST + 17
#TVM_CREATEDRAGIMAGE = #TV_FIRST + 18
#TVM_SORTCHILDREN = #TV_FIRST + 19
#TVM_ENSUREVISIBLE = #TV_FIRST + 20
#TVM_SORTCHILDRENCB = #TV_FIRST + 21
#TVM_ENDEDITLABELNOW = #TV_FIRST + 22
#TVM_GETISEARCHSTRINGA = #TV_FIRST + 23
#TVM_GETISEARCHSTRINGW = #TV_FIRST + 64
#TVM_SETTOOLTIPS = #TV_FIRST + 24
#TVM_GETTOOLTIPS = #TV_FIRST + 25
#TVM_SETINSERTMARK = #TV_FIRST + 26
#TVM_SETUNICODEFORMAT = #CCM_SETUNICODEFORMAT
#TVM_GETUNICODEFORMAT = #CCM_GETUNICODEFORMAT
#TVM_SETITEMHEIGHT = #TV_FIRST + 27
#TVM_GETITEMHEIGHT = #TV_FIRST + 28
#TVM_SETBKCOLOR = #TV_FIRST + 29
#TVM_SETTEXTCOLOR = #TV_FIRST + 30
#TVM_GETBKCOLOR = #TV_FIRST + 31
#TVM_GETTEXTCOLOR = #TV_FIRST + 32
#TVM_SETSCROLLTIME = #TV_FIRST + 33
#TVM_GETSCROLLTIME = #TV_FIRST + 34
#TVM_SETINSERTMARKCOLOR = #TV_FIRST + 37
#TVM_GETINSERTMARKCOLOR = #TV_FIRST + 38
#TVM_GETITEMSTATE = #TV_FIRST + 39
#TVM_SETLINECOLOR = #TV_FIRST + 40
#TVM_GETLINECOLOR = #TV_FIRST + 41
#TVM_MAPACCIDTOHTREEITEM = #TV_FIRST + 42
#TVM_MAPHTREEITEMTOACCID = #TV_FIRST + 43

;
;
;
  WindowXSize = 800
  WindowYSize = 480
  Quit = #FALSE
  If OpenWindow(0,0,0,WindowXSize,WindowYSize,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ExplorerTreeGadget") And CreateGadgetList(WindowID(0))
      AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      ExplorerTreeGadget(#Gadget_Explorer, 10, 10, (WindowXSize - 10) / 2, WindowYSize - 20, "*.*")
      ImageList = ImageList_Duplicate_(SendMessage_(GadgetID(#Gadget_Explorer),#TVM_GETIMAGELIST,#TVSIL_NORMAL,0))
      SendMessage_(GadgetID(#Gadget_Explorer),#TVM_SETIMAGELIST,#TVSIL_NORMAL,ImageList)
      ImageList_SetBkColor_(ImageList,$400000)
      SendMessage_(GadgetID(#Gadget_Explorer),#TVM_SETBKCOLOR,0,$400000)
      SendMessage_(GadgetID(#Gadget_Explorer),#TVM_SETLINECOLOR,0,$C0FFFF)
      SendMessage_(GadgetID(#Gadget_Explorer),#TVM_SETTEXTCOLOR,0,$C0FFFF)
      TreeGadget(#Gadget_TreeGadget,WindowXSize / 2 + 10,10,(WindowXSize -10 ) / 2 ,WindowYSize - 20,#PB_Tree_CheckBoxes|#PB_Tree_NoLines)
      ImageList = ImageList_Duplicate_(SendMessage_(GadgetID(#Gadget_TreeGadget),#TVM_GETIMAGELIST,#TVSIL_NORMAL,0))
      SendMessage_(GadgetID(#Gadget_TreeGadget),#TVM_SETIMAGELIST,#TVSIL_NORMAL,ImageList)
      ImageList_SetBkColor_(ImageList,$400000)
      SendMessage_(GadgetID(#Gadget_TreeGadget),#TVM_SETBKCOLOR,0,$400000)
      SendMessage_(GadgetID(#Gadget_TreeGadget),#TVM_SETLINECOLOR,0,$C0FFFF)
      SendMessage_(GadgetID(#Gadget_TreeGadget),#TVM_SETTEXTCOLOR,0,$C0FFFF)
      For a=0 To 10
        AddGadgetItem (#Gadget_TreeGadget, -1, "Normal Item "+Str(a))
        AddGadgetItem (#Gadget_TreeGadget, -1, "Node "+Str(a))
        OpenTreeGadgetNode(#Gadget_TreeGadget)
        AddGadgetItem(#Gadget_TreeGadget, -1, "Sub-Item 1")
        AddGadgetItem(#Gadget_TreeGadget, -1, "Sub-Item 2")
        AddGadgetItem(#Gadget_TreeGadget, -1, "Sub-Item 3")
        AddGadgetItem(#Gadget_TreeGadget, -1, "Sub-Item 4")
        CloseTreeGadgetNode(#Gadget_TreeGadget)
        AddGadgetItem (#Gadget_TreeGadget, -1, "File "+Str(a))
      Next
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Quit = #TRUE
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
        EndSelect
      Until Quit
  EndIf
End
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

fweil,

Two very nice examples. :)

Thanks from all the 'lurkers' on this forum.

--blueb
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

...,

To all lurkers ... looking for a solution to code better ?

Purebasic can do !

And I can Purebasic, so I can do.

8)
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Searhin
User
User
Posts: 41
Joined: Mon May 26, 2003 10:53 am
Location: Germany

Post by Searhin »

Great! :D

Just what I needed. You are the man!

Still one follow-up: :wink:
what does the "ImageList_Duplicate_" mean? I did not find it in the Win32 reference.
Post Reply