genericthread.h

来自「windows ce开发技巧与实例光盘代码」· C头文件 代码 · 共 113 行

H
113
字号
// GenericThread.h: interface for the CGenericThread class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(GENERICTHREAD__INCLUDED_)
#define GENERICTHREAD__INCLUDED_

#pragma once

#include "GapiDraw.h"
#include "resource.h"
#include <afxmt.h> // CCriticalSection
#include "afxtempl.h"

enum
{
#ifdef _WIN32_WCE
		GAMEPARAM_FULLSCREEN  = 1,  // WINCE: Always use full screen on Windows CE
		GAMEPARAM_TARGETFPS   = 30  // WINCE: Target frame rate
#else
#ifdef _DEBUG
		GAMEPARAM_FULLSCREEN  = 0,  // WINXP WINDOW: Use window mode in debug version
		GAMEPARAM_TARGETFPS   = 30  // WINXP WINDOW: Target frame rate
#else
		GAMEPARAM_FULLSCREEN  = 1,  // WINXP FULLSCREEN: Use full screen in release version
		GAMEPARAM_TARGETFPS   = 50  // WINXP FULLSCREEN: Target frame rate
#endif
#endif
};

class CGenericThread  
{
// Construction
public:
	CGenericThread();

// Attributes
protected:
	// Thread attributes
    BOOL m_bIsRunning;
    BOOL m_bThreadIsFinished;
	BOOL m_bSuspendThread;
	HANDLE m_hGameThread;
    CCriticalSection m_criticalsection;

	// Graphics attributes - feel free to change to test performance
	enum
	{
		PLANTCOUNT            = 50,  // Number of plants drawn to background
		BACKGROUND_WIDTH      = 1300, // Width of background surface
		BACKGROUND_HEIGHT     = 1300, // Height of background surface
	};

	// Sprite attributes
	enum
	{
		SPRITE_ANIMATION_FRAMES = 20,
		SPRITECOUNT_MIN         = 50, // Give some sprites even to those old devices
		SPRITECOUNT_MAX         = 1000
	};

	CGapiDisplay   m_display;
	CGapiSurface   m_backbuffer;
	CGapiSurface   m_background;
	CGapiSurface   m_introbuffer;

	// Resource surfaces
	CGapiSurface   m_spritelist;
	CGapiSurface   m_plant1;
	CGapiSurface   m_plant2;

	CGapiTimer     m_timer;
	DWORD m_dwScreenOrientation;
	DWORD m_dwSpriteCount;
	DWORD m_dwSpriteIndex;
	DWORD m_dwSpriteWidth;
	DWORD m_dwSpriteHeight;

	BOOL m_bFirstGfxUpdate;
	BOOL m_bRequestSaveScreen;

	CPoint m_backgroundOffset;
	CPoint m_backgroundDirection;
	CList<CPoint, CPoint&> m_coordlist;
	CList<CPoint, CPoint&> m_velocitylist;
	CList<long, long> m_logoindex;

// Operations
public:
    BOOL StartThread(HWND hParentFrame);
    void KillThread();
	void SuspendThread();
	void ResumeThread();
    BOOL IsRunning();
    BOOL IsFinished();
	static unsigned __stdcall ThreadFunc(LPVOID pParam);

	void SaveScreenshot();
	void ChangeScreenOrientation();

protected:
	// ThreadCallback will be called from ThreadFunc
	void ThreadCallback();
	void DrawFrameInfo(DWORD dwY, const TCHAR* pText, COLORREF color);

// Implementation
public:
	virtual ~CGenericThread();

};

#endif // !defined(GENERICTHREAD__INCLUDED_)

⌨️ 快捷键说明

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