i have notice that using the joyGetPosEx() function, when the joystick isn't connected, that the memory, that the application uses, is increasing.
so is there another way just for see if 1 joystick is connected to pc?

How is the joystick connected to the computer? Analog game port, serial port, usb port? What?

USB

for use the WM_INPUT_DEVICE_CHANGE message, i must use the RegisterRawInputDevices() : https://msdn.microsoft.com/en-us/library/windows/desktop/ms645591%28v=vs.85%29.aspx

see the 'Community Additions'.
so i did:

case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                        WindowMain = HandleWindow;

                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);

                    RAWINPUTDEVICE rid;

                    rid.usUsagePage = 1;
                    rid.usUsage     = 4; // Joystick
                    rid.dwFlags     = 0;
                    rid.hwndTarget  = inst->hwnd;

                    if(!RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)))
                        SetWindowText(inst->hwnd,"error");
                }
                break;


                case 0x00FE: //#define WM_INPUT_DEVICE_CHANGE          0x00FE
                {
                    SetWindowText(inst->hwnd,"enter device");

                    return 0;
                }
                break;

i'm using windows 7. but the message isn't activated when i connect or disconnect a device :(

finally works ;)

case 0x00FE:
                {

                    if(wParam==1)
                    {
                        SetWindowText(inst->hwnd,"enter device");
                    }
                    else if(wParam==2)
                    {
                        SetWindowText(inst->hwnd,"exit device");
                    }


                    return 0;
                }
                break;

                case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                        WindowMain = HandleWindow;

                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);

                    RAWINPUTDEVICE rid;

                    rid.usUsagePage = 1 ;
                    rid.usUsage     = 4; // Joystick
                    rid.dwFlags     = 0x00002000;
                    rid.hwndTarget  = inst->hwnd;

                    if(!RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)))
                        SetWindowText(inst->hwnd,"error");
                }
                break;

how use the GetRawInputDeviceInfo() for test if a joystick is connected to pc?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.