⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cegdiobject.cpp

📁 windows mobile应用的图形库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ---------------------------------------------------------------------------------------------------
 *  
 *                          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.
//
void CCEPen_Create(C_Class CCEPen* objthis)
{
	if(!objthis)
		return;
	objthis->m_nPenStyle = 0;
	objthis->m_nWidth = 1;
	objthis->m_Color = 0;
	objthis->m_dwObjectType = CEG_GDIOBJECT_TYPE_PEN;
	objthis->gthis = objthis;
}

BOOL CreatePen(C_Class CCEPen* objthis, UINT nPenStyle, UINT nWidth, unsigned short Color )
{
	if(!objthis)
		return FALSE;

	objthis->m_nPenStyle = nPenStyle;
	objthis->m_nWidth = nWidth;
	objthis->m_Color = Color;
	objthis->m_dwObjectType = CEG_GDIOBJECT_TYPE_PEN;

	return TRUE;
}





/*----------------------------------- Brush Class ------------------------------- */

//
// Function : CCEBrush()
// Purpose  : Construction function.
//
void CCEBrush_Create(C_Class CCEBrush* objthis)
{
	if(!objthis)
		return;

	objthis->m_nBrushStyle = 0;
	objthis->m_lbHatch = 0;
	objthis->m_Color = 0;
	objthis->m_dwObjectType = CEG_GDIOBJECT_TYPE_BRUSH;
	objthis->gthis = objthis;
}

BOOL CreateBrush(C_Class  CCEBrush* objthis, UINT nBrushStyle, unsigned short Color, long lbHatch )
{
	if(!objthis)
		return FALSE;

	objthis->m_nBrushStyle = nBrushStyle;
	objthis->m_Color = Color;
	objthis->m_lbHatch = lbHatch;
	objthis->m_dwObjectType = CEG_GDIOBJECT_TYPE_BRUSH;

	return TRUE;
}

/*----------------------------------- Font Class ------------------------------- */


//
// Function : CCEFont()
// Purpose  : Construction function.
//
void CCEFont_Create(C_Class CCEFont* objthis)
{
	if(!objthis)
		return;
	objthis->m_hFont = NULL;
	objthis->m_nColor = 0;
	objthis->gthis = objthis;
}

void CCEFont_Delete(C_Class CCEFont* objthis)
{
	if(objthis)
	{
		if((objthis->m_hFont) != NULL)
		{
			::DeleteObject(objthis->m_hFont);
		}
	}

}

//
// Function : CreateFont()
// Purpose  : Create the Font
//
BOOL CreateFont(C_Class CCEFont* objthis,
							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;
	if(objthis == NULL)
		return FALSE;
	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 );

	objthis->m_hFont = ::CreateFontIndirect( &logFont );
	if ( NULL == (objthis->m_hFont) ) return FALSE;

	return TRUE;
}

BOOL CreateFontIndirect(C_Class CCEFont* objthis, const LOGFONT *lpFont )
{
	if(objthis == NULL) return FALSE;
	objthis->m_hFont = ::CreateFontIndirect( lpFont );
	if ( NULL == (objthis->m_hFont) ) return FALSE;

	return TRUE;
}

/*----------------------------------- Bitmap Class ------------------------------- */


//
// Function : CCEBitmap()
// Purpose  : Construction function.
//
void CCEBitmap_Create(C_Class CCEBitmap* objthis)
{
	if(objthis == NULL) return;
	objthis->m_pBitmapBuffer = NULL;
	objthis->m_nType = CEB_TYPE_BITMAP;
	objthis->gthis = objthis;
}

void CCEBitmap_Delete(C_Class CCEBitmap* objthis)
{
	if(objthis == NULL) return;
	if(objthis->m_pBitmapBuffer != NULL)
		free(objthis->m_pBitmapBuffer);
}


//
// Function : LoadBitmap()
// Purpose  : Load the bitmap and translate to the GAPI recoginzlia memory buffer...
//
BOOL LoadBitmap(C_Class CCEBitmap* objthis, CCEDraw* pCEDraw, LPCTSTR lpszBitmapName )
{
	HBITMAP hBitmap;
	BITMAP  Bitmap;
	if(objthis == NULL)
		return FALSE;

	// Free the buffer, if it exist...
	if( NULL != objthis->m_pBitmapBuffer ) 
	{
		free( objthis->m_pBitmapBuffer );
		objthis->m_pBitmapBuffer = NULL;
	}

	// If the lpszBitmapName == NULL, that means we create a screen bitmap...
	if( NULL == lpszBitmapName )
	{
		objthis->m_sizeBitmap.cx = pCEDraw->GetDisplayProperties().cxWidth;
		objthis->m_sizeBitmap.cy = pCEDraw->GetDisplayProperties().cyHeight;
		objthis->m_pBitmapBuffer = (unsigned char*)malloc( (objthis->m_sizeBitmap.cx) * (objthis->m_sizeBitmap.cy) * pCEDraw->GetDisplayProperties().cBPP / 8 );
		memcpy( objthis->m_pBitmapBuffer, pCEDraw->GetBuffer(), (objthis->m_sizeBitmap.cx) * (objthis->m_sizeBitmap.cy) * pCEDraw->GetDisplayProperties().cBPP / 8 );
		objthis->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 != objthis->m_pBitmapBuffer ) 
	{
		free( objthis->m_pBitmapBuffer );
		objthis->m_pBitmapBuffer = NULL;
	}

	long cByte = pCEDraw->GetDisplayProperties().cBPP / 8;
	objthis->m_sizeBitmap.cx = Bitmap.bmWidth;
	objthis->m_sizeBitmap.cy = Bitmap.bmHeight;
	objthis->m_pBitmapBuffer = (unsigned char*)malloc( Bitmap.bmWidth * Bitmap.bmHeight * cByte );
	if(NULL == objthis->m_pBitmapBuffer ) 
	{
		bReturn = FALSE;
		goto Exit;
	}

    /* Warning : Does not support 8 byte color model in here */
	for( nY = 0; nY < Bitmap.bmHeight ; nY ++ )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -