Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Synchronized Listboxes

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

  • Synchronized Listboxes

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Example of synchronising 2 listboxes via parent's WM_CTLCOLORLISTBOX
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    %ID_LIST     = 31
    %ID_LIST2    = 32
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG, I AS LONG
      DIM arr(49) AS STRING
     
      DIALOG NEW 0, "Synchronized listboxes",,, 188, 155, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
     
      FOR I = 0 TO 49 : arr(I) = "Line" & STR$(I + 1) : NEXT
     
      CONTROL ADD LISTBOX, hDlg, %ID_LIST, arr(), 4, 4, 180, 65, _
                           %WS_CHILD OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
     
      CONTROL ADD LISTBOX, hDlg, %ID_LIST2, arr(), 4, 74, 180, 65, _
                           %WS_CHILD OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
     
      CONTROL ADD BUTTON, hDlg, %IDOK, "E&xit", 134, 138, 50, 14
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      STATIC NoUpdate AS LONG 'to avoid un-neccessay updating
     
      SELECT CASE CBMSG
         CASE %WM_CTLCOLORLISTBOX
            'Note: if needed, return bg color brush and set textcolor, etc. here, before NoUpdate flag
     
            IF NoUpdate THEN EXIT FUNCTION
            NoUpdate = %TRUE
     
            LOCAL hList AS LONG, hList2 AS LONG, ln AS LONG, ln2 AS LONG
            hList  = GetDlgItem(CBHNDL, %ID_LIST)
            hList2 = GetDlgItem(CBHNDL, %ID_LIST2)
            IF CBLPARAM = hList2 THEN SWAP hList, hList2      'hList is the one with focus..
     
            'SYNCHRONIZE SELECTED LINE (if needed, otherwise rem out)
            ln  = SendMessage(hList, %LB_GETCURSEL, 0, 0)     '<- get seleced line
            ln2 = SendMessage(hList2, %LB_GETCURSEL, 0, 0)    '<- get seleced line
            IF ln <> ln2 THEN
               CALL SendMessage(hList2, %LB_SETCURSEL, ln, 0) '<- set selected line
            END IF
     
            'SYNCHRONIZE TOP LINE (if needed, otherwise rem out)
            ln  = SendMessage(hList, %LB_GETTOPINDEX, 0, 0)   '<- get first visible line in 1
            ln2 = SendMessage(hList2, %LB_GETTOPINDEX, 0, 0)  '<- get first visible line in 2
            IF ln <> ln2 THEN
               SendMessage hList2, %LB_SETTOPINDEX, ln, 0     '<- amount to scroll textbox 1
            END IF
     
            NoUpdate = 0
     
         CASE %WM_COMMAND
            IF CBCTL = %IDOK THEN DIALOG END CBHNDL
     
      END SELECT
    END FUNCTION
    ------------------


    [This message has been edited by Borje Hagsten (edited April 24, 2001).]
Working...
X