Re: Picking LISTBOX items in a dialog

Discussions related to mouse, keyboard, fonts and Graphical User Interface
Hated Moron

Re: Picking LISTBOX items in a dialog

Post by Hated Moron »

On 04/09/2023 20:05, Daniel Bingamon wrote (cross-posted from the Discussion Group):
I've had BBC4WIN for quite some time, I also program in plain C windows applications and VB.NET.

There is a program that I've written in the other two computer languages and now I'm trying in BBC Basic SDL Version.
I'm wanting to take the selection from the primary listbox (ctrl 104) on the left and show it after the "Selected" position - control #300 - which shows as a "." for placeholder. I don't want to kill the dialog quite yet....
The following minor modification to your program should do that (I've replaced your file-reading code for expository purposes). The key point you may have missed is that the listbox shouldn't be given a constant ID like 104 but the value returned from FN_setproc():

Code: Select all

      ON ERROR IF ERR=17 CHAIN @lib$+"../examples/tools/touchide" ELSE MODE 3 : PRINT REPORT$ : END

      REM Beginnings of Electronic Songbook

      INSTALL @lib$ + "dlglib"

      REM!WC Windows Constants:
      ES_NUMBER = 8192
      SS_CENTER = 1
      WS_GROUP = &20000

      REM Set colour palette:
      PROC_setdialogpalette

      REM Set font according to platform:
      IF INKEY(-256) = &57 THEN
        *FONT Segoe UI,10
      ELSE
        OSCLI "FONT """ + @lib$ + "FreeMono"",12"
      ENDIF

      REM Adjust caret shape and size according to font:
      VDU 23,0,10,0,0;0;0;         : REM Set start line
      VDU 23,0,11,@vdu%!220,0;0;0; : REM Set end line
      VDU 23,0,18,2,0;0;0;         : REM Set caret width

      REM Create the dialogue box 'template':
      dlg% = FN_newdialog("Electric Songbook - BBC Basic Edition By D.Bingamon", 319, 234)

      REM Buttons

      PROC_button(dlg%, "Edit Song", 1011, 5, 4, 56, 14, WS_GROUP)

      PROC_button(dlg%, "Create New Song", 1012, 64, 4, 78, 14, 0)
      PROC_button(dlg%, "Review from Main List", 1013, 145, 4, 115, 14, 0)
      PROC_button(dlg%, "Exit", 1, 262, 4, 40, 14, 0)
      PROC_button(dlg%, "Search", 20, 5, 200, 40, 14, 0)
      PROC_static(dlg%, "Selected:", 220, 50, 202, 50, 12, 0)

      PROC_static(dlg%, ".", 300, 100, 202, 100, 12, 0)

      PROC_button(dlg%, "Transfer", 21, 232, 28, 42, 8, 0)
      PROC_button(dlg%, "Run", 22, 282, 28, 35, 8, 0)
      PROC_button(dlg%, "Del", 23, 282, 38, 35, 8, 0)
      PROC_button(dlg%, "Up", 24, 282, 48, 35, 8, 0)
      PROC_button(dlg%, "Dn", 25, 282, 58, 35, 8, 0)

      PROC_button(dlg%, "PDF", 26, 282, 68, 35, 28, 0)

      REM
      REM Listobx
      REM
      DIM ListBox$(1000)

      ListBox$() = "", "Song one", "Song two", "Song three", "Song four", "Song five"
      intSongCount = 5

      lbid% = FN_setproc(PROClbclick())
      PROC_listbox(dlg%, "", lbid%, 10, 35, 120, 160, WS_VSCROLL)
      PROC_setlistboxarray(dlg%, lbid%, ListBox$(), intSongCount)

      PROC_static(dlg%, "Main list of songs", \
      \           100, 10, 22, 102, 12, 0)

      PROC_static(dlg%,"Your choices", \
      \           200, 140, 22, 62, 12, 0)
      PROC_static(dlg%,"#, Song Name, Key", \
      \           200, 140, 32, 92, 12, 0)

      DIM SongChoices$(10)

      PROC_listbox(dlg%, "", 204, 140, 45, 140, 150, WS_VSCROLL)
      PROC_setlistboxarray(dlg%, 204, SongChoices$(), DIM(SongChoices$(),1))

      PROC_registerdlgcallback(dlg%, FNmycb())
      result% = FN_showdialog(dlg%, &80000000, &80000000)

      IF result% = 1 THEN
        tb$ = FN_getdlgitemtext(dlg%, 101)
        nb% = VAL(FN_getdlgitemtext(dlg%, 102))
        ComboBox$ = FN_getdlgitemtext(dlg%, 103)
        ListBox$ = FN_getdlgitemtext(dlg%, lbid%)
        rb% = FN_isdlgitemchecked(dlg%, 105)
        cb% = FN_isdlgitemchecked(dlg%, 107)

      ENDIF

      PROC_closedialog(dlg%)

      VDU 4, 30
      IF result%=1 THEN
        PRINT "OK pressed, settings were:"'
        PRINT "Text box contained """ tb$ """"
        PRINT "Number box contained "; nb%

        PRINT "Combobox selection was """ ComboBox$ """"
        PRINT "Listbox selection was """ ListBox$ """"
        IF rb% THEN
          PRINT "Radiobutton 1 was checked"
        ELSE
          PRINT "Radiobutton 2 was checked"
        ENDIF

        IF cb% THEN
          PRINT "Checkbox was checked"
        ELSE
          PRINT "Checkbox was not checked"
        ENDIF

      ELSE
        PRINT "Cancel pressed"
      ENDIF

      REPEAT WAIT 1 : UNTIL FALSE
      END

      DEF FNmycb(D%,K%)
      IF K% = 13 THEN = 1
      = 0

      DEF PROClbclick(D%, I%)
      LOCAL song$
      song$ = FN_getdlgitemtext(D%, I%)
      PROC_setdlgitemtext(D%, 300, song$)
      PROC_refreshdialog(D%)
      ENDPROC