Cafu Engine
DirectInput.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 /*****************************/
8 /*** Direct Input (Header) ***/
9 /*****************************/
10 
11 #ifndef CAFU_DIRECTINPUT_HPP_INCLUDED
12 #define CAFU_DIRECTINPUT_HPP_INCLUDED
13 
14 #define WIN32_LEAN_AND_MEAN
15 
16 #include <windows.h> // Header file for Win32.
17 #include <dinput.h> // Header file for DirectInput.
18 
19 
21 {
22  private:
23 
24  LPDIRECTINPUT7 lpDirectInput7; // DirectInput 7.0 Interface.
25  LPDIRECTINPUTDEVICE7 lpDIMouseDevice7; // DirectInput 7.0 Mouse Device Interface.
26 
27 
28  public:
29 
30  /// Create DirectInput object.
31  DirectInputT();
32 
33  /// Initialize DirectInput:
34  /// - Create DirectInput 7.0 object
35  /// - Create Mouse Device
36  /// Set DataFormat
37  /// Set CooperativeLevel (Foreground and Non-Exclusive)
38  /// Set BufferSize to 64 setzen for buffered mouse events.
39  /// Aquire mouse.
40  /// This is separated from the constructor to return errors without the use of exceptions.
41  /// If Initialize() fails the deconstructor will clean up everything.
42  HRESULT Initialize(HINSTANCE hInstance, HWND hWindow);
43 
44  /// Release DirectInput object. This must be possible outside of the destructor if for example
45  /// the hWindow object from Initialize becomes invalid because the associated windows has been
46  /// closed and reopened.
47  void Release();
48 
49  /// Destrcutor.
50  ~DirectInputT();
51 
52  /// Reads the next mouse event from the mouse buffer and returns it in MouseEvent.
53  /// ReadNrOfEvents is 1 if the event was read and 0 if the buffer was empty.
54  /// If something different from DI_OK or DI_BUFFEROVERFLOW is returned,
55  /// MouseEvent and ReadNrOfEvents are undefined.
56  HRESULT GetNextMouseEvent(DIDEVICEOBJECTDATA* MouseEvent, DWORD* ReadNrOfEvents);
57 
58  /// Returns the current state of the mouse buttons.
59  /// If the n-th bit of the return value is set, the n-th mouse button is pressed.
61 };
62 
63 #endif
char GetMouseButtonsImmediate()
Returns the current state of the mouse buttons.
Definition: DirectInput.cpp:126
HRESULT Initialize(HINSTANCE hInstance, HWND hWindow)
Initialize DirectInput:
Definition: DirectInput.cpp:21
DirectInputT()
Create DirectInput object.
Definition: DirectInput.cpp:14
~DirectInputT()
Destrcutor.
Definition: DirectInput.cpp:95
void Release()
Release DirectInput object.
Definition: DirectInput.cpp:78
Definition: DirectInput.hpp:20
HRESULT GetNextMouseEvent(DIDEVICEOBJECTDATA *MouseEvent, DWORD *ReadNrOfEvents)
Reads the next mouse event from the mouse buffer and returns it in MouseEvent.
Definition: DirectInput.cpp:101