wpQueryBitmapHandle
This method is specific to Version 4, or higher, of the OS/2 operating system.
This instance method returns a handle to the bitmap that can be displayed showing the contents of the image file and a handle to the palette to be used when displaying the bitmap.
Syntax
_wpQueryBitmapHandle(somSelf, phBitmap, phPalette, ulWidth, ulHeight, ulFlags, lBackgroundColor, pbQuitEarly)
Parameters
- somSelf (WPBitmap *) - input
- Pointer to the object on which the method is being invoked.
- Points to an object of class WPBitmap.
- phBitmap (HBITMAP *) - in/out
- Pointer to the buffer to receive the handle of the bitmap.
- phPalette (HPAL *) - in/out
- Pointer to the buffer to receive the handle of the palette. If this parameter is **NULL**, no palette handle is returned.
- ulWidth (ULONG) - input
- Width of the bitmap. This parameter is required. If this parameter is 0, the bitmap will not be scaled.
- ulHeight (ULONG) - input
- Height of the bitmap. This parameter is required. If this parameter is 0, the bitmap will not be scaled.
- ulFlags (ULONG) - input
- Processing flags.
- lBackgroundColor (LONG) - input
- Color to be used for transparent pixels.
- pbQuitEarly (BOOL *) - in/out
- Buffer containing quit early flag. If this parameter is **NULL**, the caller will not be able to asynchronously abort the loading of the bitmap.
Returns
- rc (BOOL32) - returns
- Success indicator.
- TRUE Successful completion.
- FALSE Error occurred.
How to Override
This method must be overridden in any subclass of WPImageFile.
Usage
The Workplace Shell calls the **wpQueryBitmapHandle** method any time it needs to access the bitmap represented by a WPImageFile object.
Remarks
This example is a simplified version of the code in the **WPBitmap** class. The example does not build a color palette for the bitmap and does no scaling of the bitmap size. (In this code, **vhab** is a global variable that contains the handle for the HAB for the Workplace Shell and **RemoveBitmapFromMem** is a function that frees the specified Device Context, Presentation Space, Bitmap, and Palette.)
Example Code
SOM_Scope BOOL32 bmp_wpQueryBitmapHandle(WPBitmap *somSelf,
HBITMAP *phBitmap,
HPAL *phPalette,
ULONG ulWidth,
ULONG ulHeight,
ULONG ulFlags,
LONG lBackgroundColor,
BOOL *pbQuitEarly)
{
HDC hdc = NULLHANDLE;
HPS hps = NULLHANDLE;
union
{
PBITMAPFILEHEADER pbfh;
PBITMAPFILEHEADER2 pbfh2;
} pBitmapFileHeader;
union
{
PBITMAPINFOHEADER pbinfoh;
PBITMAPINFOHEADER2 pbinfoh2;
PBITMAPINFO2 pbinfo2;
} pBitmapInfoHeader;
SIZEL sizlSource;
/* Make sure the caller specified a place to return the bitmap handle */
if (!phBitmap)
{
return FALSE;
}
/* Set the returned bitmap and palette handles to NULLHANDLE in case
* this method fails */
*phBitmap = NULLHANDLE;
if (phPalette)
{
*phPalette = NULLHANDLE;
}
/* Read the bitmap file */
if (!_wpReadImageFile(somSelf))
{
return FALSE;
}
/* Create a device context and presentation space for the bitmap */
hdc = DevOpenDC (vhab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE);
if (hdc == DEV_ERROR)
{
return FALSE;
}
/*
* Create a new Presentation Space for the bitmap */
sizlSource.cx = 0;
sizlSource.cy = 0;
hps = GpiCreatePS (vhab,
hdc,
&sizlSource,
PU_PELS | GPIT_NORMAL | GPIA_ASSOC);
if(hps == GPI_ERROR)
{
RemoveBitmapFromMem(&hdc,NULL,NULL,NULL);
return FALSE;
}
/* Make sure there is no palette selected in the PS */
GpiSelectPalette(hps,NULLHANDLE);
/* Create the bitmap */
pBitmapFileHeader.pbfh = (PBITMAPFILEHEADER)
_wpQueryBitmapData(somSelf,NULL);
pBitmapInfoHeader.pbinfoh = &(pBitmapFileHeader.pbfh->bmp);
*phBitmap = GpiCreateBitmap (hps,
pBitmapInfoHeader.pbinfoh2,
CBM_INIT,
(PBYTE)pBitmapFileHeader.pbfh +
pBitmapFileHeader.pbfh->offBits,
pBitmapInfoHeader.pbinfo2);
if(!*phBitmap)
{
RemoveBitmapFromMem(&hdc,&hps,NULL,NULL);
return FALSE;
}
/*
* Select the bitmap into the presentation space */
GpiSetBitmap (hps, *phBitmap);
/* Clean up the resources we allocated */
RemoveBitmapFromMem(&hdc,&hps,NULL,NULL);
return !!*phBitmap;
}