📄 vmdib.cpp
字号:
/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: handles device independant bitmaps both to the screen and
the printer
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/
#include "../../../stdafx.h"
#include "VMDib.h"
static DWORD dwOffset;
static RECT rcClip;
static BOOL bMemoryDIB = TRUE; // Load Entire DIB into memory in CF_DIB format
static BOOL bLegitDraw = FALSE; // We have a valid bitmap to draw
static HANDLE hdibCurrent = NULL; // Handle to current memory DIB
static HANDLE hbiCurrent = NULL; // Handle to current bitmap info struct
/*****************************************************************************/
/*
FUNCTION NAME: PrintTheBitMap
DESCRIPTION:
INPUT: ps -
OUTPUT: none
RETURNS: TRUE if worked, FALSE if not
*/
BOOL WINAPI PrintTheBitMap( PRTTYPE* ps )
{
BITMAPINFOHEADER bi;
RECT Rect;
if ( InitDIB( ps )==FALSE )
{
return( FALSE );
}
DibInfo( hbiCurrent, &bi );
if ( !IsRectEmpty( &rcClip ) )
{
bi.biWidth = rcClip.right - rcClip.left;
bi.biHeight = rcClip.bottom - rcClip.top;
}
// Fix bounding rectangle for the picture ..
//
Rect.top = ps->rc.top;
Rect.left = ps->rc.left;
Rect.bottom = ps->rc.bottom-ps->rc.top;
Rect.right = ps->rc.right-ps->rc.left;
ps->rc.right = Rect.right;
ps->rc.bottom = Rect.bottom;
// ... and inform the driver
//
ps->pDC->Escape( SET_BOUNDS, sizeof( RECT ), (LPSTR)&Rect, NULL );
PrintDIB( ps, ps->rc.left, ps->rc.top, ps->rc.right, ps->rc.bottom );
FreeDib();
return( TRUE );
}
/* End of function "PrintTheBitMap"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: ScreenPrintTheBitMap
DESCRIPTION:
INPUT: ps -
OUTPUT: none
RETURNS: TRUE if worked, FALSE if not
*/
BOOL WINAPI ScreenPrintTheBitMap( PRTTYPE* ps )
{
BITMAPINFOHEADER bi;
RECT Rect;
if ( hbiCurrent == NULL )
{
if ( InitDIB( ps ) == FALSE )
{
return( FALSE );
}
}
DibInfo( hbiCurrent, &bi );
if ( !IsRectEmpty( &rcClip ) )
{
bi.biWidth = rcClip.right - rcClip.left;
bi.biHeight = rcClip.bottom - rcClip.top;
}
// Fix bounding rectangle for the picture ..
//
Rect.top = ps->rc.top;
Rect.left = ps->rc.left;
Rect.bottom = ps->rc.bottom-ps->rc.top;
Rect.right = ps->rc.right-ps->rc.left;
// ... and inform the driver
//
ps->pDC->Escape( SET_BOUNDS, sizeof( RECT ), (LPSTR)&Rect, NULL );
PrintDIB( ps, ps->rc.left, ps->rc.top, (int)bi.biWidth, (int)bi.biHeight );
return( TRUE );
}
/* End of function "ScreenPrintTheBitMap"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: InitDIB
DESCRIPTION:
INPUT: ps -
OUTPUT: none
RETURNS: TRUE if worked, FALSE if not
*/
int WINAPI InitDIB( PRTTYPE* ps )
{
unsigned fh;
BITMAPINFOHEADER bi;
OFSTRUCT of;
FreeDib();
// Open the file and get a handle to it's BITMAPINFO
//
fh = OpenFile( (LPCSTR)ps->Text, (LPOFSTRUCT)&of, OF_READ );
if ( fh == -1 )
{
return( FALSE );
}
hbiCurrent = ReadDibBitmapInfo(fh);
dwOffset = _llseek( fh, 0L, SEEK_CUR );
_lclose( fh );
if ( hbiCurrent == NULL )
{
return( FALSE );
}
DibInfo( hbiCurrent,&bi );
bLegitDraw = TRUE;
// If the input bitmap is not in RGB FORMAT the banding code will
// not work! we need to load the DIB bits into memory.
// if memory DIB, load it all NOW! This will avoid calling the
// banding code.
//
if ( bMemoryDIB || bi.biCompression != BI_RGB )
{
hdibCurrent = OpenDIB( ps->Text );
}
// If the RLE could not be loaded all at once, exit gracefully NOW,
// to avoid calling the banding code
//
if ( ( bi.biCompression != BI_RGB ) && !hdibCurrent )
{
FreeDib();
return( FALSE );
}
return( TRUE );
}
/* End of function "InitDIB"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: FreeDib
DESCRIPTION:
INPUT: void -
OUTPUT: none
RETURNS: void
*/
void WINAPI FreeDib( void )
{
if ( hdibCurrent )
{
GlobalFree( hdibCurrent );
}
if ( hbiCurrent && hbiCurrent != hdibCurrent )
{
GlobalFree( hbiCurrent );
}
bLegitDraw = FALSE;
hdibCurrent = NULL;
hbiCurrent = NULL;
SetRectEmpty( &rcClip );
}
/* End of function "FreeDib"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: PrintDIB
DESCRIPTION:
INPUT: ps -
x -
y -
dx -
dy -
OUTPUT:
RETURNS: void
*/
void WINAPI PrintDIB( PRTTYPE *ps, int x, int y, int dx, int dy )
{
BITMAPINFOHEADER bi;
int dibX;
int dibY;
int dibDX;
int dibDY;
if ( !bLegitDraw )
{
return;
}
DibInfo( hbiCurrent, &bi );
if ( IsRectEmpty( &rcClip ) )
{
dibX = 0;
dibY = 0;
dibDX = (int)bi.biWidth;
dibDY = (int)bi.biHeight;
}
else
{
dibX = rcClip.left;
dibY = (int)bi.biHeight - 1 - rcClip.bottom;
dibDX = rcClip.right - rcClip.left;
dibDY = rcClip.bottom - rcClip.top;
}
if ( hdibCurrent )
{
// Stretch the DIB to printer DC
//
StretchDibBlt( ps->pDC->GetSafeHdc(),
x,
y,
dx,
dy,
hdibCurrent,
dibX,
dibY,
dibDX,
dibDY,
SRCCOPY );
}
}
/* End of function "PrintDIB"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: OpenDIB
DESCRIPTION:
INPUT: szFile -
OUTPUT: none
RETURNS: HANDLE
*/
HANDLE WINAPI OpenDIB( LPCSTR szFile )
{
unsigned fh;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen = 0;
DWORD dwBits;
HANDLE hdib;
HANDLE h;
OFSTRUCT of;
// Open the file and read the DIB information
//
fh = OpenFile( szFile, &of, OF_READ );
if ( fh == -1 )
{
return( NULL );
}
hdib = ReadDibBitmapInfo( fh );
if ( !hdib )
{
return( NULL );
}
DibInfo( hdib,&bi );
// Calculate the memory needed to hold the DIB
//
dwBits = bi.biSizeImage;
dwLen = bi.biSize + (DWORD)PaletteSize (&bi) + dwBits;
// Try to increase the size of the bitmap info. buffer to hold the DIB
//
h = GlobalReAlloc( hdib, dwLen, GHND );
if ( !h )
{
GlobalFree( hdib );
hdib = NULL;
}
else
{
hdib = h;
}
// Read in the bits
//
if ( hdib )
{
lpbi = (LPBITMAPINFOHEADER)GlobalLock( hdib );
lread( fh, (LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize( lpbi ), dwBits );
GlobalUnlock( hdib );
}
_lclose( fh );
return( hdib );
}
/* End of function "OpenDIB"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: DibInfo
DESCRIPTION:
INPUT: hbi -
lpbi -
OUTPUT:
RETURNS: BOOL
*/
BOOL WINAPI DibInfo( HANDLE hbi, LPBITMAPINFOHEADER lpbi )
{
if ( hbi )
{
*lpbi = *(LPBITMAPINFOHEADER)GlobalLock( hbi );
// fill in the default fields
//
if ( lpbi->biSize != sizeof( BITMAPCOREHEADER ) )
{
if ( lpbi->biSizeImage == 0L )
{
lpbi->biSizeImage = WIDTHBYTES( lpbi->biWidth * lpbi->biBitCount ) * lpbi->biHeight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -