Thread: ListBox Scrolling Problems

  1. #16
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    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

  2. #17
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Sounds like you'd better send that check, bud

    Have you ever tried MFC, mate?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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

    Nope ive not tried MFC. Should i? Ive just started reading up on it.

    I thought we were gettin somewhere though with the previous stuff!? hmmm


  4. #19
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    OK, just one more time.

    That code snippet is all you need to scroll the list box AND to initialse the controls. It is not all supposed to go in one place.

    First initialise the common controls in your winmain() with the InitCommonControlsEx()

    Write a function for when you get a new item to add to the listbox that;

    1 Checks the number of items in the listbox
    2 Deletes those over the required number starting at the oldest
    3 Adds the new item
    4 Uses the two lines (SetItemState and EnsureVisible) so that the new item is highlighted and scrolled into view by windows.


    How do you know you have another item to add to the listbox?
    How do you know you have all the new item?
    Call the new function at this point in the code.

    Post this function before I will help again (I still haven't got that check so you had better double it and send again)
    "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. #20
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    Rite, here is my code so far,

    Code:
    // vLog
    void vLog(char* vsText)
    {
    #if defined gtLOG
    	char sDateTime[20];
    	char sTime[20];
    	char sText[256];
    	char sLogFile[100]; // store the name of the log file
    	FILE* hLogFile;
    
      // get the current time
      _strtime(sTime);
    
      // append current time to text
    	sprintf(sText, "%s %s", sTime, vsText);
    
      // add text to list box
    	//if (SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0) >= gtMAX_LIST_ITEMS)
    	if (SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0) >= 140)
    	{
    		SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_DELETESTRING, (WPARAM) 0, 0);
    		SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sText);
    		//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_ENSUREVISIBLE, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
    		//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_SCROLL, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
    		SetWindowPos(u_hDlg, 0, 0, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), 0, 0), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    	}
    	else
    	{	
    		
    		//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_ENSUREVISIBLE, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
    		//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_SCROLL, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
    		
    		SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sText);
    		SetWindowPos(u_hDlg, 0, 0, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), 0, 0), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    	
    	}
    
    	// create file name based on date
    	vGetTime(sDateTime, gtDATE);
    	sprintf(sLogFile, "c:\\sms\\c\\c_%s.log", sDateTime);
    
    	// log text to file
      if (hLogFile = fopen(sLogFile, "a+"))
    	{	
    		fprintf(hLogFile, "%s \n", sText);
    		fflush(hLogFile);
    		fclose(hLogFile); 
    	}
    #endif
    }
    As you may have noticed ive tried to use the SetWindowPos function to always show the most recent item entered to the listbox. Not sure if this is setup correctly? But it seems easyier to implement than the previous methods we were discussing. If you think i am wrong please say and describe what i can do.

    Surely it cannot be this hard just to keep the most recent item entered into the listbox displayed. ie, so that if the scroll bar comes into play (when all the data cant fit on one screen of the listbox), it is scrolled down to show the current item!


    Anyone??!


    thanks,

  6. #21
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    A try even if not much of one.
    Did you compile this and attempt to debug?

    (I can see you didn't from)
    #if defined gtLOG

    try

    #ifdef gtLOG or (#ifndef)

    Apart from the errors that may occur with the adding strings to other strings.

    try breaking it down into smaller pieces
    Code:
    Find number of items
    while(NumListViewItems>MAX_ITEMS)
    {
         delete first item
          find number of items
    }
    
    Add new Item
    
    Get New items index
     (probably a return from the add )
    
    Use the set focus and ensure visible 
    
    UpdateWindow(u_hDlg);//ask windows to redraw the screen
    Windows should then redraw the contol with the lat item highlighted and in view.
    "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. #22
    Registered User
    Join Date
    Sep 2002
    Posts
    29
    ok, try again!

    heres what i have done:-

    Code:
    // vLog
    void vLog(char* vsText)
    {
    #if defined gtLOG
    	char sDateTime[20];
    	char sTime[20];
    	char sText[256];
    	char sLogFile[100]; // store the name of the log file
    	FILE* hLogFile;
    	long i;
    	long ni;
    
      // get the current time
      _strtime(sTime);
    
      // append current time to text
    	sprintf(sText, "%s %s", sTime, vsText);
    
      // add text to list box
    		
    	i = SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0);
    	
    	while (i >= gtMAX_LIST_ITEMS)
    	{
    		SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_DELETESTRING, (WPARAM) 0, 0);
    		i = SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0);
    	}
    
    	
    	
    		ni = SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sText);
    		ListView_SetItemState(u_hDlg, ni, LVIS_SELECTED | LVIS_FOCUSED, 0);
    		ListView_EnsureVisible(u_hDlg, ni, FALSE);
    
    		UpdateWindow(u_hDlg);
    	
    
    
    
    
    
    	// create file name based on date
    	vGetTime(sDateTime, gtDATE);
    	sprintf(sLogFile, "c:\\sms\\c\\c_%s.log", sDateTime);
    
    	// log text to file
      if (hLogFile = fopen(sLogFile, "a+"))
    	{	
    		fprintf(hLogFile, "%s \n", sText);
    		fflush(hLogFile);
    		fclose(hLogFile); 
    	}
    #endif
    }

    Still doesnt work! ie, it doesnt focus on newest item added to the listbox when scrollbar becomes active.


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