/* joystick_dinput_exit: [primary thread] * Shuts down the DirectInput joystick devices. */ static void joystick_dinput_exit(void) { int i, j; /* unacquire the devices */ wnd_call_proc(joystick_dinput_unacquire); /* destroy the devices */ for (i=0; i<dinput_joy_num; i++) { IDirectInputDevice2_Release(dinput_joystick[i].device); for (j=0; j<dinput_joystick[i].num_axes; j++) { if (dinput_joystick[i].axis_name[j]) _AL_FREE(dinput_joystick[i].axis_name[j]); } if (dinput_joystick[i].caps & JOYCAPS_HASPOV) _AL_FREE(dinput_joystick[i].hat_name); for (j=0; j<dinput_joystick[i].num_buttons; j++) _AL_FREE(dinput_joystick[i].button_name[j]); } /* destroy the DirectInput interface */ IDirectInput_Release(joystick_dinput); win_remove_all_joysticks(); dinput_joy_num = 0; }
/* joystick_dinput_init: [primary thread] * Initialises the DirectInput joystick devices. */ static int joystick_dinput_init(void) { HRESULT hr; /* the DirectInput joystick interface is not part of DirectX 3 */ if (_dx_ver < 0x0500) return -1; /* get the DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &joystick_dinput, NULL); if (FAILED(hr)) return -1; /* enumerate the joysticks attached to the system */ hr = IDirectInput_EnumDevices(joystick_dinput, DIDEVTYPE_JOYSTICK, joystick_enum_callback, NULL, DIEDFL_ATTACHEDONLY); if (FAILED(hr)) { IDirectInput_Release(joystick_dinput); return -1; } /* acquire the devices */ wnd_call_proc(joystick_dinput_acquire); return (dinput_joy_num == 0); }
/* mouse_dinput_exit: [primary thread] * Shuts down the DirectInput mouse device. */ static int mouse_dinput_exit(void) { if (mouse_dinput_device) { /* unregister event handler first */ _win_input_unregister_event(mouse_input_event); /* unacquire device */ wnd_call_proc(mouse_dinput_unacquire); /* now it can be released */ IDirectInputDevice_Release(mouse_dinput_device); mouse_dinput_device = NULL; } /* release DirectInput interface */ if (mouse_dinput) { IDirectInput_Release(mouse_dinput); mouse_dinput = NULL; } /* close event handle */ if (mouse_input_event) { CloseHandle(mouse_input_event); mouse_input_event = NULL; } /* update the system cursor */ wnd_schedule_proc(mouse_set_syscursor); return 0; }
/* key_dinput_exit: [primary thread] * Shuts down the DirectInput keyboard device. */ static int key_dinput_exit(void) { if (key_dinput_device) { /* unregister event handler first */ _win_input_unregister_event(key_input_event); /* unacquire device */ wnd_call_proc(key_dinput_unacquire); /* now it can be released */ IDirectInputDevice_Release(key_dinput_device); key_dinput_device = NULL; } /* release DirectInput interface */ if (key_dinput) { IDirectInput_Release(key_dinput); key_dinput = NULL; } /* close event handle */ if (key_input_event) { CloseHandle(key_input_event); key_input_event = NULL; } return 0; }
// Function name : CVMR9Graph::SetMediaFile // Description : set a media source // Return type : BOOL // Argument : const char* pszFileName // Argument : int nLayer = 0 BOOL CVMR9Graph::SetMediaFile(const char* pszFileName, bool withSound, int nLayer) { if (pszFileName == NULL) { ReportError("Could not load a file with an empty file name", E_INVALIDARG); return FALSE; } UseAVISound = withSound; m_pszFileName = pszFileName; if (!wnd_call_proc(wndproc_build_filter_graph)) return FALSE; return TRUE; }
/* mouse_dinput_init: [primary thread] * Sets up the DirectInput mouse device. */ static int mouse_dinput_init(void) { HRESULT hr; DIPROPDWORD property_buf_size = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ DINPUT_BUFFERSIZE, // dwData }; /* Get DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &mouse_dinput, NULL); if (FAILED(hr)) goto Error; /* Create the mouse device */ hr = IDirectInput_CreateDevice(mouse_dinput, &GUID_SysMouse, &mouse_dinput_device, NULL); if (FAILED(hr)) goto Error; /* Find how many buttons */ dinput_buttons = 0; dinput_wheel = FALSE; hr = IDirectInputDevice_EnumObjects(mouse_dinput_device, mouse_enum_callback, NULL, DIDFT_PSHBUTTON | DIDFT_AXIS); if (FAILED(hr)) goto Error; /* Check to see if the buttons are swapped (left-hand) */ mouse_swap_button = GetSystemMetrics(SM_SWAPBUTTON); /* Set data format */ hr = IDirectInputDevice_SetDataFormat(mouse_dinput_device, &c_dfDIMouse); if (FAILED(hr)) goto Error; /* Set buffer size */ hr = IDirectInputDevice_SetProperty(mouse_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph); if (FAILED(hr)) goto Error; /* Enable event notification */ mouse_input_event = CreateEvent(NULL, FALSE, FALSE, NULL); hr = IDirectInputDevice_SetEventNotification(mouse_dinput_device, mouse_input_event); if (FAILED(hr)) goto Error; /* Register event handler */ if (_win_input_register_event(mouse_input_event, mouse_dinput_handle) != 0) goto Error; /* Grab the device */ _mouse_on = TRUE; wnd_call_proc(mouse_dinput_grab); return 0; Error: mouse_dinput_exit(); return -1; }
/* key_dinput_init: [primary thread] * Sets up the DirectInput keyboard device. */ static int key_dinput_init(void) { HRESULT hr; HWND allegro_wnd = win_get_window(); DIPROPDWORD property_buf_size = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ DINPUT_BUFFERSIZE, // dwData }; /* Get DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &key_dinput, NULL); if (FAILED(hr)) goto Error; /* Create the keyboard device */ hr = IDirectInput_CreateDevice(key_dinput, &GUID_SysKeyboard, &key_dinput_device, NULL); if (FAILED(hr)) goto Error; /* Set data format */ hr = IDirectInputDevice_SetDataFormat(key_dinput_device, &c_dfDIKeyboard); if (FAILED(hr)) goto Error; /* Set buffer size */ hr = IDirectInputDevice_SetProperty(key_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph); if (FAILED(hr)) goto Error; /* Set cooperative level */ hr = IDirectInputDevice_SetCooperativeLevel(key_dinput_device, allegro_wnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); if (FAILED(hr)) goto Error; /* Enable event notification */ key_input_event = CreateEvent(NULL, FALSE, FALSE, NULL); hr = IDirectInputDevice_SetEventNotification(key_dinput_device, key_input_event); if (FAILED(hr)) goto Error; /* Register event handler */ if (_win_input_register_event(key_input_event, key_dinput_handle) != 0) goto Error; get_reverse_mapping(); /* Acquire the device */ wnd_call_proc(key_dinput_acquire); return 0; Error: key_dinput_exit(); return -1; }