

  Declare Function Rectangle Lib "gdi32.dll" (ByVal hdc as long, ByVal X1 as long, ByVal Y1 as long, ByVal X2 as long, ByVal Y2 as long) as long
  Declare Function Ellipse Lib   "gdi32.dll" (ByVal hdc as long, ByVal X1 as long, ByVal Y1 as long, ByVal X2 as long, ByVal Y2 as long) as long


  #lookahead ' for procedures

  % ID_Timer            3000
  % Interval            100



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

  sys xmax,ymax,r,idx,idy,xball,yball
  '
  r=15 : idx=5 : idy=5 : xball=200 : yball=100  


  '--------------------------------------------------------------------------------------------------------------
  Function WinMain(byval inst as long,byval prevInst as long,byval cmdline as asciiz, byval show as long) as long
  '==============================================================================================================


  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 =@"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 = -1 then
      'show an error message
      exit while
    else
      TranslateMessage &wm
      DispatchMessage &wm
    end if
  wend

  End Function 



  dim as rect crect 'for WndProc and TimerProc

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

    static as Long count=0, refreshes=0, hdc
    static as String txt
    static as PaintStruct Paintst
    static as sys htimer
 
    '==========
    select wMsg
    '==========
        
      '--------------
      case WM_CREATE
      '=============

      hTimer = SetTimer (hWnd, ID_Timer, 100, &TimerProc)
      GetClientRect  hWnd,&cRect

      '--------------
      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)
       'print txt
       'DrawText hDC,"Hello World",-1,&cRect,0x25
       DrawText hDC,*txt,-1,&cRect,0x25
       refreshes+=1
       Ellipse hdc, xball-r, yball-r, xball+r, yball+r
       'Ellipse hdc, xball, yball, xball+20, yball+30
       EndPaint hWnd,&Paintst
       ValidateRect hwnd,&crect 
        
      '--------------   
      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


  '-----------------------------------------------------------------------------------------------------------------------------
  Function TimerProc(BYVAL hWnd AS DWORD, byval wMsg as DWORD, BYVAL nIDEvent AS LONG, BYVAL dwTime AS DWORD)  as long 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

   end select
 
 
  End Function ' TimerProc
 