Thread: Looking for a way to store listbox data

  1. #16
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100
    Bob, that code doesn't compile unfortionately. A ton of errors on Bloodshed Dev C++

    For example, these are not defined..
    LPNMLISTVIEW
    CDDS_PREPAINT
    CDRF_NOTIFYITEMDRAW

    There are TONS of other things like that.

  2. #17
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    I ain't up to snuff on my ANSI stuff but if memory serves me correctly, there isn't any strings.h header. I believe it should be string.h. I changed strings.h to string.h and it compiles.

    But anyway, I would suggest that you forget about the listview stuff for now and focus on getting your original code functioning properly, one step at a time. Once it's functioning properly, you can change it to a listview.

    Problem number one is that you have a wild pointer:
    Code:
       mainframeset=(struct framelist *)malloc(sizeof(struct framelist));
       mainframeset->filename = (char *)malloc(MAX_PATH);
        mainframeset->filepath = (char *)malloc(MAX_PATH);
        mainframeset->delay = 0;
        mainframeset->loop = 0;
        mainframeset->xpos = 0;
        mainframeset->ypos = 0;
    mainframeset->next = NULL;
        AppendNode(&mainframeset, 0, 0, 0, 0, "", "");
    Set the pointer to the next node to NULL.

    Also, a trivial issue, the return value of the AppendNode function is a struct of type node. It should be void since the function is not returning anything.

    *EDIT* Please explain what you're attempting to do with the Add Frame, Remove Frame, Safe Gif, Clear Frames and Update Frame Settings buttons in relation to your linked list. I'm totally lost here.
    Last edited by BobS0327; 10-31-2007 at 05:53 PM. Reason: Need additional info

  3. #18
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100
    Bob, you may be right on the include file.

    I will try that suggestion as well and get back to you.

    Yes, I noticed that about the AppendNode. That one was not written by me. I was going to change that but then I left it because it may come in handy later to return the newly appended item so I can assign a pointer to it in my listbox's 2nd paremeter after I add an item to the listbox/linked lists.

  4. #19
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100
    It doesn't crash if I remove "RetrieveList" from the main code... But I can't figure out what is wrong with it. It runs fine in my console test program, but not in this Win32 API program.

  5. #20
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    It doesn't crash if I remove "RetrieveList" from the main code... But I can't figure out what is wrong with it.
    When your listbox selection is zero, you will be checking for counter to equal -1 AND the current pointer to equal NULL to break out of the while loop. Counter will never equal -1 and your RetrieveList function crashes because it's in a perpetual loop.

    Code:
    struct framelist* RetrieveList(struct framelist** head, int num)
    {
        struct framelist* current = *head;
        int counter=0;
    
        if(current != NULL)
        {
            while(current != NULL && counter != num-1)
            {
                current = current->next;
                
                counter++;
            }
        }
    
        return current;
    }
    Also, the code in red is not necessary. Check the PushLinkedList function. Memory is allocated in that function.
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        mainframeset=(struct framelist *)malloc(sizeof(struct framelist));
        mainframeset->filename = (char *)malloc(MAX_PATH);
        mainframeset->filepath = (char *)malloc(MAX_PATH);
        mainframeset->delay = 0;
        mainframeset->loop = 0;
        mainframeset->xpos = 0;
        mainframeset->ypos = 0;
        AppendNode(&mainframeset, 0, 0, 0, 0, "", "");
    
    	DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
    
        free(mainframeset);
        return 0;
    }

  6. #21
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Location
    Washington
    Posts
    100
    Well thanks again for all the help you guys gave, especially Salem you were a big help to me.

    I ended up getting all my linked list code working, I rewrote a bunch of code in the functions I got from the tutorial to make them work for my application and will post them here when I get time (probably tomorrow) for people to learn from.

    I said "screw it" to the RetrieveList() function that I wrote and ended up using a pointer to the list and storing it in my listbox with SETITEMDATA and it works beautifully.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  2. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  3. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 06:03 PM
  4. Do you store store one off data arrays in a class?
    By blood.angel in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2002, 12:05 PM
  5. Can applications store data in DLL's ?
    By kes103 in forum C Programming
    Replies: 6
    Last Post: 06-02-2002, 06:55 PM