How can I get the ImageID from a TreeGadget item?

Just starting out? Need help? Post your questions and find answers here.
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

How can I get the ImageID from a TreeGadget item?

Post 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?
Last edited by IceSoft on Tue Aug 16, 2011 11:55 am, edited 1 time in total.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

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

Post 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
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

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

Post 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...
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

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

Post 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.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
criobot
User
User
Posts: 10
Joined: Sat Dec 27, 2008 9:42 pm
Location: Bulgaria
Contact:

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

Post 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

Post Reply