Announcement

Collapse
No announcement yet.

api listbox code

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

  • api listbox code

    How do I add and insert text into this listbox program using the api.

    Resource code
    Code:
    #define IDD_DLG1 1000
    #define IDC_LST1 1001
    #include "C:/PBCC40/WinAPI/Resource.h"
    dialog_1 DIALOGEX 206,206,393,259
    CAPTION "IDD_DLG"
    FONT 8,"MS Sans Serif",0,0
    STYLE 0x10CF0000
    BEGIN
      CONTROL "",IDC_LST1,"ListBox",0x50010141,20,72,350,76,0x00000200
    END
    Here is the source code
    Code:
    'list box pgm
    
    #COMPILE EXE
    #CONSOLE OFF
    '#DIM ALL
    %ccwin=1
    
    #INCLUDE "WIN32API.INC"
    
    #RESOURCE "CK009.PBR"
    
    DECLARE FUNCTION DialogBox (BYVAL hCurInstance AS LONG, lpTemplateName AS ASCIIZ, BYVAL hWndParent AS LONG, BYVAL lpDialogFunc AS LONG) AS LONG
    
    %IDC_LST1 = 1001
    
    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
    
        LOCAL windowtitle AS ASCIIZ * 256
    
    
     DialogBox hCurInstance, "dialog_1", hconsole, CODEPTR(DialogProc) 'the DialogProc will receive the events from the dialog
    
    
    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 * 46
    
     SELECT CASE wMsg
        CASE %WM_COMMAND
            SELECT CASE LOWRD(wParam)
    
            CASE %IDCANCEL      'X cancel
                EndDialog hDlg, 1
                FUNCTION = 1
            END SELECT
     END SELECT
    
    END FUNCTION
    djthain

  • #2
    You'll need to use LB_ADDSTRING. Something like this..
    Code:
        LOCAL buffer AS ASCIIZ * 46
        LOCAL Res AS LONG
        STATIC hListBox AS DWORD
     
     SELECT CASE wMsg
        CASE %WM_INITDIALOG
          hListBox = GetDlgItem(hDlg, %IDC_LST1)
          buffer = "This is the First Line"
          Res = SendMessage (hListBox, %LB_ADDSTRING, 0, BYVAL VARPTR(buffer))
          buffer = "This is the Second Line"
          Res = SendMessage (hListBox, %LB_ADDSTRING, 0, BYVAL VARPTR(buffer))
          SetWindowText hDlg, "ListBox Index(0-based): " + str$(res)
     
        CASE %WM_COMMAND
            SELECT CASE LOWRD(wParam)
              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
    Last edited by Dave Biggs; 26 Jan 2009, 02:05 AM.
    Rgds, Dave

    Comment


    • #3
      thanks

      Hi Dave,
      Thanks for the input. Everything worked fine after I added your routines.
      djthain

      Comment


      • #4
        You need to be careful, Mr. Thain.

        Telling us you are actually TRYING new things such as adding a listbox to a PB/CC application - and then seeing it work -might start a dangerous new trend.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X