----------------------------------------------------------------------------- Name: OnCreateDevice() Desc: Sets up the mouse device using the flags from the dialog. -----------------------------------------------------------------------------
| 58 | // Desc: Sets up the mouse device using the flags from the dialog. |
| 59 | //----------------------------------------------------------------------------- |
| 60 | HRESULT DirectInputInit( HWND hDlg ) |
| 61 | { |
| 62 | LogFileOutput("DirectInputInit: g_bDisableDirectInput=%d\n", g_bDisableDirectInput); |
| 63 | if (g_bDisableDirectInput) |
| 64 | return S_OK; |
| 65 | |
| 66 | #ifdef NO_DIRECT_X |
| 67 | |
| 68 | return E_FAIL; |
| 69 | |
| 70 | #else // NO_DIRECT_X |
| 71 | |
| 72 | HRESULT hr; |
| 73 | BOOL bExclusive; |
| 74 | BOOL bForeground; |
| 75 | BOOL bImmediate; |
| 76 | DWORD dwCoopFlags; |
| 77 | |
| 78 | DirectInputUninit(hDlg); |
| 79 | LogFileOutput("DirectInputInit: DirectInputUninit()\n"); |
| 80 | |
| 81 | // Determine where the buffer would like to be allocated |
| 82 | bExclusive = FALSE; |
| 83 | bForeground = FALSE; // Otherwise get DIERR_OTHERAPPHASPRIO (== E_ACCESSDENIED) on Acquire() |
| 84 | bImmediate = TRUE; |
| 85 | |
| 86 | if( bExclusive ) |
| 87 | dwCoopFlags = DISCL_EXCLUSIVE; |
| 88 | else |
| 89 | dwCoopFlags = DISCL_NONEXCLUSIVE; |
| 90 | |
| 91 | if( bForeground ) |
| 92 | dwCoopFlags |= DISCL_FOREGROUND; |
| 93 | else |
| 94 | dwCoopFlags |= DISCL_BACKGROUND; |
| 95 | |
| 96 | // Create a DInput object |
| 97 | hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ); |
| 98 | LogFileOutput("DirectInputInit: DirectInput8Create(), hr=0x%08X\n", hr); |
| 99 | if (FAILED(hr)) |
| 100 | return hr; |
| 101 | |
| 102 | // Obtain an interface to the system mouse device. |
| 103 | hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ); |
| 104 | LogFileOutput("DirectInputInit: CreateDevice(), hr=0x%08X\n", hr); |
| 105 | if (FAILED(hr)) |
| 106 | return hr; |
| 107 | |
| 108 | // Set the data format to "mouse format" - a predefined data format |
| 109 | // |
| 110 | // A data format specifies which controls on a device we |
| 111 | // are interested in, and how they should be reported. |
| 112 | // |
| 113 | // This tells DirectInput that we will be passing a |
| 114 | // DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState. |
| 115 | hr = g_pMouse->SetDataFormat( &c_dfDIMouse2 ); |
| 116 | LogFileOutput("DirectInputInit: SetDataFormat(), hr=0x%08X\n", hr); |
| 117 | if (FAILED(hr)) |
no test coverage detected