Pen input in Windows using C++ - c++

How can I access pen input with pressure on Windows? I am making a paint program, and had been using wintab, but wintab does not exist on my new computer. Wintab seems to be deprecated, but there are apparently some newer APIs called Windows Ink and Tablet PC.
The problem is that I cannot find documentation or an example of how to actually use a recent pen API. The API needs to be usable from a normal, unmanaged C++ desktop application. Also, I would really rather avoid UWP if possible, because I don't want to deal with "deployment" or "signing".
Where is an SDK I can download that has C/C++ headers and libraries that will give me raw pen input?

I got better results using the Realtimestylus API instead of wintab. Because wintab doesn't seem to return packets frequent enough for smooth lines when drawing.
The windows RTS API gave me more information packets, thus smoother results when drawing, and also more pen information can be accessed such as tilt and pen button presses.
there's a nice small demo app using RealTimeStylus with SDL:
https://backworlds.com/under-pressure/
It includes comments in the implementation, where it explains how to access raw tablet input.
The sample code contains an eventhandler class derived from the interface class IStylusSyncPlugin from rtscom.h.
With this interface you can register pen and touch events using STDMETHODS, for example: STDMETHOD(StylusButtonDown){}.
To get the actual pen position in screen coordinates is a bit difficult. As you first need to get the x,y coordinates as packets, using STDMETHOD(Packets). You will also need to describe which packets you want to receive and in what order using: IRealTimeStylus::GetPacketDescriptionData().
Lastly you need to convert the X, Y input into screen-coordinates depending on the dpi,
using Gdiplus::Graphics::GetDpiX()
X = dpiX * (float)pLastPacket[g_lContexts[iCtx].x] / 2540;
Y = dpiY * (float)pLastPacket[g_lContexts[iCtx].y] / 2540;
All this is provided in the example code by Anders Ekermo.
Hope it helps.

Look at RealTimeStylus and the MS Pointer API (WM_PointerXxx messages). These are two different ways.

Related

full screen and zoom in Koolplot

I'm trying to graph some things in C++ and Koolplot seems like a very simple and suitable library to do so with. I'm stuck, however, on finding some documentation about it that allows me to fullscreen the application (or resize it like you can do so on lots of applications, chrome, word, discord...). As well as this, I can't find or see how i can allow the user to drag the graph around with the mouse as well as zooming into a point of a scatterplot or function. If anyone has any ideas about these things i'd appreciate it, thanks.
The short reply is: cannot do.
Koolplot uses for drawings of the charts a modernized version of the venerable BGI driver. It was invented once upon a time, when personal computers were still running on some DOS version. Those times the graphics were full screen, hence of fixed size. This particularity was kept in the modernized WinBGIm library.
Zooming or panning properly a chart present on the screen require access from the drawing/painting routines of Koolplot to the data to be shown. This is not the case. If you look once again in the source code, you will note that in the implementation efforts were made to keep separated data to be plot from the actual drawing on the screen.
In conclusion, to do what you want, you will have to modify WinBGIm such that it manages correctly a drawing surface of variable dimensions and modify koolplot such that data to be shown is owned by (or aggregated with) Plotstream class.

Get image data of known process

For Imageprocessing I want to get all pixel information from a given process.
Concrete its for testing an image hashing algorithm for identifying hearthstone cards, so i need to get a screenshot of the given process.
How can I solve it in windows?
My idea so far:
Get the process name.
Get the process ID
Get Window Handle
I have no idea how to go further from this point.
I hope it understandable what I want to achieve.
Unfortunately, there is no general method for getting the pixels of a particular window that I would be aware of. Depending on how the target application draws itself, this task can be very simple or very complicated. If we were talking about an application that uses good old GDI, then you could just get yourself an HDC to the window via GetWindowDC() and BitBlt/StretchBlt the content over into a bitmap of your own.
Unfortunately, the target application in your case appears to be a game. Games typically use 3D graphics APIs like Direct3D or OpenGL for drawing. Assuming that you cannot simply modify the target application to just send the desired data over to you out of its own free will, the only way to specifically record output from such applications that I'm aware of is to hook into the graphics API and capture the data from underneath the API. This can be done. However, implementing such a system is quite involved. There might be existing libraries to aid with writing such applications, but I don't know any that I could recommend here. If you don't have to capture the game content in real-time, you could just use a screen recording application to, e.g., record a video and then use that video as input for your algorithm. There are also graphics debugging tools like NSight Graphics or RenderDoc that you could use. Be aware that games, particularly online games, these days often have cheat protection systems that are likely to get very angry at you if you attempt to hook into the game…
Apart from all that, one alternative approach might be to use DXGI Output Duplication to just capture the entire desktop. While you won't be able to target one specific application (as far as I know), this would potentially have several advantages: First of all, it's only moderately complex to set up compared to a fully-fledged API-hook-based approach. Second, it should work regardless of what API the target application uses and even if the application is in fullscreen mode. Third, since you will have the data delivered straight from the operating system, you shouldn't have any issues with cheat protection. You can use MonitorFromWindow() to get the monitor your target window appears on and then enumerate all outputs of all DXGI adapters to find the one that corresponds to that HMONITOR…

what's the best approach to design this simple ReactNative AR app?

I'm trying to write a simple AR app in ReactNative, it should simply see 4 predefined markers and draw a rectangle as a boundary on the live preview of the camera, the thing is I'm trying to do the processing in C++ using opencv so as to have the logic of the app in one place accessible to both Android & IOS.
here's what I've been thinking
write the OS dependent code to open the camera and get permissions in (java/ObjC) & the C++ part to do processing on each frame.
call the C++ code (from within the native code) on each frame, and that should return lets say coordinates for the markers.
draw the rect if 4 markers found on the preview in native code (No idea how to achieve this so far but I think it will be native code).
expose that preview (the live preview with the drawn view) to ReactNative (Not sure about that or how to achieve it)
I've looked at the react native camera component but it doesn't provide access to frames & if that's even possible, I'm not sure if it would be a good idea to send frames over the bridge between JS & java/ObjC.
the problem is that I'm not sure of the performance or if that is even possible.
if you know of any ReactNative library that would be great.
Your steps seem sound. After processing the frame in C++, you will need to set the application properties RCTRootView.appProperties in iOS, and emit an event using RCTDeviceEventEmitter on Android. So, you will need an Objective-C wrapper for your C++ code on iOS and a Java wrapper on Android. In either case, you should be able to use the same React Native code for actually drawing the rectangle on top of the camera preview. You're right that the React Native camera component does not have an API for getting individual frames from the camera, so you'll need to write that code natively for each platform.

Is there a way to use both the PEN and TOUCH together on Windows "POINTER" API?

Windows 10 when you use the "POINTER" api for a "unified" way of getting input from all pointing devices has some quirks.
Some for good design reasons but it does not serve all cases.
They disable touch input when the stylus or pen is being used. Not a HW issue.
So if I want to drag the space with a finger while I am drawing a line with the pen, can't do that or hold down a button while using the pen etc.
Is there a way to turn off the "disable touch while pen is down" "feature" in the windows 10 API ?? so I can get simultaneous input from both ?
I know that this works for sure with RAWINPUT, but then you'll need to implement parsing for the raw touchscreen digitizer input data for every device that you want to support.
I'm still researching myself if there is another API that will allow you to receive the unfiltered touch events in a device-independent format.

GetwindowoffsetEx in windows XP and up

I have an visaul object up and running
GetwindowoffsetEx moved the canvas around
But I cannot change the size of the canvas to my needs
Like should I not beable to change the canvas size for a A4-A3 printer or to a picture size
can this be done using the windows API
I do not seem to get the instructions to do this.
I take it that if I want a Zoom, I strech draw from another cavuas
am I asking the obvious in all this.
Lex Dean
I'm struggling to understand exactly what I need but you seem to want to map between two coordinate spaces in GDI.
Whilst you can use the fully general SetWorldTransform(), I suspect you are better off with the following functions:
SetWindowOrgEx(), SetWindowExtEx()
SetViewportOrgEx(), SetViewportExtEx()
The MSDN documentation also includes a full list of functions related to coordinate space transformations.