Книга: DirectX 8 Programming Tutorial
Setting up the mouse
Setting up the mouse
As with the keyboard, we need to set up the mouse before we can get access to it. Below is the code required, take a look and you'll notice that it is very similar to the keyboard set up code above.
//MOUSE =======================================================================
//Create the mouse device object
if (FAILED(m_pDirectInput->CreateDevice(GUID_SysMouse, &m_pMouse, NULL))) {
CleanUpDirectInput();
LogError("<li>Unable to create DirectInput mouse device interface.");
return false;
} else {
LogInfo("<li>DirectInput mouse device interface created OK.");
}
//Set the data format for the mouse
if (FAILED(m_pMouse->SetDataFormat(&c_dfDIMouse))) {
CleanUpDirectInput();
LogError("<li>Unable to set the mouse data format.");
return false;
} else {
LogInfo("<li>Set the mouse data format OK.");
}
//Set the cooperative level for the mouse
if (FAILED(m_pMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) {
CleanUpDirectInput();
LogError("<li>Unable to set the mouse cooperative level.");
return false;
} else {
LogInfo("<li>Set the mouse cooperative level OK.");
}
//Acquire the mouse
if (m_pMouse) {
m_pMouse->Acquire();
}
So, for the mouse we have the same basic steps as for the keyboard. One of the differences is that we pass in the predefined GUID for the system mouse (GUID_SysMouse) into the CreateDevice method instead of the one for the keyboard which will return a pointer to the mouse. Another difference is that we need to use a different data format, c_dfDIMouse instead of c_dfDIKeyboard. We then set the cooperation level as before and finally acquire the mouse. We are now ready to get data from the keyboard and mouse.
- Setting up the keyboard
- 7.6.3 Drawing with the Mouse Using Artist
- The Controls
- Cleaning up
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Appendix E. Other resources and links
- Example NAT machine in theory
- The final stage of our NAT machine
- Compiling the user-land applications
- The conntrack entries