ipc提供的windows监控软件SDK比较多,但是都不支持遥控手柄基于onvif协议支持云台控制,需要加入directshow里的两个库dxinput.lib和dxguid.lib,增加游戏手柄控制的类
1. CDIJoystick类用来控制遥控手柄
头文件:
// DIJoystick.h: interface for the CDIJoystick class.
//
//
#if !defined(AFX_DIJOYSTICK_H__D1950720_938F_4491_A3E3_583B1FB98E2C__INCLUDED_)
#define AFX_DIJOYSTICK_H__D1950720_938F_4491_A3E3_583B1FB98E2C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma comment (lib, "dxguid.lib")
#pragma comment (lib, "dinput.lib")
#define MAXJOYBUTTONS 256
class CDIJoystick
{
public:
CDIJoystick();
virtual ~CDIJoystick();
bool PollDevice(); // Update the device state.
void SetPreferredDevice(GUID* pguid); // Set the current GUID for joystick device.
void SetHWND(HWND hwnd); // The the HWND to which the joystick will be attached.
bool InitDevice(void); // Initialise the Device Pointer
bool InitJoystick(void); // Initialise the Joystick
int HowManyButtons(void); // Find out how many buttons the attached device has
bool CreateDevice(GUID *guid); // Create A Device Pointer for a GUID
LPCDIDEVICEINSTANCE GetFirstJoystickID(void); // Get First Joystick Device Data For Enumerated Devices (Must be called before GetNextJoystickID()
LPCDIDEVICEINSTANCE GetNextJoystickID(); // Get Next Joystick Device Data For Enumerated Devices
TCHAR* GetFirstButtonName(void);// Get First Joystick Button Friendly Name For Enumerated Device (Must be called before GetNextJoystickID()
TCHAR* GetNextButtonName(); // Get First Joystick Button Friendly Name For Enumerated Device
bool IsJoystickLeft(void) {return m_JoyLeft;}; // Is Joystick Being Moved Left?
bool IsJoystickRight(void) {return m_JoyRight;};// Is Joystick Being Moved Right?
bool IsJoystickUp(void) {return m_JoyUp;}; // Is Joystick Being Moved Up?
bool IsJoystickDown(void) { return m_JoyDown;}; // Is Joystick Being Moved Down?
bool IsJoystickFire(void) { return m_JoyFire1;};// Has Any Fire Button Been Pressed?
bool IsJoystickFire(int button) { return m_JoyFire[button%MAXJOYBUTTONS];};// Has a specific button been pressed?
DIJOYSTATE2* GetJoystickStateInfo(void) {return &m_dijs;};
void RunControlPanel(void); // Run the Control Panel
protected:
bool Initialise(void); // Initialise Direct Input 7
void Shutdown(void); // Close down and de-allocate any memory assigned to this object.
bool Enumerate_Joysticks(void); // Start Enumeration of Attached Joystick Devices
TCHAR* GetDIError(HRESULT error);// Return Friendly Text to DI7 Error HR
bool ReInitialise(void); // ReInitialise DI7 (Not Implemented)
void ClearFriendlyButtonNames(void); // Clear Down Allocated Memory for Friendly Button Names
bool AddDeviceInfo(LPCDIDEVICEINSTANCE lpddi); // Add DI7 Device Info for Enumerated Device
static BOOL CALLBACK EnumDevicesProc( LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); // Callback procedure for Enumerating Attached Joystick Devices
bool Acquire(bool state); // Acquire/UnAcquire the Joystick
private:
POSITION m_DevicePOS; // Used in CPtrList to keep track of next item.
POSITION m_ButtonPOS; // Used in CPtrList to keep track of next item.
bool m_EnumerationStarted; // Has enumeration started and joystick been found?
DIJOYSTATE2 m_dijs; // Holds Joystick State Information
GUID m_JoystickGUID; // Current Joystick GUID
CPtrList m_DIJoystickList; // Contains a pointer list to Attached Joystick Devices
CPtrList m_DIButtonNames; // Contains a pointer list to Button Names for selected Joystick
bool m_JoyLeft; // Generic Direction, Is Joystick Moving Left
bool m_JoyUp; // Generic Direction, Is Joystick Moving Up
bool m_JoyDown; // Generic Direction, Is Joystick Moving Down
bool m_JoyRight; // Generic Direction, Is Joystick Moving Right
bool m_JoyFire[MAXJOYBUTTONS]; // Which Fire Button Has Been Pressed?
bool m_JoyFire1; // Has any fire button been pressed?
HCURSOR m_hCursorWait; // Wait Cursor Handle when Enumerating Feedback Effects
HWND m_hwnd; // HWND to which Direct Input will be attached to.
bool m_Initialised; // Has Direct Input Been Initialised?
char m_buffer[256]; // A Generic buffer
HINSTANCE m_hInstance; // This modules Instance
LPDIRECTINPUT7 m_lpDI; // Pointer to Direct Input 7
LPDIRECTINPUTDEVICE7 m_lpDIDevice; // Pointer to Direct Input 7 Device
//
// Used for Force Feed Back, Not Yet Implemented
//
LPDIRECTINPUTEFFECT m_lpTriggerEffect; // For Force Feedback Effects
LPDIRECTINPUTEFFECT m_lpStickyEffect; // For Force Feedback Effects
LPDIRECTINPUTEFFECT m_lpResistEffect; // For Force Feedback Effects
bool m_TriggerOK;
BOOL m_FFAvailable; // Is device Force Feedback Compatible?
GUID m_TriggerGuid; // GUID For Force Feed Back Device?
};
#endif // !defined(AFX_DIJOYSTICK_H__D1950720_938F_4491_A3E3_583B1FB98E2C__INCLUDED_)
CPP文件:
<pre name="code" class="cpp">// DIJoystick.cpp: implementation of the CDIJoystick class.
//
//
#include "stdafx.h"
//#include "JoystickDemo.h"
#include "DIJoystick.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "stdafx.h"
#include "DIJoystick.h"
#define BUFFERSIZE 16
// Set the maxmimum range to which we'll gauge the swing
#define JOYMAX 10000
#define JOYMIN -10000
/* Y
^
|
|
X -10,000 <---*---> +10,000
|
|
\/
*/
// Dead zone is the amount of sway the joystick can have before we start registering movement
// In this case 20%
#define JOYDEAD 2000
// The Saturation Point Is Where the Joystick is deemed to be at Full Swing, in this case 95%
#define JOYSAT 9500
//
// Construction/Destruction
//
CDIJoystick::CDIJoystick()
{
// Initialise Member Variables
m_EnumerationStarted=false;
m_Initialised=false;
m_hInstance=GetModuleHandle(NULL);
// Initialise Direct Input
Initialise();
// Start Enumeration of Attached Joysticks.
Enumerate_Joysticks();
}
//
//
// Destroy The Direct Input Joystick Control and tidy up.
//
//
CDIJoystick::~CDIJoystick()
{
Shutdown();
}
//
//
// Initialise Direct Input
//
//
bool CDIJoystick::Initialise()
{
HRESULT hr;
hr = DirectInputCreateEx(m_hInstance, DIRECTINPUT_VERSION,
IID_IDirectInput7, (void**)&m_lpDI, NULL);
if FAILED(hr)
{
// DirectInput not available;
// take appropriate action
OutputDebugString("Failed To Initialise Direct Input 7 in CDIJoystick::Initialise\n");
OutputDebugString(GetDIError(hr));
return false;
}
m_hwnd=NULL;
if FAILED(hr)
{
OutputDebugString(GetDIError(hr));
Shutdown();
return false;
}
m_Initialised=true;
return true; // Successfully Created Direct Input 7 Object
}
//
//
// Shutdown the Direct input object and release it.
//
// Basically clean up any memory allocated to this object
//
//
void CDIJoystick::Shutdown()
{
ClearFriendlyButtonNames();
// Remove Joystick Information
if(!m_DIJoystickList.IsEmpty())
{
POSITION pos=m_DIJoystickList.GetHeadPosition();
LPVOID del=NULL;
while(pos)
{
del=static_cast<LPVOID>(m_DIJoystickList.GetNext(pos));
if(del