Images, Icons and Cursors

Top  Previous  Next

Loading an image

EBASIC can load an image, icon or cursor with the LOADIMAGE function. LOADIMAGE returns a handle to the loaded image as an unsigned integer value. This value can then be passed to any of the functions that accepts a handle as a parameter. The syntax of LOADIMAGE is:

handle = LOADIMAGE (filename | resource ID, type)

Type is a numeric value defining what kind of image to load.

The valid values for type are:

@IMGBITMAP - bitmap (*.bmp)

@IMGICON - Icon (*.ico)

@IMGCURSOR - Cursor (*.cur)

@IMGEMF - Enhanced meta file (*.emf)

@IMGSCALABLE - scalable bitmap, JPEG (*.jpg) or GIF (*.gif) files.

@IMGOEM - OR in with @IMGBITMAP, @IMGICON or @IMGCURSOR to load an OEM (system) image.

@IMGMAPCOLORS - OR in with @IMGBITMAP to have the system search the bitmap color table and map the following shades of grey:

Dk Gray, RGB(128,128,128)

3DSHADOW COLOR

Gray, RGB(192,192,192)

3DFACE COLOR

Lt Gray, RGB(223,223,223)

3DLIGHT COLOR

The mapping of colors with @IMGMAPCOLORS  is used in loading toolbars and button images so the current system colors are used for 3D elements.

If a filename is specified the image is loaded from disk. EBASIC can also load bitmaps, icons and cursors directly from the executables resources. Enhanced meta files cannot be loaded from the resource table. Scalable images may be loaded from resources as custom type @RTIMAGE.

Resource ID is either the string or integer identifier of a resource compiled with the project.

Freeing the image

After your program is finished with an image it should call the DELETEIMAGE statement to free memory used by the image.  The syntax of DELETEIMAGE is:

DELETEIMAGE handle, type

Type must be the same value specified in the LOADIMAGE function.

Displaying the image

An image can be drawn in a window using the SHOWIMAGE statement. SHOWIMAGE can draw images, icons and enhanced metafiles. The syntax of SHOWIMAGE is:

SHOWIMAGE window, handle, type, x, y , {w, h{, flags}}

Type is the same value specified in the LOADIMAGE statement. x and y specify the upper left corner of the image. W and h specify the width and height of the image or EMF file. The flags variable is for advanced users and are passed directly to the Windows function BitBlt.

If the image type equals 4 then SHOWIMAGE will show a JPEG, GIF or bitmap and w,h will scale the image to the width and height specified. If w and h are omitted the exact size of the image will be used with no scaling.

Width and Height must be specified for bitmap files.

Changing cursors

The currently displayed cursor in a window can be changed with the SETCURSOR statement. The syntax of SETCURSOR is:

SETCURSOR window, style {, handle}

Valid values for style are @CSWAIT for a wait cursor, @CSARROW for the standard arrow cursor and @CSCUSTOM for a cursor loaded with the LOADIMAGE function.

Changing icons

The current icon for a window, displayed in the titlebar and taskbar, can be changed with the SETICON statement. SETICON accepts a handle from the LOADIMAGE function. The syntax of SETICON is:

SETICON window, handle

See Also: The samples bitmap.eba and imgview.eba for examples of using the image functions.