Page 1 of 1

How can I get the ImageID from a TreeGadget item?

Posted: Tue Aug 16, 2011 6:17 am
by IceSoft
I added some items with an image to a TreeGadget like this:

Code: Select all

AddGadgetItem(0, -1, "text, ImageID(i), 1) 
My question is now:
How can I get the ImageID from the items again?

Re: How can I get thi ImageID from an TreeGadget item?

Posted: Tue Aug 16, 2011 6:39 am
by J. Baker
IceSoft wrote:I added some items to a TreeGadget like this:

Code: Select all

AddGadgetItem(0, -1, "text, ImageID(i), 1) 
My question is now:
How can I get the ImageID from one of the items again?
Can you not?

Code: Select all

ImageOne = ImageID(i)
AddGadgetItem(0, -1, "text, ImageOne, 1)
Debug ImageOne

Re: How can I get the ImageID from an TreeGadget item?

Posted: Tue Aug 16, 2011 6:55 am
by citystate
I don't think there is a native method of getting the ImageID - can you use something like this?

Code: Select all

AddGadgetItem(0, -1, "text", ImageID(i), 1) 
SetGadgetItemData(0,CountGadgetItems(0),ImageID(i))
though I'd be more inclined to store the image number...

Re: How can I get the ImageID from an TreeGadget item?

Posted: Tue Aug 16, 2011 7:43 am
by IceSoft
citystate wrote:I don't think there is a native method of getting the ImageID - can you use something like this?

Code: Select all

AddGadgetItem(0, -1, "text", ImageID(i), 1) 
SetGadgetItemData(0,CountGadgetItems(0),ImageID(i))
though I'd be more inclined to store the image number...
Yes this is possible. I thought also on it. And yes it works.

But a native function should be available too.

Re: How can I get the ImageID from an TreeGadget item?

Posted: Tue Aug 16, 2011 8:02 am
by criobot
You could use TreeView API to get each gadget item's icon. Sadly making this cross-platform will be much more complicated.
Example (PB 4.6):

Code: Select all

For i = 1 To 7
CreateImage(i, 16,16)

StartDrawing(ImageOutput(i))
    DrawText(4,1,Str(i))
    StopDrawing()
Next

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TreeGadget(0, 10, 10, 160, 160)
    
    CanvasGadget(1, 180, 10, 32,32, 0)
    
    AddGadgetItem (ID, -1, "Normal Item "+Str(a), ImageID(1))
    AddGadgetItem (ID, -1, "Node "+Str(a), ImageID(2))
    AddGadgetItem(ID, -1, "Sub-Item 1", ImageID(3), 1)
    AddGadgetItem(ID, -1, "Sub-Item 2", ImageID(4), 1)
    AddGadgetItem(ID, -1, "Sub-Item 3", ImageID(5), 1)
    AddGadgetItem(ID, -1, "Sub-Item 4", ImageID(6), 1)
    AddGadgetItem (ID, -1, "File "+Str(a), ImageID(7), 0)
    
    Repeat
        Event = WaitWindowEvent()    
        
        
        
        If Event = #PB_Event_Gadget
            If EventGadget() = 0 And EventType() = #PB_EventType_Change
                If GetGadgetState(0) > -1
                    DC = StartDrawing(CanvasOutput(1))
                    item.TVITEM
                    item\hItem = GadgetItemID(0, GetGadgetState(0))
                    item\mask = #TVIF_IMAGE
                    
                    SendMessage_(GadgetID(0),#TVM_GETITEMA, 0, @item)
                    
                    ;Directly draw image
                    ;ImageList_Draw_(SendMessage_(GadgetID(0), #TVM_GETIMAGELIST,#TVSIL_NORMAL,0),item\iImage, DC, 8,8, #SRCCOPY) 
                    
                    
                    Icon = ImageList_GetIcon_(SendMessage_(GadgetID(0), #TVM_GETIMAGELIST,#TVSIL_NORMAL,0), GetGadgetState(0)+1, 0)
                    DrawImage(Icon, 8, 8)
                    DeleteObject_(Icon)
                    StopDrawing()
                EndIf
            EndIf
        EndIf
        
        
    Until Event = #PB_Event_CloseWindow
EndIf