Click here to Skip to main content
15,886,664 members
Articles / Desktop Programming / MFC

Drawing with DirectDraw & GDI

Rate me:
Please Sign up or sign in to vote.
4.88/5 (11 votes)
24 May 2002 300.3K   13.8K   68  
Drawing Graphics fast with DirectDraw than with GDI
// Copyright (C) 1991 - 1999 Rational Software Corporation

#include "stdafx.h"
#include "CDDCanvasImpl.h"

NDDScreen* CDDCanvasImpl::m_pScreen = NULL;

CDDCanvasImpl::CDDCanvasImpl(CWnd* pWnd)
{
	m_pSurface = NULL;

	Create(pWnd);
}

//��������
HRESULT CDDCanvasImpl::Create(CWnd* pWnd)
{
	CRect rect;
	pWnd->GetWindowRect(rect);
	
	m_rcPosition = rect;
	m_nWidth = (rect.Width()+3)/4*4;
	m_nHeight = rect.Height();

	HWND hMainWnd = ::GetDesktopWindow();
	HWND hWnd	= pWnd->GetSafeHwnd();
	
	
	// ������Ļ����
	if(!m_pScreen)
	{
		m_pScreen = NDDScreen::Instance();
	}

	m_pScreen->SetHWnd(hWnd);
	//����Surface����
	if(!m_pSurface)
	{
		m_pSurface = new NDDSurface();
		m_pSurface->Create(m_pScreen, m_nWidth, m_nHeight);
	}
	m_bIsDBuffer = TRUE;
	return 0;
}


//##ModelId=3C1812A80174
//DEL HRESULT CDDCanvasImpl:: SetFont(LPCTSTR FontName , int Width , int Height , int Attributes)
//DEL {
//DEL 	m_pSurface->ChangeFont(FontName, Width, Height, Attributes);
//DEL 	return m_pSurface->SetFont();
//DEL }


//	���Ƶ�
//DEL HRESULT CDDCanvasImpl:: PutPixel (int X, int Y, DWORD Col)
//DEL {
//DEL 	return m_pSurface->PutPixel(X, Y, Col);
//DEL }

//	ȡ��ָ�������ɫ
//DEL DWORD CDDCanvasImpl::GetPixel (int X, int Y)
//DEL {
//DEL 	return m_pSurface->GetPixel(X, Y);
//DEL }

//	����: Rect
//	˵��: ���ƾ���
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: Rect (int X1, int Y1, int X2, int Y2, DWORD Col)
//DEL {
//DEL 	return m_pSurface->Rect(X1, Y1, X2, Y2, Col);
//DEL }

//	����: FillRect
//	˵��: ����������
//	����: 0 or > - �ɹ�
//	            < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: FillRect (int X1, int Y1, int X2, int Y2, DWORD Col)
//DEL {
//DEL 	return m_pSurface->FillRect(X1, Y1, X2, Y2, Col);
//DEL }

//	����: Line
//	˵��: ����ֱ��.
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: Line (int X1, int Y1, int X2, int Y2, DWORD Col)
//DEL {
//DEL 	return m_pSurface->Line(X1, Y1, X2, Y2, Col);
//DEL }

//	����: Circle
//	˵��: ����Բ��
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: Circle (int X, int Y, int Radius, DWORD Col)
//DEL {
//DEL 	return m_pSurface->Circle(X, Y, Radius, Col);
//DEL }

//	����: FillCircle
//	˵��: ����һ��������
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: FillCircle (int X, int Y, int Radius, DWORD Col)
//DEL {
//DEL 	return m_pSurface->FillCircle(X, Y, Radius, Col);
//DEL }

//	����: RoundedRect
//	˵��: ����Բ�Ǿ���
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: RoundedRect (int X1, int Y1, int X2, int Y2, int Radius, DWORD Col)
//DEL {
//DEL 	return m_pSurface->RoundedRect(X1, Y1, X2, Y2, Radius, Col);
//DEL }

//	����: Fill
//	˵��: ��ָ����ɫ��䱳��
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: Fill (DWORD FillColor)
//DEL {
//DEL 	return m_pSurface->Fill(FillColor);
//DEL }

//	����: TextXY
//	˵��: ��ָ��λ��������֣����ֱ���͸��
//	����: x - X ����
//	y       - Y ����
//	col     - ��ɫ.
//	pString - �ַ���
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//DEL HRESULT CDDCanvasImpl:: TextOut (int x, int y, COLORREF col, LPCTSTR pString)
//DEL {
//DEL 	return m_pSurface->TextXY(x, y, col, pString);
//DEL }

/////////////////////////
//	����: DrawText
//
//	˵��: ��ָ�������ڻ����Զ����е�����
//	����: pString - �ַ���
//	col     - ��ɫ
//	pRect   - �
//
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//
//	/////////////////////////////////////////////////////////
//	///////////////////////
//DEL HRESULT CDDCanvasImpl:: DrawText (LPCTSTR pString, COLORREF col, LPRECT pRect)
//DEL {
//DEL 	return m_pSurface->DrawText(pString, col, pRect);
//DEL }




//	///////////////////////
//	����: ClipRect
//	˵��: �޶��������
//	����: Rect - �޶��������
//	����: TRUE  - proceed with the draw operation
//	FALSE - after clipping there is �� to draw, exit
//	draw operation.
//DEL BOOL CDDCanvasImpl::ClipRect (RECT* Rect)
//DEL {
//DEL 	return m_pSurface->ClipRect(Rect);
//DEL }

//	����: Restore
//	˵��: ���涪ʧ��������ָ�����
//	����: ��
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��

HRESULT CDDCanvasImpl:: Restore ()
{
	m_pSurface->Restore();
	return 0;
}


//	����: Lock
//	˵��: �������棬�Ա�ֱ�ӷ��ʱ�������
//	����: ��
//	����: ��������    - �ɹ�
//	      < 0         - ʧ��
//	ע��: ʹ�ý�����Ҫ���˵���UnLock.
HRESULT CDDCanvasImpl:: Lock ()
{
	return m_pSurface->Lock();
}

//	����: UnLock
//	˵��: ȡ����������
//	����: ��
//	����: ��������    - �ɹ�
//	      < 0         - ʧ��
HRESULT CDDCanvasImpl:: UnLock ()
{
	return m_pSurface->UnLock();
}

//	����: GetDC
//	˵��: ȡ���豸�����ľ��
//	����: ��
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//	ע��:  ʹ����GDI������Ӧ����ReleaseDC
HDC CDDCanvasImpl::GetDC ()
{
	HDC hdc;
	hdc = m_pSurface->GetDC();
	return hdc;
		
}
//	����: ReleaseDC
//	˵��: �ͷ��豸������. Ӧ����ʹ��GetDC������Ӧ����ReleaseDC
//	����: ��
//	����: 0 or > - �ɹ�
//	      < 0    - ʧ��
//	ע��:  Ӧ����ʹ��GetDC������Ӧ����ReleaseDC
HRESULT CDDCanvasImpl::ReleaseDC()
{
	return m_pSurface->ReleaseDC();
	
}


// ȡ�ñ�������ָ��
//DEL void* CDDCanvasImpl::GetSurfacePointer ()
//DEL {
//DEL 	return m_pSurface->GetSurfacePointer();
//DEL }

// ȡ�òü���
LPRECT CDDCanvasImpl::GetClipRect ()
{
	return 0;//  [1/10/2002]m_pSurface->GetClipRect();
}

//	����: SetClipRect
//	˵��: ���òü���
//	����: clipRect - �ü���
//	����: ��
//	ע��: �ü������ܳ�������
//DEL void CDDCanvasImpl::SetClipRect (LPRECT lpClipRect)
//DEL {
//DEL 	m_pSurface->SetClipRect(lpClipRect);
//DEL }

//	����: GetFontName
//	˵��: ȡ����������
//DEL LPCTSTR CDDCanvasImpl::GetFontName ()
//DEL {
//DEL 	char name[256];
//DEL 	return m_pSurface->GetFontName(name);
//DEL }

//	����: GetSurfaceDescriptor
//	˵��:ȡ�ñ������
//	����: [out, retval]lpddsd 
//	����: ��
//DEL void CDDCanvasImpl::GetSurfaceDescriptor(LPDDSURFACEDESC2 lpddsd)
//DEL {
//DEL 	m_pSurface->GetSurfaceDescriptor(lpddsd);
//DEL }

//ȡ��DirectDraw����
LPDIRECTDRAWSURFACE7 CDDCanvasImpl::GetDDS ()
{
	return m_pSurface->m_lpDDS;
}

// ˢ��
HRESULT CDDCanvasImpl:: Refresh(LPRECT lpRect)
{
	HRESULT val;
	CRect rc = m_rcPosition;
	CRect temprc;
	if(lpRect != NULL)
	{
		temprc.OffsetRect(m_rcPosition.TopLeft());
		temprc.SetRect(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom);
	    lpRect = &temprc;
		ClipRect(lpRect);
	}

	rc.OffsetRect(2, 2);
	val = m_pScreen->m_lpDDSPrimary->Blt(&rc, m_pSurface->m_lpDDS, lpRect, DDBLT_WAIT, NULL);
	return val;

}
// TODO blt

//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Blt
// �������� : ��λͼ�ļ������ݶ���
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] LPRECT pDestRect
//          
// ��    �� : [in] LPRECT pSrcRect
//          
// ��    �� : [in] CONST VOID *lpBits
//          
// ��    �� : [in] CONST BITMAPINFO *lpBitsInfo
//          
HRESULT CDDCanvasImpl::Blt(LPRECT pDestRect, LPRECT pSrcRect, CONST VOID *lpBits, CONST BITMAPINFO *lpBitsInfo)
{
	
	HDC hDC = GetDC();
	::SetStretchBltMode(hDC, COLORONCOLOR);
	if ((RECTWIDTH(pDestRect)  == RECTWIDTH(pSrcRect)) &&
	   (RECTHEIGHT(pDestRect) == RECTHEIGHT(pSrcRect)))
	{
		::SetDIBitsToDevice(hDC,                    // hDC
						   pDestRect->left,             // DestX
						   pDestRect->top,              // DestY
						   RECTWIDTH(pDestRect),        // nDestWidth
						   RECTHEIGHT(pDestRect),       // nDestHeight
						   pSrcRect->left,				// SrcX
						   pSrcRect->top,				// SrcY
						   pSrcRect->top,               // nStartScan
						   RECTHEIGHT(pSrcRect),        // nNumScans
						   lpBits,                  // lpBits
						   lpBitsInfo,     // lpBitsInfo
						   DIB_RGB_COLORS);            // wUsage
	}
	else
	{

		::StretchDIBits(hDC, 
						pDestRect->left, 
						pDestRect->top, 
						RECTWIDTH(pDestRect),
						RECTHEIGHT(pDestRect),
						pSrcRect->left, 
						pSrcRect->top, 
						RECTWIDTH(pSrcRect),
						RECTHEIGHT(pSrcRect),
						lpBits, 
						lpBitsInfo, 
						DIB_RGB_COLORS,
						SRCCOPY);
		

		
	}

	ReleaseDC();
	return 0;
}
    


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::FillRect
// �������� : ������
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X1
//          
// ��    �� : [in] int Y1
//          
// ��    �� : [in] int X2
//          
// ��    �� : [in] int Y2
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::FillRect(int X1, int Y1, int X2, int Y2, DWORD Col)
{
	DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
    return m_pSurface->FillRect(X1,Y1,X2,Y2, color);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::FillCircle
// �������� : ���Բ��
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X
//          
// ��    �� : [in] int Y
//          
// ��    �� : [in] int Radius
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::FillCircle(int X, int Y, int Radius, DWORD Col)
{
    DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	return m_pSurface->FillCircle(X,Y,Radius,color);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::SetClipRect
// �������� : ���òü����
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : void 
//          
// ��    �� : [in] LPRECT lpClipRect
//          
void CDDCanvasImpl::SetClipRect(LPRECT lpClipRect)
{
   return;
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Circle
// �������� : 
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : ����Բ��
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X
//          
// ��    �� : [in] int Y
//          
// ��    �� : [in] int Radius
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::Circle(int X, int Y, int Radius, DWORD Col)
{

    DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	HRESULT hr;
    hr = m_pSurface->Circle(X,Y,Radius,color);
	return hr;
	
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Fill
// �������� : ��仭��
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::Fill(DWORD Col)
{
      DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	  m_pSurface->Fill(color); 
	  return DD_OK;
          
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::PutPixel
// �������� : ��ҳ�����������
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int x
//          
// ��    �� : [in] int y
//          
// ��    �� : [in] DWORD Col
//          
 HRESULT CDDCanvasImpl::PutPixel(int x, int y, DWORD Col)
{
     
	 DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col)); 
	 HRESULT val;  
	 Lock();
	 val = m_pSurface->PutPixel(x,y,color);
	 UnLock();
     return val;
}



//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::BltFast
// �������� : ���������洫�͵���������
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] NDDSurface *lpDDSurface
//          
HRESULT CDDCanvasImpl::BltFast(NDDSurface *lpDDSurface)
{
  return m_pScreen->m_lpDDSPrimary->Blt(NULL,lpDDSurface->m_lpDDS,NULL,NULL,NULL);
}


CDDCanvasImpl::~CDDCanvasImpl()
{
	
}




//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::DrawText
// �������� : ��ҳ���ϻ����ַ���
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] LPCSTR pString
//          
// ��    �� : [in] COLORREF col
//          
// ��    �� : [in] LPRECT pRect
//          
HRESULT CDDCanvasImpl::DrawText(LPCSTR pString, COLORREF col, LPRECT pRect)
{
	//DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	return m_pSurface->DrawText(pString,col,pRect);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::LoadBitmap
// �������� : �Ӵ����ж���λͼ��ʽ���ļ�����ʾ
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] const char *szFilename
//          
HRESULT CDDCanvasImpl::LoadBitmap(const char *szFilename)
{
   if(m_bIsDBuffer)
	   return m_pSurface->LoadBitmap(szFilename);
   else
	   return m_pScreen->LoadBitmap(szFilename);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::GetPixel
// �������� : ȡ��������ɫֵ
// ��    �� : 2002-2-27
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : DWORD 
//          
// ��    �� : [in] int X
//          
// ��    �� : [in] int Y
//          
DWORD CDDCanvasImpl::GetPixel(int X, int Y)
{
   HRESULT val;
   Lock();
   val = m_pSurface->GetPixel(X,Y);
   UnLock();
   return val;
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Rect
// �������� : ���ƾ���
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X1
//          
// ��    �� : [in] int Y1
//          
// ��    �� : [in] int X2
//          
// ��    �� : [in] int Y2
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::Rect(int X1, int Y1, int X2, int Y2, DWORD Col)
{
    DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	return m_pSurface->Rect(X1,Y1,X2,Y2,color);
}

char* CDDCanvasImpl::GetFontName(char *name)
{
   return m_pSurface->GetFontName(name);
}

void CDDCanvasImpl::GetSurfaceDescriptor(LPDDSURFACEDESC2 lpddsd)
{
    
	memcpy(lpddsd,&m_pSurface->m_DDSD,sizeof(DDSURFACEDESC2));
	
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Line
// �������� : ����ֱ�ߣ���������
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X1
//          
// ��    �� : [in] int Y1
//          
// ��    �� : [in] int X2
//          
// ��    �� : [in] int Y2
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::Line(int X1, int Y1, int X2, int Y2, DWORD Col)
{
	DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	return m_pSurface->AALine(X1,Y1,X2,Y2,color);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::ClipRect
// �������� : �ü����
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : BOOL 
//          
// ��    �� : [in] RECT *Rect
//          
BOOL CDDCanvasImpl::ClipRect(RECT *Rect)
{
	return m_pSurface->ClipRect(Rect);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::GetSurfacePointer
// �������� : ȡ��ָ��ҳ���ָ��
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : void* 
//          
void* CDDCanvasImpl::GetSurfacePointer()
{
   return m_pSurface->GetSurfacePointer();
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::RoundedRect
// �������� : ����Բ�Ǿ���
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int X1
//          
// ��    �� : [in] int Y1
//          
// ��    �� : [in] int X2
//          
// ��    �� : [in] int Y2
//          
// ��    �� : [in] int Radius	Բ�ǰ뾶
//          
// ��    �� : [in] DWORD Col
//          
HRESULT CDDCanvasImpl::RoundedRect(int X1, int Y1, int X2, int Y2, int Radius, DWORD Col)
{
    DWORD color = RGB(GetBValue(Col), GetGValue(Col), GetRValue(Col));
	return m_pSurface->RoundedRect(X1,Y1,X2,Y2,Radius,color);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::SaveAsBMP
// �������� : �����ݴ��λͼ
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] const char *szFilename
//          
HRESULT CDDCanvasImpl::SaveAsBMP(const char *szFilename)
{
   return m_pSurface->SaveAsBMP(szFilename);
}



//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::TextOut
// �������� : ��ָ��λ������ַ���
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] int x
//          
// ��    �� : [in] int y
//          
// ��    �� : [in] COLORREF col
//          
// ��    �� : [in] LPCTSTR pString
//          
HRESULT CDDCanvasImpl::TextOut(int x, int y, COLORREF col, LPCTSTR pString)
{
   return m_pSurface->TextOut(x,y,col,pString);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Release
// �������� : ��ձ������
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
HRESULT CDDCanvasImpl::Release()
{
    HRESULT val;
	val = m_pSurface->Release();
	if(m_pSurface !=NULL)
	{
		delete m_pSurface;
		m_pSurface = NULL;
	}
	return val;
}



//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Blt
// �������� : ��һ��������������blt����һ������������
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] CCanvasImpl *pDestcanvas
//          
// ��    �� : [in] LPRECT pDestRect
//          
// ��    �� : [in] LPRECT pSrcRect
//          
HRESULT CDDCanvasImpl::Blt(CCanvasImpl *pDestcanvas, LPRECT pDestRect, LPRECT pSrcRect)
{
	
	return m_pSurface->Blt(pDestcanvas->GetDDS(),pDestRect,pSrcRect);
}

CDDCanvasImpl::CDDCanvasImpl(CWnd *pWnd, int Width, int Height, int BPP)
{
   	m_pSurface = NULL;

	Create(pWnd,Width,Height,BPP);
}


//////////////////////////////////////////////////////////////////
// �� �� �� : CDDCanvasImpl::Create
// �������� : ����Screen��Surface����
// ��    �� : 2002-3-18
//----------------------------------------------------------------
// �� �� �� : 
// �� �� ֵ : HRESULT 
//          
// ��    �� : [in] CWnd *pWnd
//          
// ��    �� : [in] int Width
//          
// ��    �� : [in] int Height
//          
// ��    �� : [in] int BPP		������ɫλ��
//          
HRESULT CDDCanvasImpl::Create(CWnd *pWnd, int Width, int Height, int BPP)
{
	ASSERT(Width>0 && Height>0);
	
//    CRect rect;
//	pWnd->GetWindowRect(rect);
//	
//	m_rcPosition = rect;


	m_rcPosition.left = 0;
	m_rcPosition.top = 0;
	m_rcPosition.right = Width;
	m_rcPosition.bottom = Height;


	
	m_nWidth = Width;
	m_nHeight = Height;
	
	// ������Ļ����
	if(!m_pScreen)
	{
		m_pScreen = NDDScreen::Instance();
//		m_pScreen->SetHWnd(pWnd->GetSafeHwnd());
	}
	if(!m_pSurface)
	{
		m_pSurface = new NDDSurface();
		m_pSurface->Create(m_pScreen, m_nWidth, m_nHeight,BPP);
	}
	m_bIsDBuffer = TRUE;
	return 0;
}



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions