简体   繁体   中英

WM_POINTER and High DPI settings

I've been working for a while with the Windows 8 Touch API ( WM_POINTERDOWN / WM_POINTERUPDATE / WM_POINTERUP ) on a desktop touch screen. Then I tried my test program on a Windows 8 tablet and found out that my application was not able to detect accurately where the user was touching the screen.

Using the mouse on the other hand, worked fine: I got the correct coordinates. Since I have the EnableMouseInPointer(TRUE) mode active it means that the same code is being used to process the mouse events and the touch events, which at least means that my code is somewhat working correctly.

What I found out, is that the tablets have the High DPI mode enabled to make it possible for the users to touch what would be otherwise very small on the screen. When I changed the DPI on the tablet to remove the scaling my application worked fine, when I upped the DPI on my desktop screen things got wrong. (And yes, my application is High DPI Aware)

The annoying thing is that apparently the coordinates I receive from the touch interface are not the same depending of the device used:

  • if the user used the mouse, the coordinates are scaled to take into consideration the High DPI scaling.
  • if the user used the touch screen, the coordinates are not scaled and are in physical pixels

So, what would be the correct way to handle that?

An obvious hack would be to check the pointerType member of the POINTER_INFO struct, and apply some rescaling depending of the type ( PT_TOUCH or PT_MOUSE ), but as far as I could see it is not documented anywhere, and for example I have no idea if a PT_PEN should be rescaled or not.

That does not seem very elegant and future proof.

Any suggestion on how to do that cleanly would be welcome.

If you have processes that are running at different DPI awareness levels (private, inter-process communications are not virtualized) you can run "SetParent" across processes so that the DPI awareness level will be inherited from the new parent. http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx#input_issues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM