  #case capital
  def NULL null
  uses MinWin
  uses FileDialogs
  uses ImgWin
  '
  'default image file setup
  =========================
  wstring strFileName = "../images/Dawn1815.jpg"
  '
  string filter="*.jpg"
  string idir=""
  string title="Load Image"
  string name=""
  sys hWnd=0
  sys flags=0
  sys saves=0
  string ifile
  '
  'Function FileDialog(string iDir, filter, Title,Name, sys Hwnd, Flags,saves) As String
  'ifile=FileDialog(idir,filter,title,name,  hWnd,Flags,saves)
  '
  if ifile
    strFileName=ifile
  endif


  #lookahead ' for procedures

  '------------------------------
  sub GetImages(sys hwnd,sys hdc)
  '==============================

  sys     hstatus
  sys     pGraphics,pImage,pBitmap,pStream,pThumbnail
  sys     nThumbnailWidth,nThumbnailHeight,nwidth,nheight
  '
  hStatus = GdipCreateFromHDC hdc, pGraphics
  '
  ' // Create an image and a thumbnail of the image.
  '
  hStatus = GdipLoadImageFromFile strFileName, pImage
  hStatus = GdipGetImageThumbnail pImage, 40, 40, pThumbnail, NULL, NULL
  '
  ' // Draw the original and the thumbnail images.
  '
  hStatus = GdipGetImageWidth pImage, nWidth
  hStatus = GdipGetImageHeight pImage, nHeight
  hStatus = GdipGetImageWidth pThumbnail, nThumbnailWidth
  hStatus = GdipGetImageHeight pThumbnail, nThumbnailHeight
  '
  '
  'DRAW IMAGES
  '
  hStatus = GdipDrawImageRect pGraphics, pThumbnail, 10, 10, nThumbnailWidth, nThumbnailHeight
  hStatus = GdipDrawImageRectI pGraphics, pImage, 10, 60, nWidth, nHeight
  '
  '
  'http://www.jose.it-berater.org/smfforum/index.php?topic=1860.0
  'http://www.jose.it-berater.org/smfforum/index.php?topic=1861.0
  ' /jpeg /png /gif /tiff /bmp
  'if pBitMap<>0 then SaveImage "tim50.jpg","image/jpeg",50,pBitMap 'itr trap param mismatch
  '
  ' // Cleanup
  '
  if pThumbnail
    GdipDisposeImage pThumbnail
  endif
  if pImage
     GdipDisposeImage pImage
  endif
  if pBitMap
    GdipDisposeImage pBitMap
  endif
  if pGraphics
    GdipDeleteGraphics pGraphics
  endif

  '
  end sub




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

  sys inst,hdc
  
  dim cmdline as asciiz ptr,inst as long
  &cmdline=GetCommandLine
  inst=GetModuleHandle 0


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


  sys hr,hdlg,token
  GdiplusStartupInput StartupInput

  StartupInput.GdiplusVersion = 1
  hr=GdiplusStartup token, StartupInput, byval 0
  '
  if hr
    print "Error initializing GDIplus: " hex hr
    exit function
  end if


  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
  '
  bool bRet
  '
  do while bRet := GetMessage (&wm, 0, 0, 0)
    if bRet = -1
      'show an error message
      exit while
    else
      TranslateMessage &wm
      DispatchMessage &wm
    end if
  wend

  GdiplusShutdown token

  End Function 



  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
 
    '==========
    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
      'DrawText hDC,"Hello",-1,&cRect,0x25
      GetImages hWnd,hDC
      'refreshes+=1
      EndPaint hWnd,&Paintst
      'ValidateRect hwnd,&crect 

      '----------------- 
      'case WM_ERASEBKGND
      '=================

      'RECT r
      'GetClientRect hWnd,r
      'GetImages hWnd,hDC
      'InvalidateRect( hWnd,@r,0 )
      'return 1

      '--------------   
      case WM_KEYDOWN
      '==============

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

        Case 0x4f  'O Open
          ifile=FileDialog(idir,filter,title,name,  hWnd,Flags,0)
          if iFile 
            StrFileName=iFile
            GetClientRect  hWnd,&cRect
            InvalidateRect hWnd,&crect
          endif

        Case 0x53 'S Save
          ifile=FileDialog(idir,filter,title,name,  hWnd,Flags,1)
          if iFile 
            SaveClientImage(hwnd,iFile)
          endif
    

	Case 27   : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

        Case 80 ' P TO CAPTURE WINDOW IMAGE
          SaveClientImage hwnd
       End Select
       '

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

  end function ' WndProc

  WinMain inst,0,cmdline,SW_NORMAL
 