Click here to Skip to main content
15,884,976 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
// CanvasImpl.h: interface for the CCanvasImpl class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CANVASIMPL_H__539A45D2_94E9_43D7_B4E7_F9697CE4C412__INCLUDED_)
#define AFX_CANVASIMPL_H__539A45D2_94E9_43D7_B4E7_F9697CE4C412__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ddraw.h"
#define RECTWIDTH(lpRect)     ((lpRect)->right - (lpRect)->left)
#define RECTHEIGHT(lpRect)    ((lpRect)->bottom - (lpRect)->top)
//##ModelId=3C1812A80069
class CCanvasImpl  
{
public:
	
    

	virtual CDC* GetMemDC() = 0;
	//ҳ��λ����
	virtual HRESULT Blt(CCanvasImpl *pDestcanvas, LPRECT pDestRect, LPRECT pSrcRect)=0;
	
	//�������
	virtual HRESULT Release()=0;

    //��ָ��λ������ַ���
	virtual HRESULT TextOut (int x, int y, COLORREF col, LPCTSTR pString)=0;
	//��ҳ����λͼ��ʽ���ļ�
	virtual HRESULT SaveAsBMP(const char *szFilename)=0;
	//����Բ�Ǿ���
	virtual HRESULT RoundedRect(int X1, int Y1, int X2, int Y2, int Radius, DWORD Col)=0;
	
	//ȡ��ҳ��ָ��
	virtual void* GetSurfacePointer()=0;
	//���òü��������
	virtual BOOL ClipRect(RECT *Rect)=0;
	//����ֱ��
	virtual HRESULT Line(int X1, int Y1, int X2, int Y2, DWORD Col)=0;
	//ȡ��ҳ����
	virtual void  GetSurfaceDescriptor(LPDDSURFACEDESC2 lpddsd)=0;
	//ȡ��������
	virtual char* GetFontName(char *name)=0;
	//���ƾ���
    virtual HRESULT Rect(int X1, int Y1, int X2, int Y2, DWORD Col)=0;
	
	//ȡ��������ɫ
	virtual DWORD   GetPixel (int X, int Y)=0;
	
	//���������ɫ
	virtual HRESULT PutPixel(int X, int Y, DWORD Col)=0;
	
	//�Ӵ����ж���λͼ��ʽ���ļ�
	virtual HRESULT LoadBitmap(const char *szFilename)=0;
	
	//��������
	virtual HRESULT Create(CWnd* pWnd)=0;
    

	//##ModelId=3C1EE8910108
	virtual HRESULT Blt(LPRECT pDestRect, LPRECT pSrcRect, CONST VOID *lpBits, CONST BITMAPINFO *lpBitsInfo)=0;
    

	//##ModelId=3C1812A80174
    

	//	���Ƶ�

	//	ȡ��ָ�������ɫ

	//	����: Rect
	//	˵��: ���ƾ���
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	//	����: FillRect
	//	˵��: ����������
	//	����: 0 or > - �ɹ�
	//	            < 0    - ʧ��
	virtual HRESULT FillRect (int X1, int Y1, int X2, int Y2, DWORD Col)=0;

	//	����: Line
	//	˵��: ����ֱ��.
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	//	����: Circle
	//	˵��: ����Բ��
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	//	����: FillCircle
	//	˵��: ����һ��������
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��
	virtual HRESULT FillCircle (int X, int Y, int Radius, DWORD Col)=0;

	//	����: RoundedRect
	//	˵��: ����Բ�Ǿ���
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	//	����: Fill
	//	˵��: ��ָ����ɫ��䱳��
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	//	����: TextXY
	//	˵��: ��ָ��λ��������֣����ֱ���͸��
	//	����: x - X ����
	//	y       - Y ����
	//	col     - ��ɫ.
	//	pString - �ַ���
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��

	/////////////////////////
	//	����: DrawText
	//
	//	˵��: ��ָ�������ڻ����Զ����е�����
	//	����: pString - �ַ���
	//	col     - ��ɫ
	//	pRect   - �
	//
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��
	//
	//	/////////////////////////////////////////////////////////
	//	///////////////////////


	//	///////////////////////
	//	����: ClipRect
	//	˵��: �޶��������
	//	����: Rect - �޶��������
	//	����: TRUE  - proceed with the draw operation
	//	FALSE - after clipping there is �� to draw, exit
	//	draw operation.

	//	����: Restore
	//	˵��: ���涪ʧ��������ָ�����
	//	����: ��
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��
	virtual HRESULT Restore ()=0;


	//	����: Lock
	//	˵��: �������棬�Ա�ֱ�ӷ��ʱ�������
	//	����: ��
	//	����: ��������    - �ɹ�
	//	      < 0         - ʧ��
	//	ע��: ʹ�ý�����Ҫ���˵���UnLock.
	virtual HRESULT Lock ()=0;

	//	����: UnLock
	//	˵��: ȡ����������
	//	����: ��
	//	����: ��������    - �ɹ�
	//	      < 0         - ʧ��
	virtual HRESULT UnLock ()=0;

	//	����: GetDC
	//	˵��: ȡ���豸�����ľ��
	//	����: ��
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��
	//	ע��:  ʹ����GDI������Ӧ����ReleaseDC
	virtual HDC GetDC ()=0;

	//	����: ReleaseDC
	//	˵��: �ͷ��豸������. Ӧ����ʹ��GetDC������Ӧ����ReleaseDC
	//	����: ��
	//	����: 0 or > - �ɹ�
	//	      < 0    - ʧ��
	//	ע��:  Ӧ����ʹ��GetDC������Ӧ����ReleaseDC
	virtual HRESULT ReleaseDC ()=0;

	// ȡ�û������
	virtual int GetWidth (){ return m_nWidth;}

	// ȡ�û����߶�
	virtual int GetHeight (){ return m_nHeight;}

	// ȡ�ñ�������ָ��

	// ȡ�òü���
	virtual LPRECT GetClipRect()=0;

	//	����: SetClipRect
	//	˵��: ���òü���
	//	����: clipRect - �ü���
	//	����: ��
	//	ע��: �ü������ܳ�������
	virtual void SetClipRect (LPRECT lpClipRect)=0;

	//	����: GetFontName
	//	˵��: ȡ����������

	//	����: GetSurfaceDescriptor
	//	˵��:ȡ�ñ������
	//	����: [out, retval]lpddsd 
	//	����: ��

	//ȡ��DirectDraw����
	virtual LPDIRECTDRAWSURFACE7 GetDDS ()=0;

	// ˢ��
	virtual HRESULT Refresh(LPRECT lpRect)=0;

	virtual HRESULT Circle(int X, int Y, int Radius, DWORD Col)=0;
    virtual HRESULT DrawText(LPCSTR pString, COLORREF col, LPRECT pRect)=0;
	virtual HRESULT Fill(DWORD color)=0;



protected:
	int m_nWidth;
	int m_nHeight;
	CRect m_rcPosition;
};

#endif // !defined(AFX_CANVASIMPL_H__539A45D2_94E9_43D7_B4E7_F9697CE4C412__INCLUDED_)

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