
  $ filename "t.exe"
  'uses rtl32
  'uses rtl64
  'uses MinWin
  uses corewin



  'extern lib "gdi32.dll"
  'sys Rectangle (sys hdc,X1,Y1,X2,Y2)
  'sys Ellipse   (sys hdc,X1,Y1,X2,Y2)
  'end extern


  #lookahead ' for procedures

  % ID_Timer   3000
  % Interval   100



  '==================
  'GLOBAL DEFINITIONS
  '==================


  sys inst,hdc
  sys xmax,ymax,r,idx,idy,xball,yball

  r =15 : idx =5 : idy=5 : xball=200 : yball=100  



  '=========
  'MAIN CODE
  '=========
  
  dim cmdline as asciiz ptr,inst as sys
  &cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS
  '-------
  '
  WinMain inst,0,cmdline,SW_NORMAL
  
  endprog:


  '===========
  'END OF MAIN
  '===========


  '------------------------------------------------------------------
  Function WinMain(sys inst,prevInst,zstring*cmdline,sys show) as sys
  '==================================================================

  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax

  wc.style = CS_HREDRAW or CS_VREDRAW
  wc.lpfnWndProc = @WndProc 
  wc.cbClsExtra =0
  wc.cbWndExtra =0    
  wc.hInstance =inst
  wc.hIcon=LoadIcon 0, IDI_APPLICATION
  wc.hCursor=LoadCursor 0,IDC_ARROW
  wc.hbrBackground = GetStockObject WHITE_BRUSH 
  wc.lpszMenuName =0
  wc.lpszClassName = strptr "Demo"

  RegisterClass (&wc)
 
  Wwd = 800 : Wht = 600
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd

  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bret=0
      exit while
    end if
    if bRet = -1
      'show an error message
      exit while
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  end while
  End Function 



  dim as rect crect 'for WndProc and TimerProc

  '-------------------------------------------------------------
  function WndProc (sys hWnd,wMsg,wParam,lparam) as sys callback
  '=============================================================

    static as sys count=0, refreshes=0, hdc, htimer
    static as String txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
        
      '--------------
      case WM_CREATE
      '=============
      hTimer = SetTimer (hWnd, ID_Timer, 100, &TimerProc)
      GetClientRect  hWnd,&cRect
      % DC_BRUSH       = 18
      % DC_PEN         = 19
      static sys hPen  = GetStockObject(DC_PEN)
      static sys hBrush = GetStockObject(DC_BRUSH)


      '--------------
      case WM_TIMER
      '=============

      '--------------  
      case WM_DESTROY
      '===============
          
      KillTimer(hWnd,ID_TIMER)
      PostQuitMessage 0
        
      '------------
      case WM_PAINT
      '============

      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx


      hDC=BeginPaint hWnd,&Paintst
      GetClientRect  hWnd,&cRect
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       txt="x y pos" str(xball) " , " str(yball)
       'DrawText hDC,"Hello World",-1,&cRect,0x25
       DrawText hDC,strptr txt,-1,&cRect,0x25
       refreshes+=1

       SetDCPenColor hdc,0x00ff00
       SetDCBrushColor hdc,0x00ff00
       'CAN SELECT BOTH PEN AND BRUSH
       SelectObject hDC, hPen
       SelectObject hDC, hBrush
       Ellipse hdc, xball-r, yball-r, xball+r, yball+r
       MoveToEx hdc,xball,yball,Byval 0
       LineTo hdc,xball+r, yball+r
       EndPaint hWnd,&Paintst
        
      '--------------   
      case WM_KEYDOWN
      '==============

      '============            
      Select wParam
      '============

	Case 37 : xball -= idx   'LEFT
        Case 39 : xball += idx   'RIGHT
        Case 38 : yball -= idy   'UP
	Case 40 : yball += idy   'DOWN
	Case 32 : Rectangle hdc, -1, -1, xmax+1, ymax+1 'SPACE
	Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

       End Select
       '
       InvalidateRect hwnd, &cRect, 1 'FULL SCREEN REFRESH

      '--------        
      case else
      '========
          
        function=DefWindowProc hWnd,wMsg,wParam,lParam
        
    end select

  end function ' WndProc


  '----------------------------------------------------
  sys TimerProc(sys hWnd,wMsg,nIDEvent,dwTime) callback
  '====================================================
  {
   static sys d=1


   select wMsg
 
     Case WM_TIMER
 
      InvalidateRect hwnd,&crect,1
      if r=50 then d=-1
      if r=10 then d=1
      r+=d
      function = 0
 
   end select
 
 
  } ' TimerProc
 