Search code examples
c++winapitouchmultiple-monitors

Discover which monitor has touch capabilities on Windows 10


I have a two-monitor setup running on Windows 10 and my secondary monitor is a touch-screen. I can detect both monitors with EnumDisplayMonitors and discover that there is a digitizer present with GetSystemMetrics(SM_DIGITIZER). I'd like my app window to open on the touch monitor, but I can't find any function that tells me which monitor the digitizer "belongs" to.

In the absence of a solution, I suppose I could have a start-up sequence during which the user is asked to tap the touch screen, then my code could move the window to the corresponding monitor. I'd just like it to be slicker than that.

Any ideas?


Solution

  • GetPointerDevices function give you that information. POINTER_DEVICE_INFO contains monitor handle and device pointer type in the same structure:

    typedef struct tagPOINTER_DEVICE_INFO {
      DWORD               displayOrientation;
      HANDLE              device;
      POINTER_DEVICE_TYPE pointerDeviceType; // can be POINTER_DEVICE_TYPE_TOUCH see below
      HMONITOR            monitor; // Monitor handle
      ULONG               startingCursorId;
      USHORT              maxActiveContacts;
      WCHAR               productString[POINTER_DEVICE_PRODUCT_STRING_MAX];
    } POINTER_DEVICE_INFO;
    
    typedef enum tagPOINTER_DEVICE_TYPE {
      POINTER_DEVICE_TYPE_INTEGRATED_PEN,
      POINTER_DEVICE_TYPE_EXTERNAL_PEN,
      POINTER_DEVICE_TYPE_TOUCH,
      POINTER_DEVICE_TYPE_TOUCH_PAD,
      POINTER_DEVICE_TYPE_MAX
    } POINTER_DEVICE_TYPE;