' buttonarray_wx-c.bas
#define DEBUG ' eanble dprint(string) macro
#include once "inc/wx.bi"

const MAX_BUTTONS = 10
dim shared as _wxButton ptr Button(MAX_BUTTONS-1)
dim shared as _wxApp    ptr App


sub EventListener APICALL(event as _wxEvent ptr, iListener as wxInt)
  dprint("EventListener")
  static as wxInt nClicks(MAX_BUTTONS-1)
  dim as wxInt id = wxEvent_GetId(event)
  nClicks(id)+=1
  wxWindow_SetLabel(Button(id),wxString("nClick " & nClicks(id)))
end sub

function OnInit APICALL as wxBool
  dim as _wxFrame ptr Frame = wxFrame_ctor()
  wxFrame_Create(Frame,WX_NULL,-1,wxString("wxFrame"),-1,-1, 150,50+MAX_BUTTONS*40, wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER,WX_NULL)

  dim as _wxPanel ptr Panel = wxPanel_ctor2(Frame)
  for i as integer =0 to MAX_BUTTONS-1
    Button(i) = wxButton_ctor()
    wxButton_Create(Button(i),Panel,i,wxString("Button " & str(i+1)),10,10+i*40,120,30,wxNO_BORDER)
    wxEvtHandler_proxy(Button(i), @EventListener)
    wxEvtHandler_Connect(Button(i), wxEvent_EVT_COMMAND_BUTTON_CLICKED())
  next
  wxWindow_Show(Frame)
  return wxApp_OnInit(App)
end function

function OnExit APICALL as wxInt
  return wxApp_OnExit(App)
end function

' main
App = wxAPP_ctor()
wxAPP_RegisterVirtual(App,@OnInit,@OnExit)
wxApp_Run()