without type_check
include win32lib.ew
include res.e 
-- the two bitmaps, in a real .res file, this time. ( testres.res )
rFile( "undercon.bmp" )
rFile( "underco2.bmp" )

integer loopCount
-- increase this, if you have a super-puter.
loopCount=2000

constant
MyWin = create( Window, "Test  loadBmpResource", 0, 0, 0, 300, 100, 0 ), 
Bitmap1 = create(  Bitmap, "", MyWin, 5, 5, 40, 38, 0 ), 
Bitmap2 = create(  Bitmap, "", MyWin, 55, 5, 40, 38, 0 ), 
Labely  = create( LText, "", MyWin, 10, 50, 230, 20, 0 ), 

MyWin2 = create( Window, 
               "Test  rReadBmp/createDIB", 0, 0, 100, 300, 100, {WS_CAPTION} ), 
Bitmap3 = create(  Bitmap, "", MyWin2, 5, 5, 40, 38, 0 ), 
Bitmap4 = create(  Bitmap, "", MyWin2, 55, 5, 40, 38, 0 ), 
Labelz  = create( LText, "", MyWin2, 10, 50, 230, 20, 0 )

--pokes resource file to memory.
function pokeResource(  sequence fileName,  atom fSize )
  atom        image
  integer     hFile,  byte

  hFile = rOpen(  fileName,  "rb"  )
  image = allocate(  fSize  )
  for i = 0 to fSize-1 do
  byte = getc ( hFile )
  poke(  image+i,  byte  )
  end for
  close( hFile )
  return image
end function

--slightly modified loadBitmapFromFile2()
--reads BMP from resource file to memory.
--you MUST specify the bitmap size !
function loadBmpResource(  sequence fileName,  atom fSize )
  atom image,  bmInfoHeader,  bmBits,  bmColors,  hdc,  hDib

  image = pokeResource( fileName, fSize )
   
  bmInfoHeader = image + SIZEOF_BITMAPFILEHEADER
  bmBits = image + fetch(  image,  bfOffBits  ) 
  bmColors = bmInfoHeader + SIZEOF_BITMAPINFOHEADER
  hdc = getDC(  Screen  )

  hDib = w32Func(  xCreateDIBitmap,  {
  hdc, address(  bmInfoHeader,  bmiHeader  ), 
  CBM_INIT, 
  bmBits, 
  bmInfoHeader, 
  DIB_RGB_COLORS}  )
  releaseDC(  Screen  )
  free(  image  )
  return hDib
end function

atom ti,  map,  map2,  map5,  map6,  jk
sequence map3,  map4

procedure Start_up(  integer self,  integer event,  sequence params  )
setVisible( MyWin, 1 )
setVisible( MyWin2, 0 )
ti=time(  )
for i= 1 to loopCount do
  map=loadBmpResource(  "undercon.bmp",  892  )
  map2=loadBmpResource(  "underco2.bmp",  892  )
    if i < loopCount then
      jk = w32Func(  xDeleteObject, {map} )
      jk = w32Func(  xDeleteObject, {map2} )
    end if
end for
setBitmap(  Bitmap1,  map  )
setBitmap(  Bitmap2,  map2  )
repaintWindow( Bitmap1 )
repaintWindow( Bitmap2 )
setText( Labely, 
"bitmaps drawn in " & sprintf( "%3.2f", time(  )-ti ) & " seconds, " )
-- now show second window
setVisible( MyWin2, 1 )
ti=time(  )
for i= 1 to loopCount do
  map3=rReadBmp(  "undercon.bmp"  )
  map4=rReadBmp(  "underco2.bmp"  )
  map5=createDIB( map3 )
  map6=createDIB( map4 )
    if i < loopCount then
      deleteObject( map5 )
      deleteObject( map6 )
    end if
end for
setBitmap(  Bitmap3,  map5  )
setBitmap(  Bitmap4,  map6  )
repaintWindow( Bitmap3 )
repaintWindow( Bitmap4 )
setText( Labelz, 
"bitmaps drawn in " & sprintf( "%3.2f", time(  )-ti ) & " seconds, " )
end procedure

procedure kill_objects(  integer self,  integer event,  sequence params  )
   jk = w32Func(  xDeleteObject, {map} )
   jk = w32Func(  xDeleteObject, {map2} )
end procedure

setHandler(  MyWin,  w32HOpen,  routine_id(  "Start_up"  )  )
setHandler(  MyWin,  w32HDestroy,  routine_id( "kill_objects" )  )

WinMain( MyWin,  Normal )
--end--
