EasyBMP C++ Bitmap Library

EasyBMP Extensions: win32

This extension to EasyBMP provides some basic interfaces to the win32 API.

Click here to download the extension. (Contained in the extensions package)

The first few functions are to convert between HBITMAP and BMP objects:

bool HBITMAPtoBMP(HDC hDC,HBITMAP hBitmap,BMP& OutputImage);
HBITMAP BMPtoHBITMAP(HDC hDC,BMP& Input);

Use the first function convert the HBITMAP object hBitmap (which is assumed to have been created with the device context with handle hDC) to the BMP object OutputImage. The function returns a boolean true if it succeeds and false otherwise. Here's a sample usage:

HBITMAP hSomeBitmap;
HDC hSomeDeviceContext;
...
BMP SomeNewBMP;
HBITMAPtoBMP( hSomeDeviceContext, hSomeBitmap, hSomeNewBMP );
hSomeNewBMP.WriteToFile( "output.bmp" );

The second function is to convert a given BMP object to an HBITMAP object with a given HDC device context. Here's a sample usage:

BMP SomeBMP;
HDC hSomeDeviceContext;
...
HBITMAP hNewBitmap = BMPtoHBITMAP( hSomeDeviceContext, SomeBMP );

The next several functions deal with window and screen captures:

bool CaptureScreen( BMP& OutputImage );
bool CaptureWindow( HWND hWND , BMP& OutputImage );
bool CaptureForegroundWindow( BMP& OutputImage );

All three capture the desired window or screen to the BMP object OutputImage. The first captures the entire screen. The second captures the window with handle hWND. The last captures whatever window is in the foreground. All three functions return a boolean true if they succeed and false otherwise. For example:

BMP ScreenImage;
CaptureScreen( ScreenImage );
ScreenImage.WriteToFile( "Screencap.bmp" );