How to Send an HBITMAP to Windows API Function Calls from VB

ID Number: Q71260

1.00

WINDOWS

Summary:

Several Windows API functions require the HBITMAP data type. Visual

Basic does not have a HBITMAP data type. This article explains how to

send the equivalent Visual Basic HBITMAP handle of a picture control

to a Windows API function call.

This information applies to Microsoft Visual Basic Programming System

version 1.00 for Windows.

More Information:

The HBITMAP data type represents a 16-bit index to GDIs physical

drawing object. Several Windows API routines need the HBITMAP data

type as an argument. Sending the [picture-control].Picture as an

argument is the equivalent in Visual Basic.

The code sample below demonstrates how to send HBITMAP to the Windows

API function ModifyMenu.

Declare Function SetMenuItemBitMaps% Lib "user" (ByVal hMenu%,

ByVal nPos%,

ByVal wFlag%,

ByVal BitmapUnChecked%,

ByVal hBitmapChecked%)

Note: The above Declare statement must be written on just one line.

The SetMenuItemBitMap takes five arguments. The fourth and fifth

arguments are HBITMAP data types.

The following code segment will associate the specified bitmap

Picture1.Picture in place of the default check mark:

X% = SetMenuItemBitMap(hMenu%, menuID%,0,0, Picture1.Picture)

Reference:

1. "Programming Windows: the Microsoft Guide to Writing Applications

for Windows 3," by Charles Petzold (published by Microsoft

Press, 1990)

2. "Microsoft Windows 3.0 Software Development Kit: Reference

Volume 1"

3. The WINSDK.HLP file shipped with Microsoft Windows 3.0 Software

Development Kit.