Author Topic: Windows 10 WM_POINTER (touch API)  (Read 4718 times)

0 Members and 1 Guest are viewing this topic.

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Windows 10 WM_POINTER (touch API)
« on: October 01, 2016, 11:13:52 AM »
WINDOWS 10 SDK

For those wanting to write applications that could run on a touch screen, you should get familiar with the WM_POINTER API.

It works with: finger, stylus, touchpad and mouse.

Warning, the value (in red) returned by the POINTER_INFO structure are DPI aware.

TYPE POINTER_INFO
   pointerType AS DWORD      
   pointerId AS DWORD      
   frameId AS DWORD
   pointerFlags AS DWORD
   sourceDevice AS DWORD '// SYSTEM INT on 64-bit      
   hwndTarget AS DWORD   '// SYSTEM INT on 64-bit
   ptPixelLocation is POINTAPI
   ptHimetricLocation is POINTAPI
   ptPixelLocationRaw is POINTAPI
   ptHimetricLocationRaw is POINTAPI

   dwTime AS DWORD
   historyCount AS DWORD
   inputData AS DWORD
   dwKeyStates AS DWORD
   PerformanceCount AS QUAD
   ButtonChangeType AS DWORD
   alignment__ AS LONG   '// 4-byte int
END TYPE '// 88 bytes (96 en 64-bit)

%POINTER_MESSAGE_FLAG_NEW               = &h00000001 '// New pointer
%POINTER_MESSAGE_FLAG_INRANGE           = &h00000002 '// Pointer has not departed
%POINTER_MESSAGE_FLAG_INCONTACT         = &h00000004 '// Pointer is in contact
%POINTER_MESSAGE_FLAG_FIRSTBUTTON       = &h00000010 '// Primary action
%POINTER_MESSAGE_FLAG_SECONDBUTTON      = &h00000020 '// Secondary action
%POINTER_MESSAGE_FLAG_THIRDBUTTON       = &h00000040 '// Third button
%POINTER_MESSAGE_FLAG_FOURTHBUTTON      = &h00000080 '// Fourth button
%POINTER_MESSAGE_FLAG_FIFTHBUTTON       = &h00000100 '// Fifth button
%POINTER_MESSAGE_FLAG_PRIMARY           = &h00002000 '// Pointer is primary
%POINTER_MESSAGE_FLAG_CONFIDENCE        = &h00004000 '// Pointer is considered unlikely to be accidental
%POINTER_MESSAGE_FLAG_CANCELED          = &h00008000 '// Pointer is departing in an abnormal manner

DECLARE FUNCTION GerPointerInfo LIB "USER32.DLL" ALIAS "GerPointerInfo" (BYVAL nPID AS DWORD, pif AS POINTER_INFO) AS LONG
DECLARE FUNCTION IsMouseInPointerEnabled LIB "USER32.DLL" ALIAS "IsMouseInPointerEnabled" () AS LONG
DECLARE FUNCTION EnableMouseInPointer LIB "USER32.DLL" ALIAS "EnableMouseInPointer" (BYVAL nEnable AS LONG) AS LONG

FUNCTION IS_POINTER_FLAG_SET_WPARAM (BYVAL wParam AS DWORD, BYVAL nFlag AS DWORD) AS LONG
LOCAL nRet AS LONG
IF (wParam AND nFlag) = nFlag THEN nRet = -1
FUNCTION = nRet
END FUNCTION

FUNCTION GET_POINTERID_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = LO(INTEGER, wParam)
END FUNCTION

FUNCTION IS_POINTER_NEW_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_NEW)
END FUNCTION

FUNCTION IS_POINTER_INRANGE_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_INRANGE)
END FUNCTION

FUNCTION IS_POINTER_INCONTACT_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_INCONTACT)
END FUNCTION

FUNCTION IS_POINTER_FIRSTBUTTON_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIRSTBUTTON)
END FUNCTION

FUNCTION IS_POINTER_SECONDBUTTON_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_SECONDBUTTON)
END FUNCTION

FUNCTION IS_POINTER_THIRDBUTTON_WPARAM(BYVAL wParam AS DWORD)
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_THIRDBUTTON)
END FUNCTION

FUNCTION IS_POINTER_FOURTHBUTTON_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FOURTHBUTTON)
END FUNCTION

FUNCTION IS_POINTER_FIFTHBUTTON_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIFTHBUTTON)
END FUNCTION

FUNCTION IS_POINTER_PRIMARY_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_PRIMARY)
END FUNCTION

FUNCTION HAS_POINTER_CONFIDENCE_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_CONFIDENCE)
END FUNCTION

FUNCTION IS_POINTER_CANCELED_WPARAM(BYVAL wParam AS DWORD) AS LONG
FUNCTION = IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_CANCELED)
END FUNCTION


I have attached to this post a WMpointer.exe D2D demo, to run on Windows 10 with touchscreen (surface 3, or surface book, or ASUS Transformer).
You can have the best experience with the fingers, however on a non-touchscreen you can still use the mouse with dynamic effects.

« Last Edit: October 01, 2016, 10:44:36 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Online Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2534
    • Josť Roca Software
Re: Windows 10 WM_POINTER (touch API)
« Reply #1 on: October 01, 2016, 11:45:41 AM »
> Warning, the value (in red) returned by the POINTER_INFO structure are DPI aware.

As it should be. This behavior is expected in the new APIs.

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Windows 10 WM_POINTER (touch API)
« Reply #2 on: October 01, 2016, 12:05:27 PM »
A good thing is also to compare with the LOINT, HIINT values of wParam (all WM_MOUSE messages), that are always given in true pixel coordinates.

Just like window coordinates (GetWindowRect).

« Last Edit: October 01, 2016, 12:10:08 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2022
    • www.zapsolution.com
Re: Windows 10 WM_POINTER (touch API)
« Reply #3 on: October 01, 2016, 04:25:33 PM »
First post of this thread has been updated with a D2D demo attachment, to try on a touchscreen.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com