www.pudn.com > GameEngine_src.rar > CDInput.h


// CDInput.h: interface for the CDInput class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#ifndef CDInput_h 
#define CDInput_h 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include  
#include  
 
/////////////////////////////////////////////////////////////// 
//DirectInput8 健盘,鼠标类的基类 
/////////////////////////////////////////////////////////////// 
class CDInput   
{ 
public: 
	CDInput(); 
	virtual ~CDInput(); 
	 
	static bool InitDInput( HINSTANCE hInstance ); 
	static void FreeDInput(); 
protected: 
	static LPDIRECTINPUT8	g_lpDI;					//DirectInput8 obj 
	static int				g_iRef;					//引用计数 
}; 
 
 
 
///////////////////////////////////////////////////////////////// 
//DirectInput8 的健盘类 
///////////////////////////////////////////////////////////////// 
class CDIKeyBoard  : public CDInput 
{ 
public: 
	CDIKeyBoard(); 
	~CDIKeyBoard(); 
 
	bool Init( HWND hwnd, HINSTANCE hInstance );	//初始化健盘 
	void Free();									 
 
	void UpdateKeyBoard();							//更新健盘状态 
 
	bool IsKeyDown( int key_id )					//判断一个健是否按下 
	{  
		if (m_KeyBuffer[key_id] & 0x80) 
			return true; 
		else  
			return false; 
	}		 
 
	bool IsKeyRelease( int key_id );				//判断一个健是否按下又松开 
	bool IsKeyPress( int key_id ); 
 
	void OnActive() { if ( m_lpKeyBoardDevice ) m_lpKeyBoardDevice->Acquire(); } 
	void OnInactive() { if ( m_lpKeyBoardDevice ) m_lpKeyBoardDevice->Unacquire(); } 
 
private: 
	 
	LPDIRECTINPUTDEVICE8	m_lpKeyBoardDevice;		//key board device; 
 
	BYTE *m_KeyStateBuffer;	//健位状态缓冲区 
	BYTE *m_KeyBuffer;		//健盘缓冲区 
 
}; 
 
 
///////////////////////////////////////////////////////////////// 
//DirectInput8 的鼠标类 
///////////////////////////////////////////////////////////////// 
class CDIMouse	: public CDInput 
{ 
public: 
	CDIMouse(); 
	~CDIMouse(); 
 
	bool Init( HWND hwnd, HINSTANCE hInstance ); 
	void Free(); 
	void Reset(); 
 
	void UpdateMouse( HWND hwnd ); 
 
	int  GetX() { return m_MousePoint.x; } 
	int  GetY()	{ return m_MousePoint.y; } 
	bool IsLDown() { return m_IsLBDown; } 
	bool IsRDown() { return m_IsRBDown; } 
 
	bool IsLRelease(){ return m_IsLRelease; } 
	bool IsRRelease(){ return m_IsRRelease; } 
 
	bool IsLPress() { return m_IsLPress; } 
	bool IsRPress()	{ return m_IsRPress; } 
 
	bool IsMoving()	{ return m_IsMoving; } 
 
	void OnActive() { if ( m_lpDIMouse ) m_lpDIMouse->Acquire(); } 
	void OnInactive() { if ( m_lpDIMouse ) m_lpDIMouse->Unacquire(); } 
 
private: 
	LPDIRECTINPUTDEVICE8	m_lpDIMouse; 
 
	POINT	m_MousePoint; 
	bool	m_IsRBDown; 
	bool	m_IsLBDown; 
 
	bool	m_IsLRelease; 
	bool	m_IsRRelease; 
 
	bool	m_IsLPress; 
	bool	m_IsRPress; 
 
	bool	m_bLBState; 
	bool	m_bRBState; 
 
	bool	m_IsMoving; 
	HANDLE					m_hMouseEvent;	//鼠标事件句柄 
}; 
#endif