Loads a bitmap from file and returns a handle.
LoadBmp() has been superseded by the LoadImage() API.
h%= LoadImage(0, file$, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
h%:bitmap handle
file$:sexp
LoadImage() loads the bitmap specified in file$ into memory. h% is then the handle of the bitmap and can, for example, be used for the Put and Stretch commands.
The application must call the FreeBmp h or the Windows API DeleteObject() function to delete each bitmap handle returned by the LoadImage function.
OpenW 1
Local h As Handle, n As Int32
// Find picture file
Local d$ = GetSetting("\\HKEY_CLASSES_ROOT\Applications\GfaWin32.exe\shell\open\command", , "")
If Left(d$, 1) = #34 Then d$ = Mid(d$, 2)
n = RInStr(d$, "\") : If n <> 0 Then d$ = Left(d$, n - 1)
If Not Exist(d$ & "\gfawintb.bmp") Then _
MsgBox("Can not locate gfawintb.bmp file"#13#10#13#10"Please manually place it in the GFABASIC32\Bin folder and try again.") : End
// Create Image OCX and load picture into object
Ocx Image img = "", 10, 10, 356, 16
h = LoadImage(0, d$ & "\gfawintb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
Set img.Picture = CreatePicture(h, False)
FreeBmp h
Do : Sleep : Until Me Is Nothing
GFA-BASIC 32 I/O routines are able to read ":Files", because they are implemented to recognize the leading colon as a resource or inline file. API functions don't know about this peculiar GFA-BASIC 32 feature. To use API I/O functions the resource must first copied to a temporary file as in the function below:
Function LoadBmp(ByVal FName As String) As Handle
Try
If Left$(FName) <> ":" ' Load from normal file
LoadBmp = LoadImage(0, FName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
Else ' copy to Temp directory
Local path$ = TempFileName("")
CopyFile FName Over To path$
LoadBmp = LoadImage(0, path$, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
KillTempFile path$
EndIf
Catch
MsgBox "LoadBmp Error #" & Err.Number & #10 & Err.Description
EndCatch
EndFunction
File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.
Another way of loading in a Bitmap from file is to use LoadPicture.
TempFileName, FreeBmp, LoadPicture, Put, Stretch
{Created by Sjouke Hamstra; Last updated: 12/10/2014 by James Gaite}