See the question and my original answer on StackOverflow

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;