Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

LOADPICTURE(), SAVEPICTURE()

These two functions let you manipulate graphic images in a format compatible with ActiveX controls.

Usage

oPicture = LoadPicture( cPathAndFileName )
lSuccess = SavePicture( oPicture, cPathAndFileName )

Parameter

Value

Meaning

cPathAndFileName

Character

A character expression specifying the file to load or save, respectively.

oPicture

Object

An object reference to a loaded graphic resource that can be used with an ActiveX control.

lSuccess

.T.

The file was saved successfully.

.F.

If the drive or path doesn't exist, or there's no disk in the drive, we get an error rather than a return value of .F. The only time we get a return value of .F. is when the function writes a 0 byte file; see bug, below.

SAVEPICTURE() has a fatal flaw. Attempting to save to a completely full diskette locks VFP 6 without an error message. Fortunately, this has been fixed in VFP 7. It saves a 0-byte file onto the diskette instead, and returns .F.

In versions prior to VFP 7, LOADPICTURE() gives an "illegal file descriptor" (VFP 5) or an "Unknown COM Status code 0x800a01e1" (VFP 6) error if you try to load a file that's included in the running APP or EXE. It does so even if the file also physically exists on disk. This is a biggie: It means you can't include image files in the EXE but must ship them as separate files. The bitmaps can be listed in the Project Manager as long as they're marked as Excluded.

Fortunately, VFP 7 no longer errors if you load a file that is in the running APP or EXE and also exists on the disk. The file built into the APP or EXE is used; not the one on the user's disk.

These two functions are intended for use with ActiveX controls, such as the ImageList, that require graphic resources to display. Rather than accepting file names, these controls need object handles. These functions supply that handle and can save the resulting file if passed a handle. The object created is a curious one, lacking the usual VFP object properties of Class, BaseClass and Name, because it is more of an OLE object than a VFP one. This object does have several properties worth examining:

Property

Value

Meaning

Height, Width

Numeric

The picture's dimensions, measured in twips. Twips are 1/20th of a point, which is 1/72nd of an inch.

Type

Numeric

The source of the picture:
1—bitmap (BMP, JPG, GIF)
2—metafile (WMF)
3—icon (ICO)
4—enhanced metafile (EMF)

hPal

Binary Numeric

A handle to the associated palette.

The FoxhWnd control, first included with VFP 5.0, allows the display of GIF and JPG bitmaps within the VFP 5.0 environment if you pass it an object reference created with LOADPICTURE(). LOADPICTURE() also works with Windows metafiles (WMF), enhanced metafiles (EMF) and icons.

Example

oPicture = LOADPICTURE(HOME()+"fox.BMP")
lSuccess = LOADPICTURE(oPicture, HOME()+"newfox.bmp")

See Also

GetPict(), PutFile()