Click here to Skip to main content
15,891,136 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.4K   13.8K   68  
Drawing Graphics fast with DirectDraw than with GDI
// DDScreen.h: interface for the NDDScreen class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DDSCREEN_H__56754101_B8D4_427F_9D31_51B88DBF0432__INCLUDED_)
#define AFX_DDSCREEN_H__56754101_B8D4_427F_9D31_51B88DBF0432__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <ddraw.h>
#include "DDSurface.h"


typedef struct 
{
    DWORD Width;
    DWORD Height;
    DWORD BPP;
    void* NextMode;
}NDD_VIDEOMODESSTRUCT;


#ifndef MAX_DDDEVICEID_STRING
	#define MAX_DDDEVICEID_STRING 512
#endif

#define NDD_DDVER		0x0700    //Currently support DirectX 7
// structure for direct draw drivers
struct NDD_DRIVERSTRUCT
{
	LPGUID	lpGUID;
	GUID	guid;
	char	lpName[MAX_DDDEVICEID_STRING];
	char	lpDesc[MAX_DDDEVICEID_STRING];
	DDCAPS	DDcaps;
    DDCAPS  HELcaps;

#if DIRECTDRAW_VERSION >= NDD_DDVER
	HMONITOR hMonitor;
#endif

	NDD_DRIVERSTRUCT *NextDriver;
};
		
// callback function for video mode enumeration, implemented in ddutils.cpp
HRESULT CALLBACK EnumDisplayModesCallback( LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext  );

// callback function for devices enumeration, implemented in ddutils.cpp
#if DIRECTDRAW_VERSION >= NDD_DDVER
BOOL WINAPI DDEnumCallback( GUID FAR *lpGUID, LPSTR lpDesc, LPSTR lpName, LPVOID lpContext, HMONITOR hm );
#else
BOOL WINAPI DDEnumCallback( GUID FAR *lpGUID, LPSTR lpDesc, LPSTR lpName, LPVOID lpContext );
#endif

class NDDScreen  
{
public:
	~NDDScreen();

	static NDDScreen* Instance();

	
	void SetPalette(int Start, int Count, LPPALETTEENTRY lpPE);
	void GetPalette(int Start, int Count, LPPALETTEENTRY lpPE);
	void SetHWnd(HWND hWnd){m_lpClipper->SetHWnd(0, hWnd);};

	void GreyScale(void);
    
	int GetWidth(void) { return m_dwPixelWidth; }
	int GetHeight(void) { return m_dwPixelHeight; }
	int GetBPP(void) { return m_BPP; }
	LPDIRECTDRAW7 GetDDraw(void) { return m_lpDD; }
	LPDIRECTDRAWPALETTE GetPalette(void) { return m_lpDDPalette; }
	

public:
	void RestoreScreen();
	HRESULT DDCopyBitmap(LPDIRECTDRAWSURFACE7 pdds, HBITMAP hbm, int x, int y, int dx, int dy);
	HRESULT DDReLoadBitmap(LPDIRECTDRAWSURFACE7 pdds, LPCSTR szBitmap);
	HRESULT LoadBitmap(const char* szFilename);
	BOOL GetRGBFormat( LPDIRECTDRAWSURFACE7 Surface, RGBFORMAT* rgb);
	void SetSurfacePixelFormat(NDDSurface* surface);
	void SetSurfaceScreen(NDDSurface* surface);
	BOOL ClipRect(RECT *Rect);
	BOOL ValidateBlt(NDDSurface* lpCDXS, int *lDestX, int *lDestY, RECT *srcRect);
	HRESULT DrawBlk(NDDSurface *offSurface, int left, int top, LPRECT lpRect);
	void Fill(DWORD FillColor);
	HWND m_hWnd;
	LPDIRECTDRAW7		m_lpDD;
	LPDIRECTDRAWSURFACE7 m_lpDDSPrimary;
	LPDIRECTDRAWPALETTE m_lpDDPalette;
	LPDIRECTDRAWCLIPPER m_lpClipper;

protected:
	RECT m_ClipRect;
	NDDScreen();
	BOOL Create();
	static NDDScreen* m_pScreen;

	DWORD m_dwPixelWidth;
	DWORD m_dwPixelHeight;
	DWORD m_BPP;
};

#endif // !defined(AFX_DDSCREEN_H__56754101_B8D4_427F_9D31_51B88DBF0432__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