[windows] CatchImage() replacement for bitmaps
Posted: Thu Jul 10, 2003 8:26 pm
Code updated for 5.20+ (same as CatchImage())
I often use the image lib only to include bitmaps inside my exes, i always look for the smallest exe size so i did this proc to get rid of the image lib, not very tested but seems to work.
To use it should be something like:
hwnd=openwindow..
hdc=getdc_(hwnd)
hbm=CatchBMP(hdc,?Lbitmap ) ;hbm used as image ID
;free bitmap
deleteobject_(hbm)
Lbitmap : includebinary "c:\yourbitmap.bmp"
I often use the image lib only to include bitmaps inside my exes, i always look for the smallest exe size so i did this proc to get rid of the image lib, not very tested but seems to work.
Code: Select all
;CatchBMP : Creates a compatible bitmap(DDB) from a DIB bitmap inside an exe.
;hdc : window DC , returned by GetDC() API
;bmpaddress : address of bitmap inside executable
;Returns : bitmap handle
;Remarks : use DeleteObject() API with the bitmap handle to free it.
;Justin 07/03
procedure CatchBMP(hdc,bmpaddress)
;ptr to BITMAPFILEHEADER
*pbfileh.BITMAPFILEHEADER=bmpaddress
;ptr to BITMAPINFOHEADER
pbinfoh=bmpaddress + sizeof(BITMAPFILEHEADER)
;pointer to bitmap data
pbits=*pbfileh\bfOffBits ;offset
init=bmpaddress + pbits ;bitmap data
procedurereturn CreateDIBitmap_(hdc,pbinfoh,#CBM_INIT,init,pbinfoh,#DIB_RGB_COLORS)
endprocedure
hwnd=openwindow..
hdc=getdc_(hwnd)
hbm=CatchBMP(hdc,?Lbitmap ) ;hbm used as image ID
;free bitmap
deleteobject_(hbm)
Lbitmap : includebinary "c:\yourbitmap.bmp"