void DirectInput_Update() { //update mouse dimouse->Poll(); if (!SUCCEEDED(dimouse->GetDeviceState(sizeof(DIMOUSESTATE),&mouse_state))) { //mouse device lose, try to re-acquire dimouse->Acquire(); } //update keyboard dikeyboard->Poll(); if (!SUCCEEDED(dikeyboard->GetDeviceState(256,(LPVOID)&keys))) { //keyboard device lost, try to re-acquire dikeyboard->Acquire(); } //update controllers for (int i=0; i< 4; i++ ) { ZeroMemory( &controllers[i], sizeof(XINPUT_STATE) ); //get the state of the controller XINPUT_STATE state; DWORD result = XInputGetState( i, &state ); //store state in global controllers array if (result == 0) controllers[i] = state.Gamepad; } }
BOOL KeyboardInit (HWND hWindow, int iMin, int iMax, int iDeadZone) { if (FAILED(m_lpkDI->CreateDevice ( pdidInstance->guidInstance, m_lpkDKB, NULL)) ) { return DIENUM_CONTINUE; } else { return DIENUM_STOP; } if (FAILED(m_lpkDKB->SetDataFormat (&c_dfDIKeyboard))) { return FALSE; } /* Acquire joystick */ HRESULT hRet = m_lpkDKB->Poll (); if (FAILED (hRet)) { hRet = m_lpkDKB->Acquire (); while (hRet == DIERR_INPUTLOST) { hRet = m_lpkDKB->Acquire (); } } return TRUE; }
int DInput_Read_Joystick(void) { // this function reads the joystick state // make sure the joystick was initialized if (!joystick_found) return(0); if (lpdijoy) { // this is needed for joysticks only if (lpdijoy->Poll()!=DI_OK) return(0); if (lpdijoy->GetDeviceState(sizeof(DIJOYSTATE), (LPVOID)&joy_state)!=DI_OK) return(0); } else { // joystick isn't plugged in, zero out state memset(&joy_state,0,sizeof(joy_state)); // return error return(0); } // end else // return sucess return(1); } // end DInput_Read_Joystick
/* Update Keyboard status */ BOOL KeyboardUpdate (void) { /* Poll the Keyboard */ if (FAILED (m_lpkDKB->Poll ()) ) { /* Acquire Keyboard */ HRESULT hRet = m_lpkDKB->Acquire (); if ((FAILED (hRet)) && (hRet == DIERR_INPUTLOST)) { m_lpkDKB->Acquire (); } else { return FALSE; } } /* Get device data */ if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (DIJOYSTATE2), &m_kDeviceData)) ) { return FALSE; } return TRUE; }
//----------------------------------------------------------------------------- // Name: UpdateInputState() // Desc: Get the input device's state and display it. //----------------------------------------------------------------------------- HRESULT UpdateInputState() { HRESULT hr; DIJOYSTATE2 js; // DInput joystick state state.is_valid = false; if (!g_pJoystick) { state.message = "No device at index"; return S_OK; } // Poll the device to read the current state hr = g_pJoystick->Poll(); if (FAILED(hr)) { state.message = "device stream interrupted"; // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); //while (hr == DIERR_INPUTLOST) // hr = g_pJoystick->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // Get the input's device state if (FAILED(hr = g_pJoystick->GetDeviceState(sizeof(DIJOYSTATE2), &js))) { state.message = "GetDeviceState failed"; return hr; // The device should have been acquired during the Poll() } state.is_valid = true; state.message = ""; // Axes state.x = js.lX; state.y = js.lY; state.z = js.lZ; state.rx = js.lRx; state.ry = js.lRy; state.rz = js.lRz; state.slider0 = js.rglSlider[0]; state.slider1 = js.rglSlider[1]; // Slider controls state.slider0 = js.rglSlider[0]; state.slider1 = js.rglSlider[1]; // Points of view state.pov0 = js.rgdwPOV[0]; state.pov1 = js.rgdwPOV[1]; state.pov2 = js.rgdwPOV[2]; state.pov3 = js.rgdwPOV[3]; // Buttons for (int i = 0; i < 128; i++) { state.buttons[i] = js.rgbButtons[i]; } return S_OK; }
// Acquire our device. Our device might get unacquired for many many reasons, and we need to be able to reacquire it to get input again. // We use this a LOT. inline HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice ) { HRESULT hResult = lpDirectInputDevice->Acquire(); while( hResult == DIERR_INPUTLOST ) hResult = lpDirectInputDevice->Acquire(); if( SUCCEEDED( hResult )) lpDirectInputDevice->Poll(); return hResult; }
void DirectInputRegistry::pollDevice( LPDIRECTINPUTDEVICE8 device ) { HRESULT hr = device->Poll(); if ( FAILED(hr) ) { device->Acquire(); if ( hr==DIERR_INPUTLOST ) osg::notify(osg::WARN) << "Device lost." << std::endl; } }
int GutReadJoystick(GutJoystickInfo *joystick) { DIJOYSTATE js; if ( g_pJoystick==NULL || joystick==NULL ) return 0; // Poll the device to read the current state int hr = g_pJoystick->Poll(); if( FAILED(hr) ) { g_pJoystick->Acquire(); g_pJoystick->Poll(); } // Get the input's device state hr = g_pJoystick->GetDeviceState( sizeof(DIJOYSTATE), &js ); if( hr == DIERR_INPUTLOST ) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); if( FAILED(hr) ) return 0; } joystick->x = js.lX; joystick->y = js.lY; joystick->z = js.lZ; joystick->rx = js.lRx; joystick->ry = js.lRy; joystick->rz = js.lRz; joystick->pov[0] = js.rgdwPOV[0]; joystick->pov[1] = js.rgdwPOV[1]; joystick->pov[2] = js.rgdwPOV[2]; joystick->pov[3] = js.rgdwPOV[3]; memcpy(joystick->button, js.rgbButtons, 32); return 1; }
bool OutDevice::Read(LPDIRECTINPUTDEVICE8 dev,void* pBuffer, long lSize) { HRESULT hr; while(true) { dev->Poll(); //轮询 dev->Acquire(); //获取设备控制权 if(SUCCEEDED(hr=dev->GetDeviceState(lSize,pBuffer))) break; if(hr != DIERR_INPUTLOST || hr != DIERR_NOTACQUIRED) return false; if(FAILED(dev->Acquire())) return false; } return true; }
HRESULT poll(LPDIRECTINPUTDEVICE8 joystick, LPDIJOYSTATE2 js) { // Device polling (as seen on x360ce) HRESULT hr = E_FAIL; if (!joystick) return E_FAIL; joystick->Poll(); hr = joystick->GetDeviceState(sizeof(DIJOYSTATE2), js); if (FAILED(hr)) { // Reacquire the device (only once) hr = joystick->Acquire(); } return hr; }
void CG27::run() { HRESULT hr; if (g_pJoystick == NULL) { return; } while(1) { hr = g_pJoystick->Poll(); g_pJoystick->Acquire(); g_mutexG27.lock(); hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &g_G27State); emit(GetG27Info()); qDebug() << g_G27State.lX; /* qDebug() << g_G27State.lY; qDebug() << g_G27State.lZ; qDebug() << g_G27State.lRx; qDebug() << g_G27State.lRy; qDebug() << g_G27State.lRz; qDebug() << g_G27State.lVX; qDebug() << g_G27State.lVY; qDebug() << g_G27State.lVZ; qDebug() << g_G27State.lAX; qDebug() << g_G27State.lAY; qDebug() << g_G27State.lAZ; qDebug() << " "; */ qDebug() << " "; qDebug() << " "; g_mutexG27.unlock(); usleep(5000); } return; }
// Update, polls values from Joystick bool JoystickHandler::update() { for(int iEntry = 0; iEntry < nEntry; ++iEntry) { Entry& e = entry[iEntry]; LPDIRECTINPUTDEVICE8 d = e.diDevice; if(FAILED(d->Poll())) { HRESULT hr = d->Acquire(); while(hr == DIERR_INPUTLOST) { hr = d->Acquire(); } } else { d->GetDeviceState(sizeof(DIJOYSTATE2), &e.joystate); } } const JoystickHandler::Entry* e = this->getEntry(0); if(e) { this->js = &e->joystate; return true; } return false; }
/* Update joystick status */ BOOL JoystickUpdate (void) { /* Poll the joystick */ if (FAILED (m_lpkDIDevice->Poll ()) ) { /* Acquire joystick */ HRESULT hRet = m_lpkDIDevice->Acquire (); if ((FAILED (hRet)) && (hRet == DIERR_INPUTLOST)) { m_lpkDIDevice->Acquire (); } else { return FALSE; } } if(JOY) { /* Get device data */ if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (DIJOYSTATE2), &m_kDeviceData)) ) { return FALSE; } } else { if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (m_strKeyState), &m_strKeyState)) ) { return FALSE; } } return TRUE; }
m64p_error VidExt_GL_SwapBuffers() { CMupen64Plus* instance = CMupen64Plus::GetSingleton( ) ; SwapBuffers( g_hDC ); BYTE keys[256]; build_keymap(); // Get the input's device state, and put the state in keys - zero first ZeroMemory(keys, sizeof(keys) ); HRESULT result = m_pDIKeyboardDevice->GetDeviceState( sizeof(keys), keys ); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { m_pDIKeyboardDevice->Acquire(); m_pDIKeyboardDevice->Poll(); m_pDIKeyboardDevice->GetDeviceState( sizeof(keys), keys ); } for(int i=0;i<256;i++) { if(keys[i] & 0x80) { SDL_keysym keysym; SDL_keysym *pressed =TranslateKey(i,&keysym,0); instance->CoreDoCommand(M64CMD_SEND_SDL_KEYDOWN,MAKELPARAM(pressed->sym,0), NULL); } else { SDL_keysym keysym; SDL_keysym *pressed =TranslateKey(i,&keysym,0); instance->CoreDoCommand(M64CMD_SEND_SDL_KEYUP,MAKELPARAM(pressed->sym,0), NULL); } } return M64ERR_SUCCESS; }
void CJoystick::Update() { if (!IsEnabled()) return; int buttonId = -1; int axisId = -1; int hatId = -1; int numhat = -1; int numj = m_pJoysticks.size(); if (numj <= 0) return; // go through all joysticks for (int j = 0; j<numj; j++) { LPDIRECTINPUTDEVICE8 pjoy = m_pJoysticks[j]; HRESULT hr; DIJOYSTATE2 js; // DInput joystick state m_NumAxes = (m_devCaps[j].dwAxes > MAX_AXES) ? MAX_AXES : m_devCaps[j].dwAxes; numhat = (m_devCaps[j].dwPOVs > 4) ? 4 : m_devCaps[j].dwPOVs; hr = pjoy->Poll(); if( FAILED( hr ) ) { int i=0; // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = pjoy->Acquire(); while( (hr == DIERR_INPUTLOST) && (i++ < 10) ) hr = pjoy->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return; } // Get the input's device state if( FAILED( hr = pjoy->GetDeviceState( sizeof( DIJOYSTATE2 ), &js ) ) ) return; // The device should have been acquired during the Poll() // get button states first, they take priority over axis for( int b = 0; b < 128; b++ ) { if( js.rgbButtons[b] & 0x80 ) { m_JoyId = j; buttonId = b+1; j = numj-1; break; } } // get hat position m_HatState = SDL_HAT_CENTERED; for (int h = 0; h < numhat; h++) { if((LOWORD(js.rgdwPOV[h]) == 0xFFFF) != true) { m_JoyId = j; hatId = h + 1; j = numj-1; if ( (js.rgdwPOV[0] > JOY_POVLEFT) || (js.rgdwPOV[0] < JOY_POVRIGHT) ) m_HatState |= SDL_HAT_UP; if ( (js.rgdwPOV[0] > JOY_POVFORWARD) && (js.rgdwPOV[0] < JOY_POVBACKWARD) ) m_HatState |= SDL_HAT_RIGHT; if ( (js.rgdwPOV[0] > JOY_POVRIGHT) && (js.rgdwPOV[0] < JOY_POVLEFT) ) m_HatState |= SDL_HAT_DOWN; if ( js.rgdwPOV[0] > JOY_POVBACKWARD ) m_HatState |= SDL_HAT_LEFT; break; } } // get axis states m_Amount[0] = 0; m_Amount[1] = js.lX; m_Amount[2] = js.lY; m_Amount[3] = js.lZ; m_Amount[4] = js.lRx; m_Amount[5] = js.lRy; m_Amount[6] = js.lRz; m_AxisId = GetAxisWithMaxAmount(); if (m_AxisId) { m_JoyId = j; j = numj-1; break; } } if(hatId==-1) { if(m_HatId!=0) CLog::Log(LOGDEBUG, "Joystick %d hat %d Centered", m_JoyId, abs(hatId)); m_pressTicksHat = 0; SetHatActive(false); m_HatId = 0; } else { if(hatId!=m_HatId) { CLog::Log(LOGDEBUG, "Joystick %d hat %u Down", m_JoyId, hatId); m_HatId = hatId; m_pressTicksHat = XbmcThreads::SystemClockMillis(); } SetHatActive(); } if (buttonId==-1) { if (m_ButtonId!=0) { CLog::Log(LOGDEBUG, "Joystick %d button %d Up", m_JoyId, m_ButtonId); } m_pressTicksButton = 0; SetButtonActive(false); m_ButtonId = 0; } else { if (buttonId!=m_ButtonId) { CLog::Log(LOGDEBUG, "Joystick %d button %d Down", m_JoyId, buttonId); m_ButtonId = buttonId; m_pressTicksButton = XbmcThreads::SystemClockMillis(); } SetButtonActive(); } }
static unsigned long Update(void *device) { // Poll the device to read the current state if (!g_pJoystick) return -1; HRESULT hr = g_pJoystick->Poll(); if(FAILED(hr)) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = SYS_DXTRACE(g_pJoystick->Acquire()); while( hr == DIERR_INPUTLOST ) hr = SYS_DXTRACE(g_pJoystick->Acquire()); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // Get the input's device state if( FAILED( hr = SYS_DXTRACE(g_pJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &g_sJOY ) ) ) ) return hr; // The device should have been acquired during the Poll() sJOY->lX = g_sJOY.lX; sJOY->lY = g_sJOY.lY; sJOY->lZ = g_sJOY.lZ; sJOY->lRx = g_sJOY.lRx; sJOY->lRy = g_sJOY.lRy; sJOY->lRz = g_sJOY.lRz; // TODO: lRx = lZ and lRy = lRx with PS2 pad sJOY->rglSlider[0] = sJOY->rglSlider[0]; sJOY->rglSlider[1] = sJOY->rglSlider[1]; sysMemCpy(sJOY->rgdwPOV, g_sJOY.rgdwPOV, 4 * 4); sysMemCpy(sJOY->steButtons, sJOY->rgbButtons, 128); sysMemCpy(sJOY->rgbButtons, g_sJOY.rgbButtons, 128); #if DIRECTINPUT_VERSION >=0x0700 sJOY->lVX = g_sJOY.lVX; sJOY->lVY = g_sJOY.lVY; sJOY->lVZ = g_sJOY.lVZ; sJOY->lVRx = g_sJOY.lVRx; sJOY->lVRy = g_sJOY.lVRy; sJOY->lVRz = g_sJOY.lVRz; sJOY->rglVSlider[0] = g_sJOY.rglVSlider[0]; sJOY->rglVSlider[1] = g_sJOY.rglVSlider[1]; sJOY->lAX = g_sJOY.lAX; sJOY->lAY = g_sJOY.lAY; sJOY->lAZ = g_sJOY.lAZ; sJOY->lARx = g_sJOY.lARx; sJOY->lARy = g_sJOY.lARy; sJOY->lARz = g_sJOY.lARz; sJOY->rglASlider[0] = g_sJOY.rglASlider[0]; sJOY->rglASlider[1] = g_sJOY.rglASlider[1]; sJOY->lFX = g_sJOY.lFX; sJOY->lFY = g_sJOY.lFY; sJOY->lFZ = g_sJOY.lFZ; sJOY->lFRx = g_sJOY.lFRx; sJOY->lFRy = g_sJOY.lFRy; sJOY->lFRz = g_sJOY.lFRz; sJOY->rglFSlider[0] = g_sJOY.rglFSlider[0]; sJOY->rglFSlider[1] = g_sJOY.rglFSlider[1]; #endif return 0; }
HRESULT _stdcall Poll(void) { return RealDevice->Poll(); }
//----------------------------------------------------------------------------- // Name: UpdateInputState() // Desc: Get the input device's state and display it. //----------------------------------------------------------------------------- HRESULT UpdateInputState( HWND hDlg ) { HRESULT hr; TCHAR strText[128] = {0}; // Device state text MouseState ms; // Custom mouse state static POINT pOrigin = {0}; // Initial position static BOOL bInitialized = FALSE; // Indicates offsets are valid if( NULL == g_pMouse ) return S_OK; // Poll the device to read the current state hr = g_pMouse->Poll(); if( FAILED( hr ) ) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pMouse->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // Get the input's device state if( FAILED( hr = g_pMouse->GetDeviceState( sizeof( MouseState ), &ms ) ) ) return hr; // The device should have been acquired during the Poll() // The initial mouse position should be subracted from the current point. if( !bInitialized ) { bInitialized = TRUE; pOrigin.x = ms.lAxisX; pOrigin.y = ms.lAxisY; } // Display state to dialog StringCchPrintf( strText, 128, TEXT( "%ld" ), ms.lAxisX - pOrigin.x ); SetWindowText( GetDlgItem( hDlg, IDC_X_AXIS ), strText ); StringCchPrintf( strText, 128, TEXT( "%ld" ), ms.lAxisY - pOrigin.y ); SetWindowText( GetDlgItem( hDlg, IDC_Y_AXIS ), strText ); // Fill up text with which buttons are pressed strText[0] = 0; for( int i = 0; i < 3; i++ ) { if( ms.abButtons[i] & 0x80 ) { TCHAR sz[128]; StringCchPrintf( sz, 128, TEXT( "%02d " ), i ); StringCchCat( strText, 128, sz ); } } SetWindowText( GetDlgItem( hDlg, IDC_BUTTONS ), strText ); return S_OK; }
int Game_Main(void *parms, int num_parms) { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! int index; // looping var int dx,dy; // general deltas used in collision detection // check of user is trying to exit if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE)) PostMessage(main_window_handle, WM_DESTROY,0,0); // start the timing clock Start_Clock(); // clear the drawing surface DDraw_Fill_Surface(lpddsback, 0); // get joystick data lpdijoy->Poll(); // this is needed for joysticks only lpdijoy->GetDeviceState(sizeof(DIJOYSTATE2), (LPVOID)&joy_state); // lock the back buffer DDraw_Lock_Back_Surface(); // draw the background reactor image Draw_Bitmap16(&playfield, back_buffer, back_lpitch, 0); // unlock the back buffer DDraw_Unlock_Back_Surface(); // is the player moving? blaster.x+=joy_state.lX; blaster.y+=joy_state.lY; // test bounds if (blaster.x > SCREEN_WIDTH-32) blaster.x = SCREEN_WIDTH-32; else if (blaster.x < 0) blaster.x = 0; if (blaster.y > SCREEN_HEIGHT-32) blaster.y = SCREEN_HEIGHT-32; else if (blaster.y < SCREEN_HEIGHT-128) blaster.y = SCREEN_HEIGHT-128; // is player firing? if (joy_state.rgbButtons[0]) Start_Missile(); // move and draw missle Move_Missile(); Draw_Missile(); // is it time to blink eyes if ((rand()%100)==50) Set_Animation_BOB(&blaster,0); // draw blaster Animate_BOB(&blaster); Draw_BOB16(&blaster,lpddsback); // draw some text Draw_Text_GDI("(16-Bit Version) Let's Rock!!!",0,0,RGB(255,255,255),lpddsback); // display joystick and buttons 0-7 sprintf(buffer,"Joystick Stats: X-Axis=%d, Y-Axis=%d, buttons(%d,%d,%d,%d,%d,%d,%d,%d)", joy_state.lX,joy_state.lY, joy_state.rgbButtons[0], joy_state.rgbButtons[1], joy_state.rgbButtons[2], joy_state.rgbButtons[3], joy_state.rgbButtons[4], joy_state.rgbButtons[5], joy_state.rgbButtons[6], joy_state.rgbButtons[7]); Draw_Text_GDI(buffer,0,SCREEN_HEIGHT-20,RGB(255,255,50),lpddsback); // print out name of joystick sprintf(buffer, "Joystick Name & Vendor: %s",joyname); Draw_Text_GDI(buffer,0,SCREEN_HEIGHT-40,RGB(255,255,50),lpddsback); // flip the surfaces DDraw_Flip(); // sync to 30 fps Wait_Clock(30); // return success return(1); } // end Game_Main
///////////////////////////////////// // Name: INPMouseUpdate // Purpose: update mouse device, we // require hMain to get the // actual location of the mouse // (this is not used in // exclusive mode) // Output: mouse updated // Return: ///////////////////////////////////// s32 F_API INPMouseUpdate(void *hMain) { if(!g_pDMouse) return RETCODE_SUCCESS; u8 i; DIMOUSESTATE2 mouseDat={0}; //update released buttons for(i = 0; i < MAXMOUSEBTN; i++) { if(g_mouseBtn[i] == INPUT_RELEASED) g_mouseBtn[i] = INPUT_UP; } HRESULT hr; hr = g_pDMouse->Poll(); if(FAILED(hr)) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pDMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pDMouse->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return RETCODE_SUCCESS; } // Get the input's device state if(FAILED(hr = g_pDMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &mouseDat))) { DInputError(hr, L"INPMouseUpdate"); return RETCODE_FAILURE; } //check the buttons for(i = 0; i < MAXMOUSEBTN; i++) { if(mouseDat.rgbButtons[i] & INPUT_DOWN) g_mouseBtn[i] = INPUT_DOWN; else if(g_mouseBtn[i] == INPUT_DOWN) g_mouseBtn[i] = INPUT_RELEASED; } //check location if(!g_bExclusive) { GetCursorPos((LPPOINT)&g_mouseLoc); ScreenToClient((HWND)hMain, (LPPOINT)&g_mouseLoc); } else { g_mouseLoc.x += mouseDat.lX; if(g_mouseLoc.x < 0) g_mouseLoc.x = 0; else if(g_mouseLoc.x > g_bound.x) g_mouseLoc.x = g_bound.x; g_mouseLoc.y += mouseDat.lY; if(g_mouseLoc.y < 0) g_mouseLoc.y = 0; else if(g_mouseLoc.y > g_bound.y) g_mouseLoc.y = g_bound.y; } g_mouseRelX = mouseDat.lX; g_mouseRelY = mouseDat.lY; g_mouseRelZ = mouseDat.lZ; return RETCODE_SUCCESS; }
void nxInputManager::DInputLoop(DWORD dwMilliseconds) { std::map<LPDIRECTINPUTDEVICE8,DIJOYSTATE> mpStates; DIJOYSTATE idleState; ZeroMemory(&idleState,sizeof(DIJOYSTATE)); DataSender objSender(NX_DINPUT,0); while (isRunning) { for (std::set<LPDIRECTINPUTDEVICE8>::iterator it = stDInputDevices.begin();it!=stDInputDevices.end();++it) { LPDIRECTINPUTDEVICE8 ptDevice = *it; nxDeviceId uDeviceId = GetInputHandleId(ptDevice); HRESULT hr = ptDevice->Poll(); if (FAILED(hr)) { // Acquire and try again ptDevice->Acquire(); hr = ptDevice->Poll(); } // If it failed again, proceed to the next device if (FAILED(hr)) continue; // Process the data DIJOYSTATE newState; if (FAILED( hr = ptDevice->GetDeviceState( sizeof( DIJOYSTATE ), &newState ) )) continue; // Get the old state, creating it if it doesn't exist. DIJOYSTATE&oldState = mpStates.insert(std::pair<LPDIRECTINPUTDEVICE8,DIJOYSTATE>(ptDevice,idleState)).first->second; // Find the differences // Axis if (oldState.lX != newState.lX) objSender.SendData(0,true,newState.lX,uDeviceId); if (oldState.lY != newState.lY) objSender.SendData(1,true,newState.lY,uDeviceId); if (oldState.lZ != newState.lZ) objSender.SendData(2,true,newState.lZ,uDeviceId); if (oldState.lRx != newState.lRx) objSender.SendData(3,true,newState.lRx,uDeviceId); if (oldState.lRy != newState.lRy) objSender.SendData(4,true,newState.lRy,uDeviceId); if (oldState.lRz != newState.lRz) objSender.SendData(5,true,newState.lRz,uDeviceId); if (oldState.rglSlider[0] != newState.rglSlider[0]) objSender.SendData(6,true,newState.rglSlider[0],uDeviceId); if (oldState.rglSlider[1] != newState.rglSlider[1]) objSender.SendData(7,true,newState.rglSlider[1],uDeviceId); // POV for (unsigned char i=0;i<4;++i) { // Change the value to be in tenths of a degree instead of hundredths if (!IS_POV_CENTERED(newState.rgdwPOV[i])) newState.rgdwPOV[i] /= 10; if (oldState.rgdwPOV[i] != newState.rgdwPOV[i]) // The value is in tenths of a degree clockwise from north. -1 = center, 0 = top, 900 = right 1800 = bottom 2700 = left objSender.SendData(i,false,newState.rgdwPOV[i],uDeviceId,1); //extended of 1 means POV } // Buttons for (int i=0;i<32;++i) { if ((oldState.rgbButtons[i] & 0x80) != (newState.rgbButtons[i] & 0x80)) objSender.SendData(i,false,(newState.rgbButtons[i] & 0x80?INPUT_MAX:0),uDeviceId); } oldState = newState; } Sleep(dwMilliseconds); } }
bool ReadJoystick(F32 axes[MaxJoystickAxes], U32 &buttonMask, U32 &hatMask) { // mark: it's ok // mark: it's called "winJoystick" // mark: it's supposed to be gross. DIJOYSTATE2 js; // DInput joystick state if(!gJoystick) return false; if(FAILED(gJoystick->Poll() ) ) { HRESULT hr; hr = gJoystick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = gJoystick->Acquire(); return false; } // Get the input's device state if(FAILED(gJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &js ) ) ) return false; // The device should have been acquired during the Poll() F32 scale = 1 / 32768.0f; axes[0] = (F32(js.lX) - 32768.0f) * scale; axes[1] = (F32(js.lY) - 32768.0f) * scale; axes[2] = (F32(js.lZ) - 32768.0f) * scale; axes[3] = (F32(js.lRx) - 32768.0f) * scale; axes[4] = (F32(js.lRy) - 32768.0f) * scale; axes[5] = (F32(js.lRz) - 32768.0f) * scale; axes[6] = (F32(js.rglSlider[0]) - 32768.0f) * scale; axes[7] = (F32(js.rglSlider[1]) - 32768.0f) * scale; axes[8] = 0; axes[9] = 0; axes[10] = 0; axes[11] = 0; // check the state of the buttons: buttonMask = 0; U32 pov = js.rgdwPOV[0]; for( U32 i = 0; i < 12; i++ ) if((js.rgbButtons[i] & 0x80) != 0) buttonMask |= BIT(i); switch(pov) { case 0: hatMask |= ControllerButtonDPadUp; break; case 4500: hatMask |= ControllerButtonDPadUp | ControllerButtonDPadRight; break; case 9000: hatMask |= ControllerButtonDPadRight; break; case 13500: hatMask |= ControllerButtonDPadRight | ControllerButtonDPadDown; break; case 18000: hatMask |= ControllerButtonDPadDown; break; case 22500: hatMask |= ControllerButtonDPadDown | ControllerButtonDPadLeft; break; case 27000: hatMask |= ControllerButtonDPadLeft; break; case 31500: hatMask |= ControllerButtonDPadLeft | ControllerButtonDPadUp; break; } return true; }
//----------------------------------------------------------------------------- // Name: UpdateInput() // Desc: Update the user input. Called once per frame //----------------------------------------------------------------------------- void CMyApplication::UpdateInput() { if( NULL == m_pInputDeviceManager ) return; CMultiplayerInputDeviceManager::DeviceInfo* pDeviceInfos; DWORD dwNumDevices; // Get access to the list of semantically-mapped input devices m_pInputDeviceManager->GetDevices( &pDeviceInfos, &dwNumDevices ); // Loop through all devices and check game input for( DWORD i=0; i<dwNumDevices; i++ ) { // skip past any devices that aren't assigned, // since we don't care about them if( pDeviceInfos[i].pPlayerInfo == NULL ) continue; DIDEVICEOBJECTDATA rgdod[10]; DWORD dwItems = 10; HRESULT hr; LPDIRECTINPUTDEVICE8 pdidDevice = pDeviceInfos[i].pdidDevice; InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam; FLOAT fScale = 1.0f; if( pDeviceInfos[i].bRelativeAxis ) { // For relative axis data, the action mapper only informs us when // the delta data is non-zero, so we need to zero its state // out each frame pInputDeviceState->fAxisMoveUD = 0.0f; pInputDeviceState->fAxisRotateLR = 0.0f; // Scale the relative axis data to make it more equal to // absolute joystick data fScale = 5.0f; } hr = pdidDevice->Acquire(); hr = pdidDevice->Poll(); hr = pdidDevice->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), rgdod, &dwItems, 0 ); if( FAILED(hr) ) continue; // Get the sematics codes for the game menu for( DWORD j=0; j<dwItems; j++ ) { BOOL bButtonState = (rgdod[j].dwData==0x80) ? TRUE : FALSE; FLOAT fButtonState = (rgdod[j].dwData==0x80) ? 1.0f : 0.0f; FLOAT fAxisState = (FLOAT)((int)rgdod[j].dwData)/100.0f * fScale; switch( rgdod[j].uAppData ) { // Handle relative axis data case INPUT_ROTATE_AXIS_LR: pInputDeviceState->fAxisRotateLR = fAxisState; break; case INPUT_MOVE_AXIS_UD: pInputDeviceState->fAxisMoveUD = -fAxisState; break; // Handle buttons separately so the button state data // doesn't overwrite the axis state data, and handle // each button separately so they don't overwrite each other case INPUT_TURNLEFT: pInputDeviceState->bButtonRotateLeft = bButtonState; break; case INPUT_TURNRIGHT: pInputDeviceState->bButtonRotateRight = bButtonState; break; case INPUT_FORWARDTHRUST: pInputDeviceState->bButtonForwardThrust = bButtonState; break; case INPUT_REVERSETHRUST: pInputDeviceState->bButtonReverseThrust = bButtonState; break; case INPUT_FIREWEAPONS: pInputDeviceState->bButtonFireWeapons = bButtonState; break; case INPUT_ENABLESHIELD: pInputDeviceState->bButtonEnableShield = bButtonState; break; // Handle one-shot buttons case INPUT_DISPLAYGAMEMENU: if( bButtonState ) m_UserInput[0].bDoConfigureInput = TRUE; break; case INPUT_QUITGAME: if( bButtonState ) m_UserInput[0].bDoQuitGame = TRUE; break; } } } for( DWORD iPlayer=0; iPlayer<m_dwNumPlayers; iPlayer++ ) { // Process user input and store result into pUserInput struct m_UserInput[iPlayer].fAxisRotateLR = 0.0f; m_UserInput[iPlayer].fAxisMoveUD = 0.0f; m_UserInput[iPlayer].bButtonFireWeapons = FALSE; m_UserInput[iPlayer].bButtonEnableShield = FALSE; // Concatinate the data from all the DirectInput devices for( i=0; i<dwNumDevices; i++ ) { // Only look at devices that are assigned to this player if( pDeviceInfos[i].pPlayerInfo == NULL || pDeviceInfos[i].pPlayerInfo->dwPlayerIndex != iPlayer ) continue; InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam; // Use the axis data that is furthest from zero if( fabs(pInputDeviceState->fAxisRotateLR) > fabs(m_UserInput[iPlayer].fAxisRotateLR) ) m_UserInput[iPlayer].fAxisRotateLR = pInputDeviceState->fAxisRotateLR; if( fabs(pInputDeviceState->fAxisMoveUD) > fabs(m_UserInput[iPlayer].fAxisMoveUD) ) m_UserInput[iPlayer].fAxisMoveUD = pInputDeviceState->fAxisMoveUD; // Process the button data if( pInputDeviceState->bButtonRotateLeft ) m_UserInput[iPlayer].fAxisRotateLR = -1.0f; else if( pInputDeviceState->bButtonRotateRight ) m_UserInput[iPlayer].fAxisRotateLR = 1.0f; if( pInputDeviceState->bButtonForwardThrust ) m_UserInput[iPlayer].fAxisMoveUD = 1.0f; else if( pInputDeviceState->bButtonReverseThrust ) m_UserInput[iPlayer].fAxisMoveUD = -1.0f; if( pInputDeviceState->bButtonFireWeapons ) m_UserInput[iPlayer].bButtonFireWeapons = TRUE; if( pInputDeviceState->bButtonEnableShield ) m_UserInput[iPlayer].bButtonEnableShield = TRUE; } } }
BOOL JoystickInit (HWND hWindow, int iMin, int iMax, int iDeadZone) { if(JOY) { /* Find first available joystick */ if (FAILED (m_lpkDInput->EnumDevices ( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &m_lpkDIDevice, DIEDFL_ATTACHEDONLY)) ) { return FALSE; } /* Set joystick data format */ if(m_lpkDIDevice == NULL) { return FALSE; } if (FAILED(m_lpkDIDevice->SetDataFormat (&c_dfDIJoystick2))) { return FALSE; } /* Set joystick cooperative level */ if (FAILED(m_lpkDIDevice->SetCooperativeLevel (hWindow, DISCL_EXCLUSIVE | DISCL_FOREGROUND))) { return FALSE; } /* Set joystick axis ranges */ DIPROPRANGE kDIRange; kDIRange.diph.dwSize = sizeof(DIPROPRANGE); kDIRange.diph.dwHeaderSize = sizeof(DIPROPHEADER); kDIRange.diph.dwHow = 0; kDIRange.diph.dwObj = DIPH_DEVICE; kDIRange.lMin = iMin; kDIRange.lMax = iMax; if (FAILED(m_lpkDIDevice->SetProperty (DIPROP_RANGE, &kDIRange.diph))) { return FALSE; } /* Set joystick dead zone */ DIPROPDWORD kDIDeadZone; kDIDeadZone.diph.dwSize = sizeof(DIPROPDWORD); kDIDeadZone.diph.dwHeaderSize = sizeof(DIPROPHEADER); kDIDeadZone.diph.dwHow = 0; kDIDeadZone.diph.dwObj = DIPH_DEVICE; kDIDeadZone.dwData = iDeadZone * 100; if (FAILED (m_lpkDIDevice->SetProperty (DIPROP_DEADZONE, &kDIDeadZone.diph)) ) { return FALSE; } /* Acquire joystick */ HRESULT hRet = m_lpkDIDevice->Poll (); if (FAILED (hRet)) { hRet = m_lpkDIDevice->Acquire (); while (hRet == DIERR_INPUTLOST) { hRet = m_lpkDIDevice->Acquire (); } } return TRUE; } else { if (FAILED(m_lpkDInput->CreateDevice ( GUID_SysKeyboard, &m_lpkDIDevice, NULL)) ) { return FALSE; } if (FAILED(m_lpkDIDevice->SetDataFormat (&c_dfDIKeyboard))) { return FALSE; } /* Set joystick cooperative level */ if (FAILED(m_lpkDIDevice->SetCooperativeLevel (hWindow, DISCL_EXCLUSIVE | DISCL_FOREGROUND))) { return FALSE; } /* Acquire joystick */ HRESULT hRet = m_lpkDIDevice->Poll (); if (FAILED (hRet)) { hRet = m_lpkDIDevice->Acquire (); while (hRet == DIERR_INPUTLOST) { hRet = m_lpkDIDevice->Acquire (); } } return TRUE; } }
C_RESULT update_dx_gamepad(void) { /* static int32_t x = 0, y = 0; static bool_t refresh_values = FALSE; size_t res; static js_event js_e_buffer[64]; */ HRESULT hr; TCHAR strText[512] = {0}; // Device state text /* Direct Input gamepad state */ DIJOYSTATE2 js; static DIJOYSTATE2 previous_js; static bool function_first_call = true; static float roll = 0, pitch = 0, gaz=0, yaw=0; const char * linefiller=" "; // Poll the device to read the current state hr = g_pJoystick->Poll(); if( FAILED( hr ) ) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pJoystick->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return C_OK; } // Get the input's device state if( FAILED( hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &js ) ) ) return hr; // The device should have been acquired during the Poll() if (function_first_call) { printf("Sending flat trim - make sure the drone is horizontal at client startup.\n"); ardrone_at_set_flat_trim(); function_first_call=false; previous_js=js; return C_OK; } ARWin32Demo_AcquireConsole(); ARWin32Demo_SetConsoleCursor(0,14); // Process the gamepad data { switch(JoystickType) { /* Tests that if an event occured */ #define EVENTJS(I) ( js.rgbButtons[I-1] != previous_js.rgbButtons[I-1] ) #define TESTJS(I) ( js.rgbButtons[I-1] & 0x80 ) #define SETJS(I,J) if( js.rgbButtons[I-1] & 0x80 ) J(1); else J(0); /********************/ case GAMEPAD_PLAYSTATION3: pitch = js.lY/(1000.0f) /* belongs to [-1000:1000] */; roll = js.lX/(1000.0f) /* belongs to [-1000:1000] */; yaw = js.lZ/(1000.0f) /* belongs to [-1000:1000] */; gaz = js.lRz/(1000.0f) /* belongs to [-1000:1000] */; // Buttons hard coded for the Playstation3 SixAxis pad connected in USB mode on a Windows XP computer if (EVENTJS(9)) { if (TESTJS(9)) { ardrone_tool_set_ui_pad_start(0); ardrone_tool_set_ui_pad_select(1); printf("Sending emergency.%s\n",linefiller); } else { ardrone_tool_set_ui_pad_select(0); } } if (EVENTJS(10) && TESTJS(10)) { start^=1; ardrone_tool_set_ui_pad_start(start); printf("Sending start %i.%s\n",start,linefiller); } break; /********************/ case JOYSTICK_CYBORG_X: pitch = js.lY/(1000.0f) /* belongs to [-1000:1000] */; roll = js.lX/(1000.0f) /* belongs to [-1000:1000] */; yaw = js.lRz/(1000.0f) /* belongs to [-1000:1000] */; /* From MSDN : Direction controllers, such as point-of-view hats. The position is indicated in hundredths of a degree clockwise from north (away from the user). The center position is normally reported as - 1; but see Remarks. For indicators that have only five positions, the value for a controller is - 1, 0, 9,000, 18,000, or 27,000. */ switch (js.rgdwPOV[0]) { case 0: gaz = 1.0f; break; case 4500: gaz = 0.5f; break; case 13500: gaz = -0.5f; break; case 18000: gaz = -1.0f; break; case 22500: gaz = -0.5f; break; case 31500: gaz = +0.5f; break; default:gaz = 0.0f; } // Buttons hard coded for the Playstation3 SixAxis pad connected in USB mode on a Windows XP computer if (EVENTJS(2)||EVENTJS(3)||EVENTJS(4)||EVENTJS(5)) { if (TESTJS(2)||TESTJS(3)||TESTJS(4)||TESTJS(5)) { ardrone_tool_set_ui_pad_start(0); ardrone_tool_set_ui_pad_select(1); printf("Sending emergency.%s\n",linefiller); } else { ardrone_tool_set_ui_pad_select(0); } } if (EVENTJS(1) && TESTJS(1)) { start^=1; ardrone_tool_set_ui_pad_start(start); printf("Sending start %i.%s\n",start,linefiller); } break; /********************/ case GAMEPAD_LOGITECH_PRECISION: pitch = (float)js.lY/(1000.0f); roll = (float)js.lX/(1000.0f); yaw = (TESTJS(3))? (1.0f) : (TESTJS(1))? (-1.0f) : (0.0f) ; gaz = (TESTJS(4))? (1.0f) : (TESTJS(2))? (-1.0f) : (0.0f) ; if (EVENTJS(9)) { if (TESTJS(9)) { ardrone_tool_set_ui_pad_start(0); ardrone_tool_set_ui_pad_select(1); printf("Sending emergency.%s\n",linefiller); } else { ardrone_tool_set_ui_pad_select(0); } } if (EVENTJS(10) && TESTJS(10)) { start^=1; ardrone_tool_set_ui_pad_start(start); printf("Sending start %i.%s\n",start,linefiller); } if (EVENTJS(5) && TESTJS(5)) { ardrone_at_set_flat_trim(); printf("Sending flat trim.%s\n",linefiller); } break; /********************/ case GAMEPAD_RADIO_GP: pitch = (float)js.lZ/(1000.0f); roll = (float)js.lRz/(1000.0f); yaw = (float)js.lX/(1000.0f); gaz = -(float)js.lY/(1000.0f); if (EVENTJS(2)) { if (TESTJS(2)) { ardrone_tool_set_ui_pad_start(0); ardrone_tool_set_ui_pad_select(1); printf("Sending flat trim.%s\n",linefiller); ardrone_at_set_flat_trim(); } } if (EVENTJS(3)) { if (TESTJS(3)) { ardrone_tool_set_ui_pad_start(0); ardrone_tool_set_ui_pad_select(1); printf("Sending emergency.%s\n",linefiller); } else { ardrone_tool_set_ui_pad_select(0); } } if (EVENTJS(1)) { start= TESTJS(1)?1:0; // button 1 is an on/off switch that does not need to be maintained ardrone_tool_set_ui_pad_start(start); printf("Sending start %i.%s\n",start,linefiller); } break; default: pitch=roll=gaz=yaw=0.0f; /********************/ } // switch } // keyboardinuse if(!keyboard_in_use) { ardrone_tool_set_pcmd(1,roll, pitch, gaz, yaw, 0.0, 0.0); printf("[Pitch %f] [Roll %f] [Yaw %f] [Gaz %f]%\n",pitch,roll,yaw,gaz); } /* Keeps track of the last joystick state in a static variable */ previous_js=js; ARWin32Demo_ReleaseConsole(); return C_OK; }
//----------------------------------------------------------------------------- // Name: UpdateInputState() // Desc: Get the input device's state and display it. //----------------------------------------------------------------------------- HRESULT UpdateInputState( HWND hDlg ) { HRESULT hr; TCHAR strText[512] = {0}; // Device state text DIJOYSTATE2 js; // DInput Joystick state if( NULL == g_pJoystick ) return S_OK; // Poll the device to read the current state hr = g_pJoystick->Poll(); if( FAILED( hr ) ) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pJoystick->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // Get the input's device state if( FAILED( hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &js ) ) ) return hr; // The device should have been acquired during the Poll() // Display Joystick state to dialog // Axes StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lX ); SetWindowText( GetDlgItem( hDlg, IDC_X_AXIS ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lY ); SetWindowText( GetDlgItem( hDlg, IDC_Y_AXIS ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lZ ); SetWindowText( GetDlgItem( hDlg, IDC_Z_AXIS ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRx ); SetWindowText( GetDlgItem( hDlg, IDC_X_ROT ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRy ); SetWindowText( GetDlgItem( hDlg, IDC_Y_ROT ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.lRz ); SetWindowText( GetDlgItem( hDlg, IDC_Z_ROT ), strText ); // Slider controls StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rglSlider[0] ); SetWindowText( GetDlgItem( hDlg, IDC_SLIDER0 ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rglSlider[1] ); SetWindowText( GetDlgItem( hDlg, IDC_SLIDER1 ), strText ); // Points of view StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[0] ); SetWindowText( GetDlgItem( hDlg, IDC_POV0 ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[1] ); SetWindowText( GetDlgItem( hDlg, IDC_POV1 ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[2] ); SetWindowText( GetDlgItem( hDlg, IDC_POV2 ), strText ); StringCchPrintf( strText, 512, TEXT( "%ld" ), js.rgdwPOV[3] ); SetWindowText( GetDlgItem( hDlg, IDC_POV3 ), strText ); #if 0 // Fill up text with which buttons are pressed StringCchCopy( strText, 512, TEXT( "" ) ); for( int i = 0; i < 128; i++ ) { if( js.rgbButtons[i] & 0x80 ) { TCHAR sz[128]; StringCchPrintf( sz, 128, TEXT( "%02d " ), i ); StringCchCat( strText, 512, sz ); } } SetWindowText( GetDlgItem( hDlg, IDC_BUTTONS ), strText ); #else // Buttons BOOL Checked; for( int i = 0; i < 32; i++ ) { if( js.rgbButtons[i] & 0x80 ) Checked = CheckDlgButton(hDlg, IDC_BUTTON1 + i, BST_CHECKED); else Checked = CheckDlgButton(hDlg, IDC_BUTTON1 + i, BST_UNCHECKED); }; #endif return S_OK; }