📄 cegdiobject.cpp
字号:
/* ---------------------------------------------------------------------------------------------------
*
* Windows CE Graphics Libary v1.00.0000
*
*
* Written by James.
* Bug report : jiet@msn.com
* Copyright 2001
*/
// File : CEGDIObject.CPP
// Graphics Object define.
//-----------------------------------------------------------------------------------------------------
// Update Information.
//-----------------------------------------------------------------------------------------------------
/*
* Created by James D. 2001.
* Date: 01/11/2001
*/
#include "StdAfx.h"
#include "CEGDIObject.h"
#include "CEDraw.h"
/*----------------------------------- Pen Class ------------------------------- */
//
// Function : CCEPen()
// Purpose : Construction function.
//
CCEPen::CCEPen( UINT nPenStyle, UINT nWidth, unsigned short Color )
{
m_dwObjectType = CEG_GDIOBJECT_TYPE_PEN;
m_nPenStyle = nPenStyle;
m_nWidth = nWidth;
m_Color = Color;
}
CCEPen::CCEPen()
{
m_nPenStyle = 0;
m_nWidth = 1;
m_Color = 0;
m_dwObjectType = CEG_GDIOBJECT_TYPE_PEN;
}
//
// Function : ~CCEPen()
// Purpose : Destruction function.
//
CCEPen::~CCEPen()
{
}
//
// Function : CreatePen()
// Purpose : Create the pen and set items' style
//
BOOL CCEPen::CreatePen( UINT nPenStyle, UINT nWidth, unsigned short Color )
{
m_nPenStyle = nPenStyle;
m_nWidth = nWidth;
m_Color = Color;
return TRUE;
}
/*----------------------------------- Brush Class ------------------------------- */
//
// Function : CCEBrush()
// Purpose : Construction function.
//
CCEBrush::CCEBrush( UINT nBrushStyle, unsigned short Color, long lbHatch )
{
m_dwObjectType = CEG_GDIOBJECT_TYPE_BRUSH;
m_nBrushStyle = nBrushStyle;
m_lbHatch = lbHatch;
m_Color = Color;
}
CCEBrush::CCEBrush()
{
m_nBrushStyle = 0;
m_lbHatch = 0;
m_Color = 0;
m_dwObjectType = CEG_GDIOBJECT_TYPE_BRUSH;
}
//
// Function : ~CCEPen()
// Purpose : Destruction function.
//
CCEBrush::~CCEBrush()
{
}
//
// Function : CreatePen()
// Purpose : Create the pen and set items' style
//
BOOL CCEBrush::CreateBrush( UINT nBrushStyle, unsigned short Color, long lbHatch )
{
m_dwObjectType = CEG_GDIOBJECT_TYPE_BRUSH;
m_nBrushStyle = nBrushStyle;
m_lbHatch = lbHatch;
m_Color = Color;
return TRUE;
}
/*----------------------------------- Font Class ------------------------------- */
//
// Function : CCEFont()
// Purpose : Construction function.
//
CCEFont::CCEFont()
{
m_hFont = NULL;
}
//
// Function : ~CCEFont()
// Purpose : Destruction function.
//
CCEFont::~CCEFont()
{
if( NULL != m_hFont )
{
::DeleteObject( m_hFont );
}
}
//
// Function : CreateFont()
// Purpose : Create the Font
//
BOOL CCEFont::CreateFont( int nHeight,
int nWidth,
int nEscapement,
int nOrientation,
int nWeight,
BYTE bItalic,
BYTE bUnderline,
BYTE cStrikeOut,
BYTE nCharSet,
BYTE nOutPrecision,
BYTE nClipPrecision,
BYTE nQuality,
BYTE nPitchAndFamily,
LPCTSTR lpszFacename )
{
LOGFONT logFont;
logFont.lfHeight = nHeight;
logFont.lfWidth = nWidth;
logFont.lfEscapement = nEscapement;
logFont.lfOrientation = nOrientation;
logFont.lfWeight = nWeight;
logFont.lfItalic = bItalic;
logFont.lfUnderline = bUnderline;
logFont.lfStrikeOut = cStrikeOut;
logFont.lfCharSet = nCharSet;
logFont.lfOutPrecision = nOutPrecision;
logFont.lfClipPrecision = nClipPrecision;
logFont.lfQuality = nQuality;
logFont.lfPitchAndFamily = nPitchAndFamily;
memcpy( logFont.lfFaceName, lpszFacename, LF_FACESIZE );
m_hFont = ::CreateFontIndirect( &logFont );
if ( NULL == m_hFont ) return FALSE;
return TRUE;
}
BOOL CCEFont::CreateFontIndirect( const LOGFONT *lpFont )
{
m_hFont = ::CreateFontIndirect( lpFont );
if ( NULL == m_hFont ) return FALSE;
return TRUE;
}
/*----------------------------------- Bitmap Class ------------------------------- */
//
// Function : CCEBitmap()
// Purpose : Construction function.
//
CCEBitmap::CCEBitmap()
{
m_pBitmapBuffer = NULL;
m_nType = CEB_TYPE_BITMAP;
}
//
// Function : ~CCEFont()
// Purpose : Destruction function.
//
CCEBitmap::~CCEBitmap()
{
if( NULL != m_pBitmapBuffer )
{
free( m_pBitmapBuffer );
}
}
//
// Function : LoadBitmap()
// Purpose : Load the bitmap and translate to the GAPI recoginzlia memory buffer...
//
BOOL CCEBitmap::LoadBitmap( CCEDraw* pCEDraw, LPCTSTR lpszBitmapName )
{
HBITMAP hBitmap;
BITMAP Bitmap;
// Free the buffer, if it exist...
if( NULL != m_pBitmapBuffer )
{
free( m_pBitmapBuffer );
m_pBitmapBuffer = NULL;
}
// If the lpszBitmapName == NULL, that means we create a screen bitmap...
if( NULL == lpszBitmapName )
{
m_sizeBitmap.cx = pCEDraw->GetDisplayProperties().cxWidth;
m_sizeBitmap.cy = pCEDraw->GetDisplayProperties().cyHeight;
m_pBitmapBuffer = (unsigned char*)malloc( m_sizeBitmap.cx * m_sizeBitmap.cy * pCEDraw->GetDisplayProperties().cBPP / 8 );
memcpy( m_pBitmapBuffer, pCEDraw->GetBuffer(), m_sizeBitmap.cx * m_sizeBitmap.cy * pCEDraw->GetDisplayProperties().cBPP / 8 );
m_nType = CEB_TYPE_SCREENBUFFER;
return TRUE;
}
// First to load the bitmap from file...
hBitmap = (HBITMAP) LoadFile( lpszBitmapName );
//hBitmap =(HBITMAP)::LoadBitmap( GetModuleHandle( NULL ), MAKEINTRESOURCE(IDB_BITMAP1));
if( hBitmap == NULL )
{
// Failed to load the bitmap...
return FALSE;
}
GetObject( hBitmap, sizeof(BITMAP), &Bitmap );
// Creating new bitmap and receive pointer to it's bits.
HBITMAP hTargetBitmap;
unsigned char *pBuffer;
// Initilize DIBINFO structure
BITMAPINFO dibInfo;
dibInfo.bmiHeader.biBitCount = 24;
dibInfo.bmiHeader.biClrImportant = 0;
dibInfo.bmiHeader.biClrUsed = 0;
dibInfo.bmiHeader.biCompression = 0;
dibInfo.bmiHeader.biHeight = Bitmap.bmHeight;
dibInfo.bmiHeader.biPlanes = 1;
dibInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
dibInfo.bmiHeader.biSizeImage = Bitmap.bmWidth*Bitmap.bmHeight*3;
dibInfo.bmiHeader.biWidth = Bitmap.bmWidth;
dibInfo.bmiHeader.biXPelsPerMeter = 3780;
dibInfo.bmiHeader.biYPelsPerMeter = 3780;
dibInfo.bmiColors[0].rgbBlue = 0;
dibInfo.bmiColors[0].rgbGreen = 0;
dibInfo.bmiColors[0].rgbRed = 0;
dibInfo.bmiColors[0].rgbReserved = 0;
// Create bitmap and receive pointer to points into pBuffer
HDC hDC = ::GetDC(NULL);
ASSERT(hDC);
hTargetBitmap = CreateDIBSection( hDC,
(const BITMAPINFO*)&dibInfo,
DIB_RGB_COLORS,
(void**)&pBuffer,
NULL,
0
);
::ReleaseDC(NULL, hDC);
// Copy source bitmap into the target bitmap.
// Create 2 device contexts
HDC memDc;
if ( !( memDc = CreateCompatibleDC(NULL) ) )
{
DeleteObject( hBitmap );
DeleteObject( hTargetBitmap );
return FALSE;
}
HDC targetDc;
if ( !( targetDc = CreateCompatibleDC(NULL) ) )
{
DeleteDC( memDc );
DeleteObject( hBitmap );
DeleteObject( hTargetBitmap );
return FALSE;
}
// Select source bitmap into one DC, target into another
HBITMAP hOldBitmap1 = (HBITMAP)::SelectObject( memDc, hBitmap);
HBITMAP hOldBitmap2 = (HBITMAP)::SelectObject( targetDc, hTargetBitmap );
// Copy source bitmap into the target one
::BitBlt( targetDc, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, memDc, 0, 0, SRCCOPY );
// Create my own bitmap buffer use the GAPI recognized style...
// Free the memory if it exist...
int nX, nY;
unsigned short nColor;
int nBitmapYPitch = ((Bitmap.bmWidth*3)+3) & 0xfffc;
BOOL bReturn = TRUE;
if( NULL != m_pBitmapBuffer )
{
free( m_pBitmapBuffer );
m_pBitmapBuffer = NULL;
}
long cByte = pCEDraw->GetDisplayProperties().cBPP / 8;
m_sizeBitmap.cx = Bitmap.bmWidth;
m_sizeBitmap.cy = Bitmap.bmHeight;
m_pBitmapBuffer = (unsigned char*)malloc( Bitmap.bmWidth * Bitmap.bmHeight * cByte );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -