Thread: ListBox Scrolling Problems

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    29

    Unhappy ListBox Scrolling Problems

    Hi,

    Ive got a listbox on my GUI which is constantly getting data displayed onto it.

    How can I limit the amount of data that is kept on the listbox, to say 100 lines??

    How can I keep the focus of the listbox on the most recent line entered, ie, so it is always scrolled to the bottom?

    Thanks very much for any help whatsoever,


    :-)

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Each new item

    find the number of items
    [use SendMessage() or one of the ListView_ macros.
    LVM_GETITEMCOUNT ListView_GetItemCount()]

    if more than needed
    delete starting with index zero

    to keep the current item shown
    ListView_SetItemState with LVIS_SELECTED and ensure you have set the LV style to LVS_SHOWSELALWAYS
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    Hi,

    Thanks for the reply.

    Would it be possible for you to give me an example, as im fairly new to this, so would help a lot! Or can anyone else help out here!?

    Here is part of the code in the GUI

    Code:
    LISTBOX         IDC_EVENTLOG,3,41,220,307,LBS_NOINTEGRALHEIGHT | 
                        WS_VSCROLL | WS_TABSTOP
    Thanks very much
    Last edited by pldd4; 10-21-2002 at 02:45 AM.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Show me you have tried and I will help more. (post code using code tags and I will correct)

    I'm sorry I will not write this for you, unless you wish to pay me for my time (as all my customers do).

    A search here will turn up more useful code (as I have posted more myself)

    I have given you all you need to compleate the code. (except determination and time)

    Start at the point you get some new data to add to the ctrl and go from there.

    Code:
    Check how many items
    If more than wanted
        delete some
    add new item
    set focus on new item
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    ok,

    ive searched and read some more of your posts.

    I tried

    Code:
    SendMessage(hListView, LVM_SCROLL, (WPARAM)0, (LPARAM)(ItemRect.bottom-ItemRect.top));
    SendMessage(hListView, LVM_ENSUREVISIBLE, (WPARAM)iRow, (LPARAM)FALSE);
    But when compiling get a few errors, LVM_SCROLL undeclared identifier, etc. Do i need to include a file??

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You have included

    commctrl.h

    (and also used InitCommonControlsEx()? )
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    Im going to try and just keep the listbox focused on the newest item added to the list, so its constantly scrolled to the bottom, first!

    ive included the commctrl.h

    Really not sure how the use InitCommonControlsEx()

    An example of how i could implement this code would be a fantastic help.

    Can anyone help me on this please??

    Thanks,



  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I'll asume your check is in the mail

    Code:
    INITCOMMONCONTROLSEX        ICC;
    ICC.dwSize=sizeof(INITCOMMONCONTROLSEX);
    ICC.dwICC=ICC_LISTVIEW_CLASSES 
    InitCommonCrtlsEx(&ICC);
    
    		ListView_SetItemState(hLV, iSeq, LVIS_SELECTED|LVIS_FOCUSED ,0);
    		ListView_EnsureVisible(hLV,iSeq,FALSE);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    Cheers mate. Cheques on its way!

    Rite, ive put the code in. Like so..

    Code:
    INITCOMMONCONTROLSEX ICC;
    						ICC.dwSize=sizeof(INITCOMMONCONTROLSEX);
    						ICC.dwICC=ICC_LISTVIEW_CLASSES;
    						InitCommonControlsEx(&ICC);
    
    						ListView_SetItemState(hDlg, IDC_EVENTLOG, LVIS_SELECTED | LVIS_FOCUSED, 0);
    						ListView_EnsureVisible(hDlg, IDC_EVENTLOG, FALSE);

    However when i compile i get the following errors


    Generating Code...
    Linking...
    sms_c.obj : error LNK2001: unresolved external symbol __imp__InitCommonControlsEx@4
    Debug/sms_c.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    sms_c.exe - 2 error(s), 2 warning(s)



    Any ideas? Do i have to put certain parts of the code in special locations etc??

    hmmmm really bugging me this.

    Thanks again

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    OK best guess first;

    Have you linked to

    comctl32.lib

    and included

    commctrl.h

    got an OS in

    Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 3.0 and later).

    Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 3.0 or later).

    Deleted your

    Comctl32.dll

    ?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    ok ive linked to comctl32.lib by going into project settings and adding it to the list. also included commctrl.h #include "commctrl.h"

    Im on Windows NT 4.0 with Internet Explorer 6

    Ive got the comctl32.lib in the following directory
    C:\Program Files\Microsoft Visual Studio\VC98\Lib\comctl32.lib

    When i do a build--batch build--rebuild all (both win32 Release & win32 Debug. The win32 Release fails with the same errors....
    Im using MS Visual C++ by the way.


    Linking...
    sms_c.obj : error LNK2001: unresolved external symbol __imp__InitCommonControlsEx@4
    Release/sms_c.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.


    However the win32 debug compiles fine

    Any other suggestions?

    Thanks for your time bud, much appreciated
    Last edited by pldd4; 10-25-2002 at 04:08 AM.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You linked to the library in BOTH release and debug didn't you?

    (I think you will find you have only got the lib in the debug)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    Yes, you were right!

    Ok, so ive put that code in

    Code:
    INITCOMMONCONTROLSEX ICC;
    						ICC.dwSize=sizeof(INITCOMMONCONTROLSEX);
    						ICC.dwICC=ICC_LISTVIEW_CLASSES;
    						InitCommonControlsEx(&ICC);
    
    						ListView_SetItemState(hDlg, IDC_EVENTLOG, LVIS_SELECTED | LVIS_FOCUSED, 0);
    						ListView_EnsureVisible(hDlg, IDC_EVENTLOG, FALSE);
    What is it supposed to do exactly??

    Because it doesnt seem to do anything at all!

    Sorry for dragging this on, but its so annoying !

    Cheers,
    Last edited by pldd4; 10-28-2002 at 04:24 AM.

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    LOL!

    I thought you had a clue.

    You tell me what it does and I will tell you where to put it.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    29

    Talking

    ok!

    The INITCOMMONCONTROLSEX is used to load the common control classes from the dll

    The ListView_SetItemState changes the state of the item in the list view control. In this case it sets the item to selected or focused.

    The ListView_EnsureVisible ensures that the list view item is either entirely or partially visible.

    ok, so this doesnt do any scrolling? yet? So that the new item is shown, ie as if the scrollbar down arrow is constantly held down. Or does the ensure visiblity suppose to do this?

    Whats the next step to get this working?!

    Please remember, as youve probably noticed im very new to this and i do appreciate your help very much.


    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListBox Extra Data Storage
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 11-01-2007, 01:46 PM
  2. ListBox Scrolling Problems
    By commissar in forum Windows Programming
    Replies: 0
    Last Post: 03-09-2005, 07:22 AM
  3. cant load dialog with listbox, help
    By terracota in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2004, 07:11 PM
  4. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM