'====================================================================
' Sorted ComboBox example, modal dialog as main.
'====================================================================

$ filename "SortedCombo.exe"
'uses rtl32
'uses rtl64

'% review

uses dialogs


int ID_Combobox=100
int ID_Info=IDOK

function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback

  string Result
  sys List1=GetDlgItem(hDlg, ID_Combobox)
  
  select case uMsg
  
    case WM_INITDIALOG
       SendMessage(List1, CB_ADDSTRING, 0, "one")
       SendMessage(List1, CB_ADDSTRING, 0, "two")
       SendMessage(List1, CB_ADDSTRING, 0, "three")
       SendMessage(List1, CB_ADDSTRING, 0, "four")
       SendMessage(List1, CB_ADDSTRING, 0, "five")
       SendMessage(List1, CB_ADDSTRING, 0, "six")
       SendMessage(List1, CB_ADDSTRING, 0, "seven")
       SendMessage(List1, CB_ADDSTRING, 0, "eight")
       SendMessage(List1, CB_ADDSTRING, 0, "nine")
       SendMessage(List1, CB_ADDSTRING, 0, "ten")
    
      return true

    case WM_COMMAND
       select case loword(wParam)
       
         case IDCANCEL
            EndDialog( hDlg, null )

         case IDOK
           'get index of List, zero-based
           int index = SendMessage(List1, CB_GETCURSEL, 0, 0)
           'get Text
           zstring buffer[80]
           int TxtLen = SendMessage(List1,CB_GETLBTEXTLEN, index, 0)                                           
           SendMessage(List1, CB_GETLBTEXT, index, @buffer)
           'get count of items
           int count = SendMessage(List1, CB_GETCOUNT, 0, 0)

           Result =
           "List count = " count & chr(13) & chr(10) &
           "Selected Item Index = " index+1 & chr(13) & chr(10) &
           "Selected Item Text = " buffer 

           mbox Result
          
       end select
  
    case WM_CLOSE
       EndDialog( hDlg, null )

  end select

  return 0
end function

sub winmain()

  Dialog( 0, 0, 100, 115, "Sorted ComboBox in a dialog",
          WS_OVERLAPPED or WS_SYSMENU or DS_CENTER )

  SortedCombo( "", ID_Combobox, 10, 10, 60, 70 )
  PushButton( "Info", ID_Info, 10, 85, 20, 12 )
  
  CreateModalDialog( null, @DialogProc, 0 )
end sub

winmain()
