//************************************************************************ BOOL CDib::LoadFromFile(LPCSTR lpFileName, BOOL fDecodeRLE) //************************************************************************ { FNAME szExpFileName; if ( !FindContent( (LPSTR)lpFileName, szExpFileName ) ) return(FALSE); HFILE fh; OFSTRUCT of; if ( (fh = OpenFile(szExpFileName, &of, OF_READ)) < 0 ) return(FALSE); if ( !(ReadBitmapInfo(fh)) ) return FALSE; // Can we get enough memory to hold the DIB bits DWORD dwBits; if ( !(m_lp = AllocX( dwBits = GetSizeImage(), GMEM_ZEROINIT )) ) { _lclose(fh); return( FALSE ); } // read in the bits _hread( fh, m_lp, dwBits ); _lclose( fh ); return(CheckDecodeRLE(fDecodeRLE)); }
HBITMAP ReadBitmapFile( HWND hwnd, char *file_name ) { FILE *fp; BITMAPFILEHEADER file_header; BITMAPINFOHEADER *h; /* to avoid typeing bitmap_info->... */ BITMAPINFO *bitmap_info; DWORD size; /* generic size - used repeatedly */ BYTE _HUGE *mask_ptr; /* pointer to bit array in memory */ HBITMAP bitmap_handle; HDC hdc; HPALETTE new_palette, old_palette; bitmap_handle = (HBITMAP)0; fp = fopen( file_name, "rb" ); if( fp == NULL ) return( bitmap_handle ); fread( &file_header, sizeof( BITMAPFILEHEADER ), 1, fp ); if( file_header.bfType != BITMAP_TYPE ) { fclose( fp ); return( bitmap_handle ); } bitmap_info = ReadBitmapInfo( fp ); if( bitmap_info != NULL ) { h = &bitmap_info->bmiHeader; fseek( fp, file_header.bfOffBits, SEEK_SET ); size = BITS_TO_BYTES( h->biWidth * h->biBitCount, h->biHeight ); #ifdef __NT__ mask_ptr = malloc( size ); memset( mask_ptr, 0, size ); #else mask_ptr = _halloc( size, 1 ); #endif if( mask_ptr != NULL ) { ReadInPieces( mask_ptr, fp, size ); new_palette = CreateDIBPalette( bitmap_info ); if( new_palette ) { hdc = GetDC( hwnd ); old_palette = SelectPalette( hdc, new_palette, FALSE ); RealizePalette( hdc ); bitmap_handle = CreateDIBitmap( hdc, h, CBM_INIT, mask_ptr, bitmap_info, DIB_RGB_COLORS ); SelectPalette( hdc, old_palette, FALSE ); DeleteObject( new_palette ); ReleaseDC( hwnd, hdc ); } #ifdef __NT__ free( mask_ptr ); #else _hfree( mask_ptr ); #endif } free( bitmap_info ); } fclose( fp ); return( bitmap_handle ); } /* ReadBitmapFile */