' clientdc01_wx-c.bas
#define DEBUG ' enable dprint(text) macro
#Include "inc/wx.bi"

dim shared as _wxPanel ptr Panel
Dim Shared as _wxApp   ptr App

Sub EventListener APICALL(event As _wxEvent Ptr,iListener as wxInt)
  ' allocate a client DC
  dim as _wxDC ptr dc = cptr(_wxDC ptr,wxClientDC_ctor2(Panel))
  ' use it
  wxDC_Clear(dc)
  for i as integer = 1 to 3
    wxDC_DrawCircle(dc, rnd*640, rnd*480, 1+rnd*240)
  next
  for i as integer = 1 to 30
    wxDC_DrawLine  (dc, rnd*640, rnd*480, rnd*640, rnd*480)
  next
  for i as integer = 1 to 10
    wxDC_DrawRotatedText(dc, wxString("Hello world!"), rnd*640, rnd*480, rnd*360)
  next
  ' release it
  wxDC_dtor(dc)
End Sub

function OnInit APICALL as wxBool
  dim as _wxFrame ptr Frame=wxFrame_ctor()
  wxFrame_Create(Frame,WX_NULL,-1,wxString("test for wxClientDC()"), _
                 -1,-1, 640,480, _
                 wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX _
                 Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)

  Panel = wxPanel_ctor2(Frame)
  
  dim as _wxButton ptr Button = wxButton_ctor()
  wxButton_Create(Button,Panel,,wxString("click me"), 70, 270, 250, 60)
  wxEvtHandler_proxy(Button, @EventListener)
  wxEvtHandler_Connect(Button, wxEvent_EVT_COMMAND_BUTTON_CLICKED())
  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()

 