Announcement

Collapse
No announcement yet.

clear listbox & attach scroll bar with API

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

  • david thain
    replied
    Thanks guys. My program scrolls and resets the content. You have been very helpful.
    djthain

    Leave a comment:


  • Michael Mattias
    replied
    >Maybe try adding WS_VSCROLL to the ListBox.

    You can do it with independent scrollbar controls by processing the WM_VSCROLL notification message. But then you also have to adjust the scroll bar size when adding or deleting items, and setting the thumb position position whenever the user selects a different item in the list box with the mouse or the cursor (SetScrollInfo function)

    But using the WS_VSCROLL style on the listbox and eschewing the use of separate scrollbar controls is WAAAAAY easier.... (Like, ZERO code required!)

    MCM

    Leave a comment:


  • Paul Squires
    replied
    Maybe try adding WS_VSCROLL to the ListBox.

    Leave a comment:


  • david thain
    replied
    Is there a way for the scroll bars in the resource file to scroll the list box content?

    Leave a comment:


  • Michael Mattias
    replied
    1. LB_RESETCONTENT message

    2. What do you mean "attach" the scroll bar controls? "Attach" to what?

    Leave a comment:


  • david thain
    started a topic clear listbox & attach scroll bar with API

    clear listbox & attach scroll bar with API

    Is there a way using API to clear the contents of a list box in pbcc? Also how do you attach the scroll bars from the resource file?

    Resource file:

    Code:
    #include "resource.h"
    DIALOG_1 DIALOGEX DISCARDABLE  34, 28, 393, 259
    STYLE WS_OVERLAPPED | WS_OVERLAPPEDWINDOW | WS_VISIBLE
    CAPTION "IDD_DLG"
    FONT 8, "MS Sans Serif"
    BEGIN
        CONTROL "",          1001, "LISTBOX", LBS_NOTIFY | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 20, 72, 350, 76, WS_EX_CLIENTEDGE
        CONTROL "",          100, "SCROLLBAR", SBS_VERT | WS_CHILD | WS_VISIBLE, 370, 73, 15, 74
        CONTROL "",          105, "SCROLLBAR", SBS_HORZ | WS_CHILD | WS_VISIBLE, 20, 149, 349, 14
        CONTROL "",          106, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 196, 97, 14
        CONTROL "",          107, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 129, 196, 92, 14
        CONTROL "",          108, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 234, 196, 97, 15
        CONTROL "",          109, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 22, 28, 69, 14
        CONTROL "Account #", 101, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 21, 10, 69, 12
        CONTROL "Search",    102, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 111, 29, 29, 14
    END
    Program:

    Code:
    'list box pgm
    
    #COMPILE EXE
    #CONSOLE OFF
    '#DIM ALL
    %ccwin=1
    
    #INCLUDE "WIN32API.INC"
    #INCLUDE "CHEETAH2.INC"  'all declares for Cheetah Database
    #RESOURCE "CK009t.PBR"
    GLOBAL varble$()  '?????
    GLOBAL rcd1$()
    GLOBAL y&
    GLOBAL dbhandle&
    GLOBAL recnum&
    GLOBAL flaga%
    GLOBAL totaloutstand#
    GLOBAL totalreconsile#
    GLOBAL totaldeposit#
    GLOBAL totalwthdl#
    GLOBAL totalinterest#
    
    DECLARE FUNCTION DialogBox (BYVAL hCurInstance AS LONG, lpTemplateName AS ASCIIZ, BYVAL hWndParent AS LONG, BYVAL lpDialogFunc AS LONG) AS LONG
    
    DECLARE SUB l25totlrtn
    
    DECLARE SUB l22get
    
    %IDC_LST1 = 1001
    %IDC_TXT1 = 106
    %IDC_TXT2 = 107
    %IDC_TXT3 = 108
    
    FUNCTION WINMAIN (BYVAL hCurInstance  AS LONG, _     'Not PBMain since
                      BYVAL hPrevInstance AS LONG, _     'hCurInstance is needed
                      BYVAL lpszCmdLine         AS ASCIIZ PTR, _
                      BYVAL nCmdShow AS LONG ) EXPORT AS LONG
        DEFLNG a-z
        DIM rcd1$(400)
        DIM varble$(11)
        LOCAL windowtitle AS ASCIIZ * 256
    
        infofle$ = "C:\accounts\cnbdt\ck001.dss"
        OPEN infofle$ FOR INPUT AS 1
        INPUT #1, conam$, lb1$, flena1$, lb2$, flena2$, fleno%, dr$
        CLOSE 1
    
        DBFname$ = flena2$
    
        flaga% = 0
    
    
    '****************************************************************************
    '            Open File Section
    '***************************************************************************
    
    'open the database (database must be open prior to creating index)
       dbHandle& = xdbOpen&(DBFname$)
    
       IF xdbError THEN
    
          PRINT "Error: " & STR$(xdbError&) & " opening database.",,Title$
          CALL xdbResetError
          EXIT FUNCTION
       END IF
    
       CALL xdbSkipDeleted (DBhandle&, 1)
    
       IF xdbError THEN
           BEEP
          PRINT "Error: " & STR$(xdbError&) & " opening database.",,Title$
          CALL xdbResetError
          EXIT FUNCTION
       END IF
    
    
        DialogBox hCurInstance, "dialog_1", hconsole, CODEPTR(DialogProc) 'the DialogProc will receive the events from the dialog
    '    DialogBoxParam(GetModuleHandle(NULL), Cast(zstring PTR,"DIALOG_1"), NULL, @DlgProc, NULL)
        ''
        '' Program has ended
        ''
    
        CALL xdbClose(DBhandle&)
    
        CLOSE
    
        END
    
    END FUNCTION  ' WinMain
    
    '------------------------------------------------------------------------------
    FUNCTION DialogProc(BYVAL hDlg AS LONG, BYVAL wMsg AS LONG, _
                       BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    
        LOCAL buffer AS ASCIIZ * 130
        LOCAL Res AS LONG
        STATIC hListBox AS DWORD
    
     SELECT CASE wMsg
        CASE %WM_INITDIALOG
            SetWindowText hDlg, "Account # Search " + STR$(res)
            setfocus(getdlgitem(hdlg,109))
            
            
        CASE %WM_COMMAND
            SELECT CASE LOWRD(wParam)
                CASE 102
                    y=0
                    recnum&=0
                    flaga%=0
    
                    GetDlgItemtext(hdlg,109,buffer,11)
                    varble$(4)=LEFT$(buffer+"     ",5)
    
                    hListBox = GetDlgItem(hDlg, %IDC_LST1)
    
                    DO: l22get: LOOP UNTIL flaga% = 1
    
                    l25totlrtn
    
                    FOR x=1 TO y
                        buffer = rcd1$(x)
                        Res = SendMessage (hListBox, %LB_ADDSTRING, 0, BYVAL VARPTR(buffer))
                    NEXT x
    
                    buffer = varble$(1)
                    setdlgitemtext(hDlg,%IDC_TXT1,buffer)
    
                    buffer = varble$(2)
                    setdlgitemtext(hDlg,%IDC_TXT2,buffer)
    
                    buffer = varble$(3)
                    setdlgitemtext(hDlg,%IDC_TXT3,buffer)
    
                    CALL xdbMoveFirst(DBhandle&, 0)
    
                    FOR x=1 TO y
                        rcd1$(x)=""
                    NEXT x
    
                CASE %IDC_LST1
                    SELECT CASE HIWRD(wParam)
                        CASE %LBN_SELCHANGE
                            Res = SendMessage (hListBox, %LB_GETCARETINDEX, 0, 0)
                            IF SendMessage (hListBox, %LB_GETTEXT, Res, BYVAL VARPTR(buffer)) <> %LB_ERR THEN
                                SetWindowText hDlg, STR$(res) + ": " + buffer
                            END IF
                    END SELECT
    
    
                CASE %IDCANCEL      'X cancel
                    EndDialog hDlg, 1
                    FUNCTION = 1
           END SELECT
     END SELECT
    END FUNCTION
    
    '****************************************************************************
    '                  Write Information to Screen
    '****************************************************************************
    SUB l22get
        LOCAL buffer AS ASCIIZ * 130
        LOCAL Res AS LONG
        STATIC hListBox AS DWORD
    
    
        INCR RecNum&
    
        CALL xdbGetRecord(dbHandle&, RecNum&)
    
        IF ISTRUE xdbEOF&(DBhandle&) THEN
            flaga%=1:EXIT SUB
        END IF
    
        IF ISTRUE xdbDeleted&(DBhandle&, RecNum&) THEN EXIT SUB
    
            primarykey$=SPACE$(11)
            LSET primarykey$ =xdbFieldValue$(dbHandle&, "primarykey", 0)
            dte1$ =xdbFieldValue$(dbHandle&, "dte1", 0)
            descr$ =SPACE$(40)
            LSET descr$ =xdbFieldValue$(dbHandle&, "descr", 0)
            deposit# =VAL(xdbFieldValue$(dbHandle&, "deposit", 0))
            wthdl# =VAL(xdbFieldValue$(dbHandle&, "wthdl", 0))
            interest# =VAL(xdbFieldValue$(dbHandle&, "interest", 0))
            chkno$=SPACE$(4)
            LSET chkno$ =xdbFieldValue$(dbHandle&, "chkno", 0)
            chkmark$=SPACE$(1)
            LSET chkmark$ =xdbFieldValue$(dbHandle&, "chkmark", 0)
            acctno$=SPACE$(5)
            LSET acctno$ =xdbFieldValue$(dbHandle&, "acctno", 0)
            comment$=SPACE$(45)
            LSET comment$=xdbFieldValue$(dbHandle&, "comment", 0)
            chkmark2$=xdbFieldValue$(dbHandle&, "chkmark2", 0)
    
    
            IF acctno$<>varble$(4) THEN EXIT SUB
    
            INCR y
            rcd1$(y)=acctno$+" "+LEFT$(descr$+SPACE$(40),40)+" deposit "+FORMAT$(deposit#*.01,"#######.00")+" wthdl "+FORMAT$(wthdl#*.01,"#######.00")+" intrst "+FORMAT$(interest#*.01,"#######.00")
    
    
            totaldeposit# = totaldeposit# + deposit#
            totalwthdl# = totalwthdl# + wthdl#
            totalinterest# = totalinterest# + interest#
    
            IF chkmark$ = "*" THEN
                totalreconsile# = totalreconsile# + interest# + deposit# - wthdl#
                totalrconwthdl# = totalrconwthdl# + wthdl#
                totalrcondep# = totalrcondep# + deposit#
                totalrconint# = totalrconint# + interest#
            ELSE
                totaloutstand# = totaloutstand# + interest# + deposit# - wthdl#
                totaloutwthdl# = totaloutwthdl# + wthdl#
                totaloutdep# = totaloutdep# + deposit#
                totaloutint# = totaloutint# + interest#
            END IF
    
    END SUB
    
    
    SUB l25totlrtn
    
           varble$(1)= USING$("#####.##", totaldeposit# * 0.01)
           varble$(2)= USING$("#####.##", totalwthdl# * 0.01)
           varble$(3)= USING$("#####.##", totalinterest# * 0.01)
           totaldeposit#=0
           totalwthdl#=0
           totalinterest#=0
    
    END SUB
Working...
X