ListBox Extra Data Storage

This is a discussion on ListBox Extra Data Storage within the Windows Programming forums, part of the Platform Specific Boards category; Ok, this is sort of a different question than I already asked so I gave this it's own thread. I ...

  1. #1
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100

    ListBox Extra Data Storage

    Ok, this is sort of a different question than I already asked so I gave this it's own thread.

    I have a listbox and some code I wrote for linked list functions.

    I have been getting problems left and right with trying to use a function that accepts a pointer to a linked list and a number referring to the structure on the stack and reads a data structure in my list and gives a pointer back to the specific data structure. Nothing but problems. If I run this code in a console program it runs fine, but when I run it in my Win32 API program it crashes. If I delete the function call it doesn't crash.

    I want to try a different approach.

    So here is my question.

    When appending an item to a listbox like this:
    SendDlgItemMessage(hwnd, IDC_MYLIST, LB_ADDSTRING, 0, (LPARAM)string);

    I know that you can also call SetDlgItemMessage with LB_SETITEMDATA and add a pointer to extra data related to the item in the listbox.

    I have a structure with frame data for an animation and want to be able to link it up with my items in my listbox, so when an item is deleted the data is deleted. If an item is added, the data will be added. Simple, right?

    Well here is the structure I have:

    Code:
    struct framelist {
        char            *filepath;
        char            *filename;
        int             delay;
        int             loop;
        int             xpos;
        int             ypos;
        struct framelist*    next;
    };
    
    struct framelist *mainframeset;
    How would I do the following:

    Add item to listbox with a pointer to a list in a linked list using that structure? I already have the code to append/delete an item from the list.

    Let's just say my functions are:

    Code:
    struct framelist *Append(struct framelist *node, int data);
    void Delete(struct framelist *node, int itemnum);
    Any help is appreciated. Thanks in advance, I am sure someone out there will have a quick solution for this.

  2. #2
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100
    Hey, I just want to let you all know that I figured it out on my own. Feels good to do it on your own.

    Anyways, for future reference to others, here is how I did it.

    To add item to list and set the data
    Code:
    //Add Item/Data to list
    int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)string);
    SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, index, (WPARAM)AppendNode(&mainframeset, somedata));
    And to retrieve the data
    Code:
    //Retrieve Item/Data from list
    
    HWND hList = GetDlgItem(hwnd, IDC_LIST);
    int nItem = (int)SendMessage(hList, LB_GETCURSEL, 0, 0);
    struct framelist *temporaryframe;
    int dataptr=SendMessage(hList, LB_GETITEMDATA, (WPARAM)nItem, 0);
    temporaryframe = (framelist *)(dataptr);
    temporaryframe=temporaryframe->next;
    // Now we can get our data with temporaryframe->data
    -Nick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Editing listbox data
    By scwizard in forum Windows Programming
    Replies: 3
    Last Post: 12-23-2006, 09:41 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C diamonds and perls :)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 07:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21