-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDXC_dinput.cpp
More file actions
94 lines (81 loc) · 2.13 KB
/
DXC_dinput.cpp
File metadata and controls
94 lines (81 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// DXC_dinput.cpp: implementation of the DXC_dinput class.
//
//////////////////////////////////////////////////////////////////////
#include "DXC_dinput.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DXC_dinput::DXC_dinput()
{
m_pDI = NULL;
m_pMouse = NULL;
m_sX = 0;
m_sY = 0;
m_sZ = 0;
}
DXC_dinput::~DXC_dinput()
{
if (m_pMouse != NULL) {
m_pMouse->Unacquire();
m_pMouse->Release();
m_pMouse = NULL;
}
if (m_pDI != NULL) {
m_pDI->Release();
m_pDI = NULL;
}
}
BOOL DXC_dinput::bInit(HWND hWnd, HINSTANCE hInst)
{
HRESULT hr;
DIMOUSESTATE dims;
POINT Point;
GetCursorPos(&Point);
m_sX = (short)(Point.x);
m_sY = (short)(Point.y);
hr = DirectInputCreate( hInst, DIRECTINPUT_VERSION, &m_pDI, NULL );
if (hr != DI_OK) return FALSE;
hr = m_pDI->CreateDevice( GUID_SysMouse, &m_pMouse, NULL );
if (hr != DI_OK) return FALSE;
hr = m_pMouse->SetDataFormat( &c_dfDIMouse );
if (hr != DI_OK) return FALSE;
hr = m_pMouse->SetCooperativeLevel( hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
if (hr != DI_OK) return FALSE;
// m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE), &dims );
if ( m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE), &dims ) != DI_OK )
{
m_pMouse->Acquire();
//return TRUE;
}
return TRUE;
}
void DXC_dinput::SetAcquire(BOOL bFlag)
{
DIMOUSESTATE dims;
if (m_pMouse == NULL) return;
if (bFlag == TRUE) {
m_pMouse->Acquire();
m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE), &dims );
}
else m_pMouse->Unacquire();
}
void DXC_dinput::UpdateMouseState(short * pX, short * pY, short * pZ, char * pLB, char * pRB)
{
if ( m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE), &dims ) != DI_OK )
{
m_pMouse->Acquire();
return;
}
m_sX += (short)dims.lX;
m_sY += (short)dims.lY;
if( (short)dims.lZ != 0 )m_sZ = (short)dims.lZ;
if (m_sX < 0) m_sX = 0;
if (m_sY < 0) m_sY = 0;
if (m_sX > 639) m_sX = 639;
if (m_sY > 479) m_sY = 479;
*pX = m_sX;
*pY = m_sY;
*pZ = m_sZ;
*pLB = (char)dims.rgbButtons[0];
*pRB = (char)dims.rgbButtons[1];
}