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

Simple Listbox With Keybord Select For PBwin9.4 using DDT

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

  • PBWin Simple Listbox With Keybord Select For PBwin9.4 using DDT

    Using PowerBasic's DDT this is simple. You do not need to capture
    characters using the %WM_CHAR message like you need to do using SDK style
    windows programming.

    Code:
    ' Simple Listbox With Keybord Select For PBwin9.4 using DDT
    
    ' Using PowerBasic's DDT this is simple. You do not need to capture
    ' characters using the %WM_CHAR message like you need to do using SDK style
    ' windows programming: see: http://msdn.microsoft.com/en-us/library/bb775144%28v=VS.85%29.aspx
    
    ' You can select list box items using the keyboard. It works as follows.
    ' The first item that begins with the character the user typed will be selected.
    ' Multiple characters typed within a short interval are treated as a group, and the first
    ' item that begins with that series of characters is selected.
    
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE ONCE "WIN32API.INC"
    
    %IDD_DIALOG1                        =  102
    %IDC_LISTBOX1                       = 1026
    %IDC_LABEL2_SELECTED                = 1027
    %IDC_BUTTON1                        = 1028
    %IDC_LABEL2_EXPLAIN                 = 1029
    %IDC_LABEL3_EXPLANATION             = 1030
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
        LOCAL i AS LONG, j AS LONG, k AS LONG
        STATIC txtv AS STRING
        STATIC s AS STRING
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
                ' Fill listbox with names
                FOR i=65 TO 90 STEP 2
                    FOR j=65 TO 90 STEP 3
                        FOR k=65 TO 90 STEP 4
                            LISTBOX ADD CBHNDL, %IDC_LISTBOX1, CHR$(i)+CHR$(j)+CHR$(k)+" ANDERSEN"
                        NEXT
                    NEXT
                NEXT
                s = "You can select a list item just by using the keyboard." + $CRLF + $CRLF + "If more " + _
                    "items begin by a certain character, the first will be selected. "+ $CRLF + $CRLF + _
                    "By entering more characters you will be able to select the one item with " + _
                    "just the specified sequence of characters." + $CRLF + $CRLF + _
                    "Remember: a list box does not distinguish between upper and lower case characters. "+ $CRLF + $CRLF + _
                    "The keyboard selection will work correctly only if the list box has the " + _
                    "%LBS_SORT style. "+ $CRLF + $CRLF + "If you enter a character sequence that is not " + _
                    "in the list box, the first item with the matching initial character(s) is being selected." + _
                    $CRLF + $CRLF + "If you then press the same key again, the next matching item will be selected. " + _
                    $CRLF + $CRLF + "If even the first entered character has no match in the list box, no selection is made. "
    
                CONTROL SET TEXT CBHNDL, %IDC_LABEL3_EXPLANATION, s
                CONTROL SET FOCUS CBHNDL, %IDC_LISTBOX1
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                    CASE %IDC_LISTBOX1
                        LISTBOX GET TEXT CBHNDL, %IDC_LISTBOX1 TO txtv
                        CONTROL SET TEXT CBHNDL, %IDC_LABEL2_SELECTED, "You Selected: "+txtv
                    CASE %IDC_BUTTON1
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CBHNDL
                END SELECT
    
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
        DIALOG NEW %HWND_DESKTOP, "Simple Listbox Keyboard Select", , , 348, 218, _
            %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
            %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME _
            OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
            %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
            %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, , 10, 25, 120, 170, %LBS_SORT OR _
            %LBS_NOTIFY OR %WS_TABSTOP OR %WS_VSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL2_SELECTED, "You Selected: ", 10, 200, _
            120, 10, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_STATICEDGE OR _
            %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL3_EXPLANATION, "" , 135, 15, 205, 180, _
            %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, _
            %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "E&xit", 295, 195, 45, 15
        CONTROL ADD LABEL,   hDlg, %IDC_LABEL2_EXPLAIN, "Press Key(s) " + _
            "to select item", 10, 15, 120, 10, %WS_CHILD OR _
            %WS_VISIBLE OR %SS_CENTER, %WS_EX_STATICEDGE OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Last edited by Erik Christensen; 11 Oct 2010, 02:37 PM.
Working...
X