Beispiel #1
0
// Constructor.
KeyboardPage::KeyboardPage() 
{
	// Setup icon.
	m_nIcon = IDI_KEYBOARD;

	// Load bitmaps.
	m_hImages = ImageList_LoadImage( ClsGetResourceHandle(), MAKEINTRESOURCE( IDB_CLIST ), 16, 0, RGB( 255, 0, 255 ), IMAGE_BITMAP, LR_CREATEDIBSECTION);
	m_hDisImages = ImageList_LoadImage( ClsGetResourceHandle(), MAKEINTRESOURCE( IDB_CLIST_GRAY ), 16, 0, RGB( 255, 0, 255 ), IMAGE_BITMAP, LR_CREATEDIBSECTION);
}
Beispiel #2
0
// Load a bitmap.
BOOL ClsBitmap::LoadBitmap( LPCTSTR pszBitmap )
{
	// Attach the loaded bitmap.
	UINT uFlags = ( pszBitmap && HIWORD( pszBitmap ) == 0 ) ? 0 : LR_LOADFROMFILE;
	Attach( ::LoadImage( ClsGetResourceHandle(), pszBitmap, IMAGE_BITMAP, 0, 0, uFlags ));
	return ( BOOL )( m_hGdiObject ? TRUE : FALSE );
}
Beispiel #3
0
// Load a mapped bitmap.
BOOL ClsBitmap::LoadMappedBitmap( LPCTSTR pszBitmap, UINT nFlags, LPCOLORMAP pColorMap /* = NULL */, int nMapSize /* = 0 */ )
{
	// Valid name?
	if ( pszBitmap )
	{
		// From the resources?
		if ( HIWORD( pszBitmap ) == 0 )
			// Attach the mapped bitmap.
			Attach( ::CreateMappedBitmap( ClsGetResourceHandle(), ( UINT )pszBitmap, nFlags, pColorMap, nMapSize ));
		else
		{
			// Load the bitmap from the file. This code is based on the code
			// from "Creating a bitmap object from a BMP file - Zafir Anjum (1998/08/05)"
			// at www.codeguru.com.
			ClsFile	file;
			HBITMAP	hBitmap = NULL;
			HGLOBAL hDIB = NULL;
			int nColors = 0;

			try
			{
				// Open the file.
				file.Open( pszBitmap, ClsFile::fileRead | ClsFile::fileShareRead );

				// Read the file header.
				BITMAPFILEHEADER        bmfHeader;
				file.Read( &bmfHeader, sizeof( bmfHeader ));

				// Is the file of the right type?
				if ( bmfHeader.bfType == (( WORD )( 'M' << 8 ) | 'B' ))
				{
					// Allocate memory for the file.
					DWORD nPackedDIBLen = file.GetFileSize( NULL ) - sizeof( BITMAPFILEHEADER );
					hDIB = ::GlobalAlloc( GMEM_FIXED, nPackedDIBLen );
					if ( hDIB )
					{
						// Read the entire file.
						file.Read( hDIB, nPackedDIBLen );

						// Cast pointers.
						LPBITMAPINFOHEADER      pbmiHeader = ( LPBITMAPINFOHEADER )hDIB;
						LPBITMAPINFO            pbmInfo    = ( LPBITMAPINFO )hDIB;

						// Determine the amount of colors present.
						nColors = pbmiHeader->biClrUsed ? pbmiHeader->biClrUsed : 1 << pbmiHeader->biBitCount;
						LPVOID lpDIBBits;

						// Get a pointer to the "real" bitmap bits.
						if ( pbmInfo->bmiHeader.biBitCount > 8 )
							lpDIBBits = ( LPVOID )(( LPDWORD )( pbmInfo->bmiColors + pbmInfo->bmiHeader.biClrUsed ) +
								    (( pbmInfo->bmiHeader.biCompression == BI_BITFIELDS ) ? 3 : 0 ));
						else
							lpDIBBits = ( LPVOID )( pbmInfo->bmiColors + nColors );

						// 256 colors or less. Higher color bitmaps do not carry
						// color information. These bitmaps are mapped via the
						// GetMappedBitmap() method.
						if ( nColors <= 256 && pColorMap )
						{
							COLORREF        cr;
							int             i, a;

							// Iterate colors.
							for ( i = 0 ; i < nColors; i++ )
							{
								// Create a COLORREF from the entry.
								cr = RGB( pbmInfo->bmiColors[ i ].rgbRed, pbmInfo->bmiColors[ i ].rgbGreen, pbmInfo->bmiColors[ i ].rgbBlue );

								// Iterate the color map.
								for ( a = 0; a < nMapSize; a++ )
								{
									// Map this color?
									if ( cr == pColorMap[ a ].from )
									{
										// Map the color.
										pbmInfo->bmiColors[ i ].rgbRed   = GetRValue( pColorMap[ a ].to );
										pbmInfo->bmiColors[ i ].rgbGreen = GetGValue( pColorMap[ a ].to );
										pbmInfo->bmiColors[ i ].rgbBlue  = GetBValue( pColorMap[ a ].to );
										break;
									}
								}
							}
						}

						// Create a display DC.
						ClsDC dc;
						if ( dc.CreateDC( _T( "DISPLAY" ), NULL, NULL, NULL ))
						{
							// Create the bitmap.
							hBitmap = CreateDIBitmap( dc,
										  pbmiHeader,
										  CBM_INIT,
										  lpDIBBits,
										  pbmInfo,
										  DIB_RGB_COLORS );
							// Release the DC.
							dc.DeleteDC();
						}
					}
					// Free the memory.
					::GlobalFree( hDIB );
				}
				// Attach the bitmap.
				if ( hBitmap )
				{
					// Attach the bitmap.
					Attach( hBitmap );

					// If the DIB does not have a colormap we map all
					// the bits by calling the GetMappedBitmap() method.
					if ( nColors > 256 && pColorMap && nMapSize )
					{
						// Create the mapped version and replace the current
						// bitmap by the mapped one.
						HBITMAP hMapped = GetMappedBitmap( pColorMap, nMapSize );
						if ( hMapped )
						{
							Delete();
							Attach( hMapped );
							return TRUE;
						}
						return FALSE;
					}
					return TRUE;
				}
				return FALSE;
			}
			catch( ClsFileException& )
			{
				if ( hDIB ) ::GlobalFree( hDIB );
				return FALSE;
			}
			catch( ClsMemoryException& )
			{
				return FALSE;
			}
		}
	}
	return FALSE;
}
Beispiel #4
0
// Create a mapped bitmap.
BOOL ClsBitmap::CreateMappedBitmap( int idBitmap, UINT nFlags, LPCOLORMAP pColorMap /* = NULL */, int nMapSize /* = 0 */ )
{
	// Attach the bitmap.
	Attach( ::CreateMappedBitmap( ClsGetResourceHandle(), idBitmap, nFlags, pColorMap, nMapSize ));
	return ( BOOL )( m_hGdiObject ? TRUE : FALSE );
}