if(pDevices[i].state.rgdwPOV[j] ^ joystick.rgdwPOV[j]) { int state = getPovState((pDevices[i].state.rgdwPOV[j] ^ joystick.rgdwPOV[j]) & joystick.rgdwPOV[j]);
if(LOWORD(pDevices[i].state.rgdwPOV[j]) != LOWORD(joystick.rgdwPOV[j])) { int state = getPovState(joystick.rgdwPOV[j]);
static void checkJoypads(){  DIDEVICEOBJECTINSTANCE di;  ZeroMemory(&di,sizeof(DIDEVICEOBJECTINSTANCE));  di.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);  int i =0;  DIJOYSTATE joystick;    for(i = 1; i < numDevices; i++) {    HRESULT hret = pDevices[i].device->Acquire();        if(pDevices[i].isPolled)      ((LPDIRECTINPUTDEVICE2)pDevices[i].device)->Poll();        hret = pDevices[i].device->GetDeviceState(sizeof(joystick), &joystick);    int j;    if(pDevices[i].first) {      memcpy(&pDevices[i].state, &joystick, sizeof(joystick));      pDevices[i].first = FALSE;      continue;    }        for(j = 0; j < pDevices[i].nButtons; j++) {      if(((pDevices[i].state.rgbButtons[j] ^ joystick.rgbButtons[j])           & joystick.rgbButtons[j]) & 0x80) {        HWND focus = GetFocus();        SendMessage(focus, JOYCONFIG_MESSAGE, i,j+128);      }          }    for(j = 0; j < pDevices[i].nAxes && j < 8; j++) {      LONG value = pDevices[i].axis[j].center;      LONG old = 0;      switch(pDevices[i].axis[j].offset) {      case DIJOFS_X:        value = joystick.lX;        old = pDevices[i].state.lX;        break;      case DIJOFS_Y:        value = joystick.lY;        old = pDevices[i].state.lY;             break;      case DIJOFS_Z:        value = joystick.lZ;        old = pDevices[i].state.lZ;             break;      case DIJOFS_RX:        value = joystick.lRx;        old = pDevices[i].state.lRx;            break;      case DIJOFS_RY:        value = joystick.lRy;        old = pDevices[i].state.lRy;            break;      case DIJOFS_RZ:        value = joystick.lRz;        old = pDevices[i].state.lRz;            break;      case DIJOFS_SLIDER(0):        value = joystick.rglSlider[0];        old = pDevices[i].state.rglSlider[0];           break;      case DIJOFS_SLIDER(1):        value = joystick.rglSlider[1];        old = pDevices[i].state.rglSlider[1];           break;      }      if(value != old) {        if(value < pDevices[i].axis[j].negative)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1));        else if (value > pDevices[i].axis[j].positive)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<1)+1);      }    }    for(j = 0;j < 4 && j < pDevices[i].nPovs; j++) {      if(pDevices[i].state.rgdwPOV[j] ^ joystick.rgdwPOV[j]) {        int state = getPovState((pDevices[i].state.rgdwPOV[j] ^ joystick.rgdwPOV[j]) & joystick.rgdwPOV[j]);                if(state & POV_UP)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x20);        else if(state & POV_DOWN)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x21);        else if(state & POV_RIGHT)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x22);        else if(state & POV_LEFT)          SendMessage(GetFocus(), JOYCONFIG_MESSAGE, i, (j<<2)+0x23);      }    }    memcpy(&pDevices[i].state, &joystick, sizeof(joystick));  }}