home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / CDX.ZIP / Src / Cdi / Device.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-14  |  3.9 KB  |  116 lines

  1. //////////////////////////////////////////////////////////////////////////////////
  2. // Project Name: [ CDI Class Library - CDI.lib ]
  3. // Author:       [ Dan Farley - 97308096@brookes.ac.uk ]
  4. // Source File:  [ CDI_Device Implementation ]
  5. // Revision:     [ 1.6 ]
  6. //////////////////////////////////////////////////////////////////////////////////
  7. #include "CDI.h"
  8.  
  9. //////////////////////////////////////////////////////////////////////////////////
  10. // CDI_Device Constructor
  11. //////////////////////////////////////////////////////////////////////////////////
  12. CDI_Device::CDI_Device(void)
  13. {
  14.     m_Device = NULL;
  15.     m_bActive = FALSE;
  16. }
  17.  
  18. //////////////////////////////////////////////////////////////////////////////////
  19. // CDI_Device Destructor
  20. //////////////////////////////////////////////////////////////////////////////////
  21. CDI_Device::~CDI_Device(void)
  22. {
  23.     m_Device->Unacquire();
  24.     RELEASE(m_Device);
  25. }
  26.  
  27. //////////////////////////////////////////////////////////////////////////////////
  28. // CDI_Device Create
  29. //////////////////////////////////////////////////////////////////////////////////
  30. HRESULT CDI_Device::Create(CDI_Input* input, REFGUID guid)
  31. {
  32.     HRESULT rval;
  33.     LPDIRECTINPUTDEVICE lpDID = NULL;
  34.  
  35.     // Create the device
  36.     rval = input->GetDI()->CreateDevice(guid, &lpDID, NULL);
  37.     if(rval == DI_OK) m_bActive = TRUE;
  38.  
  39.     rval = lpDID->QueryInterface(IID_IDirectInputDevice2, (LPVOID*)&m_Device);
  40.     if(rval != DI_OK) return rval;
  41.  
  42.     RELEASE(lpDID);
  43.  
  44.     return rval;
  45. }
  46.  
  47. //////////////////////////////////////////////////////////////////////////////////
  48. // CDI_Device SetDateFormat
  49. //////////////////////////////////////////////////////////////////////////////////
  50. HRESULT CDI_Device::SetDataFormat(LPCDIDATAFORMAT df)
  51. {
  52.     return m_Device->SetDataFormat(df);
  53. }
  54.  
  55. //////////////////////////////////////////////////////////////////////////////////
  56. // CDI_Device SetCooperativeLevel
  57. //////////////////////////////////////////////////////////////////////////////////
  58. HRESULT CDI_Device::SetCooperativeLevel(void* hwnd, DWORD flags)
  59. {
  60.     return m_Device->SetCooperativeLevel(hwnd, flags);
  61. }
  62.  
  63. //////////////////////////////////////////////////////////////////////////////////
  64. // CDI_Device RunControlPanel
  65. //////////////////////////////////////////////////////////////////////////////////
  66. HRESULT CDI_Device::RunControlPanel(void* hwnd)
  67. {
  68.     return m_Device->RunControlPanel(hwnd, 0);
  69. }
  70.  
  71. //////////////////////////////////////////////////////////////////////////////////
  72. // CDI_Device Acquire
  73. //////////////////////////////////////////////////////////////////////////////////
  74. HRESULT CDI_Device::Acquire(void)
  75. {
  76.     return m_Device->Acquire();
  77. }
  78.  
  79. //////////////////////////////////////////////////////////////////////////////////
  80. // CDI_Device Unacquire
  81. //////////////////////////////////////////////////////////////////////////////////
  82. HRESULT CDI_Device::Unacquire(void)
  83. {
  84.     return m_Device->Unacquire();
  85. }
  86.  
  87. //////////////////////////////////////////////////////////////////////////////////
  88. // CDI_Device SetAbsolute
  89. //////////////////////////////////////////////////////////////////////////////////
  90. HRESULT CDI_Device::SetAbsolute(void)
  91. {
  92.     DIPROPDWORD dipdw;
  93.  
  94.     dipdw.diph.dwSize = sizeof(DIPROPDWORD);
  95.     dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  96.     dipdw.diph.dwObj = 0;
  97.     dipdw.diph.dwHow = DIPH_DEVICE;
  98.     dipdw.dwData = DIPROPAXISMODE_ABS;
  99.     return m_Device->SetProperty(DIPROP_AXISMODE, &dipdw.diph);
  100. }
  101.  
  102. //////////////////////////////////////////////////////////////////////////////////
  103. // CDI_Device SetRelative
  104. //////////////////////////////////////////////////////////////////////////////////
  105. HRESULT CDI_Device::SetRelative(void)
  106. {
  107.     DIPROPDWORD dipdw;
  108.  
  109.     dipdw.diph.dwSize = sizeof(DIPROPDWORD);
  110.     dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  111.     dipdw.diph.dwObj = 0;
  112.     dipdw.diph.dwHow = DIPH_DEVICE;
  113.     dipdw.dwData = DIPROPAXISMODE_REL;
  114.     return m_Device->SetProperty(DIPROP_AXISMODE, &dipdw.diph);
  115. }
  116.