Книга: 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.

Оглавление книги


Генерация: 0.260. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз