Announcement

Collapse
No announcement yet.

Please help with scrollbar question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pierre Bellisle
    replied
    Hey Tory,
    since you prefer to have an example,
    here is one using "SendMessage hList, %LB_SETCURSEL, LastItem, 0"

    Code:
    #COMPILE EXE '#Win 8.04#
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "Win32Api.inc" '#2005-01-27#
     
    %Listbox = 101
    %Button  = 201
    '______________________________________________________________________________
     
    CALLBACK FUNCTION DlgProc() AS LONG
     LOCAL  Buffer   AS STRING
     LOCAL  LastItem AS LONG
     STATIC Looper   AS LONG
     STATIC hList    AS DWORD
     
     SELECT CASE CBMSG
     
       CASE %WM_INITDIALOG
         hList = GetDlgItem(CBHNDL, %Listbox)                   'Get listbox handle
         FOR Looper = 1 To 15
           Buffer = "Item " & FORMAT$(Looper, "000")            'Fill listbox
           SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer)) 'Add info to listbox
         NEXT
         SendMessage hList, %LB_SETCURSEL, Looper - 2, 0        'Go to last position
     
       CASE %WM_COMMAND
         SELECT CASE CBCTL
           CASE %Button
             IF CBCTLMSG = %BN_CLICKED THEN
               Buffer = "Item " & FORMAT$(Looper, "000")              'Prepare info for listbox
               SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))   'Add info to listbox
               LastItem = SendMessage(hList, %LB_GETCOUNT,  0, 0) - 1 'Ask for last item number, zero based
               SendMessage hList, %LB_SETCURSEL, LastItem, 0          'Go to last position
               INCR Looper                                            'Needed to update the buffer
             END IF  
      
          END SELECT
     
     END SELECT
     
    END FUNCTION
    '______________________________________________________________________________
     
    FUNCTION PBMAIN() AS LONG
     LOCAL hDlg AS DWORD
     
     DIALOG NEW %HWND_DESKTOP, "Listbox", , , 162, 100, _
                %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
     
     SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice dialog icon
     
     CONTROL ADD LISTBOX, hDlg, %Listbox, , 6, 6, 150, 80
     
     CONTROL ADD BUTTON, hDlg, %Button, "Add to list", 6, 80, 150, 15
     
     DIALOG SHOW MODAL hDlg, CALL DlgProc
     
    END FUNCTION
    '______________________________________________________________________________
    '
    Last edited by Pierre Bellisle; 6 Feb 2008, 08:59 PM.

    Leave a comment:


  • Kev Peel
    replied
    ..or you could use LB_SETTOPINDEX which will "auto scroll" to place your item at the top of the list, if the list is scrollable.

    Leave a comment:


  • Michael Mattias
    replied
    Hint: LB_SETCURSEL message.

    Leave a comment:


  • Tory Remrey
    started a topic Please help with scrollbar question

    Please help with scrollbar question

    Greetings all,

    Ok I have a dialog, which contains a LISTBOX with a vertical scrollbar. Is there a way I can set the behavior of the VSCROLL to, automatically and persistently, scroll down to the bottom of the list? As opposed to the default manner in which VSCROLL remains at the top of the list, until the user instructs otherwise. Basically I wish to reverse the default scroll bar behavior.

    The reason being the DIALOG also has a TEXTBOX, which receives data from the user, then must output text (entered by the user) to the LISTBOX. As new text is appended to the LISTBOX it always appears at the bottom of the list. This is perfectly ok and exactly as I wish. The problem is to see the newest entries I must manually scroll to the bottom. I simply wish to automate the VSCROLL downwards.

    For example, consider an instant messenger program, chat program, or telenet MUD client. The scrollbar in these types of programs behave in an inverse manner. Essentially these types of programs are identical to what I am attempting to accomplish.

    As always, an actual example of code is preferable to an explanation of how this may be achieved. If I have the code, the explanation should be self-evident. However, I appreciate any help you may be able to provide.

    Thank You!
Working...
X