DirectInput wrapper question/opinion request

Started by
0 comments, last by Programmer16 20 years, 1 month ago
I''m making a DirectInput wrapper and I was wondering if it would be smarter to just wrap the DirectInput pointer, and the device for the keyboard and mouse, etc. all together into 1 class or into 3. Thanks in advance! /* I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition) */
Advertisement
I made one class for the device and the keyboard together

class CDirectInput{protected:  LPDIRECTINPUT8       m_pDI;       // DirectInput object  LPDIRECTINPUTDEVICE8 m_pKeyboard; // DirectInput keyboard device  BYTE m_diks[256];public:  CDirectInput();  ~CDirectInput() { Cleanup(); }  bool KeyDown(int dikCode);  void Update();  bool Init(HWND hWnd);  void Cleanup();};


#include <windows.h>#include <dinput.h>#include "input.h"CDirectInput::CDirectInput(){  m_pDI       = NULL;  m_pKeyboard = NULL;  for( int i=0; i<256; i++ )    m_diks[i] = 0;}bool CDirectInput::KeyDown(int dikCode){  return ((m_diks[dikCode] & 0x80) == 0x80);}void CDirectInput::Update(){  HRESULT hr = DI_OK;  // Get the input''s device state, and put the state in m_diks  ZeroMemory(&m_diks, sizeof(m_diks));  hr = m_pKeyboard->GetDeviceState(sizeof(m_diks), &m_diks);  if( FAILED(hr) )  {    m_pKeyboard->Acquire();    return;  }}bool CDirectInput::Init(HWND hWnd){  // Create a IDirectInput8*  if( FAILED( DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&m_pDI, NULL) ) )    return false;  // Create a IDirectInputDevice8* for the keyboard  if( FAILED( m_pDI->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, NULL) ) )    return false;  // Set the keyboard data format  if( FAILED( m_pKeyboard->SetDataFormat(&c_dfDIKeyboard) ) )    return false;  // Set the cooperative level on the keyboard  if( FAILED( m_pKeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND | DISCL_NOWINKEY) ) )    return false;  // Acquire the keyboard  m_pKeyboard->Acquire();  return true;}void CDirectInput::Cleanup(){  if( m_pKeyboard )  {    m_pKeyboard->Release();    m_pKeyboard = NULL;  }  if( m_pDI )  {    m_pDI->Release();    m_pDI = NULL;  }}

This topic is closed to new replies.

Advertisement