  ' -- gdip load image from file, adepted gdiplus, oxygen
  ' -- halProment Basic, 25+27-07-2024, 18-08-2024,frank bruebach
  '  
  take promplus
  take promgui
  take promImg

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

  long     hstatus
  long     pGraphics,pImage,pBitmap,pStream,pThumbnail
  wstring  strFileName
  long     nThumbnailWidth,nThumbnailHeight,nwidth,nheight
  '
  hStatus = GdipCreateFromHDC hdc, pGraphics
  '
  ' // Create an image and a thumbnail of the image.
  '
  strFileName = "genuss.jpg" ' take and load an image of your choice 
  hStatus = GdipLoadImageFromFile strFileName, pImage
  hStatus = GdipGetImageThumbnail pImage,70, 50, 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
  ''
  ' // Cleanup
  '
  if pThumbnail
    GdipDisposeImage pThumbnail
  endif
  if pImage
     GdipDisposeImage pImage
  endif
  if pBitMap
    GdipDisposeImage pBitMap
  endif
  if pGraphics
    GdipDeleteGraphics pGraphics
  endif
  end sub

  long 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
  '==============================================================================================================


  long 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

  long 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 = 600 : Wht = 440
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"Image Load Test",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 

  '--------------------------------------------------------------------------------------------------------------------------
  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
    RECT crect 

    '==========
    select wMsg
    '==========
        
      '--------------
      case WM_CREATE
      '=============

      ''long hTimer = SetTimer (hWnd, IDC_TIMER, 100, &TimerProc)
      GetClientRect  hWnd,&cRect

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

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

      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_KEYDOWN
      '==============

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

	Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0  

        Case 80 
          SaveClientImage hwnd
       End Select
       '
      '--------        
      case else
      '========
          
        function=DefWindowProc hWnd,wMsg,wParam,lParam
    end select

  end function 

  WinMain inst,0,cmdline,SW_NORMAL
   ' ends
