Subscribe to a java frame - windows 7 multitouch - JNI - cpp
-
Wednesday, December 21, 2011 10:44 AM
hello all,
I am currently developing a multitouch application for windows in Java.
Coding under windows, I try to retrieve raw messages that Windows sends to each 'touch'.
For this I created a dll in cpp which is supposed to retrieve data and modify one of my java objects passed as a parameter with the position of 'touch':JNIEXPORT jint findWindowFromJava(JNIEnv, jobject, jstring classname, jstring windowsname){ return (jint)findWindow(classname, windowsname); // get the handle of my java Frame } JNIEXPORT jboolean JNICALL init(JNIEnv, jobject, jlong hWnd){ //hWnd is the handle of the frame (the same as above HINSTANCE hInst = (HINSTANCE)GetWindowLong((HWND)hWnd, GWL_HINSTANCE); //get the instance of the frame MyRegisterClass(hInst); //Enable all gesture types GESTURECONFIG gestureConfig; gestureConfig.dwID = 0; gestureConfig.dwBlock = 0; gestureConfig.dwWant = GC_ALLGESTURES; // get all gestures BOOL result = SetGestureConfig((HWND)hWnd, 0, 1, &gestureConfig, sizeof(gestureConfig)); if (!result){ return FALSE; }else{ return TRUE; } } ATOM MyRegisterClass(HINSTANCE hInstance) // copy-paste to a fonctionnel project { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = L"SunAwtFrame"; // just for now wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); return RegisterClassEx(&wcex); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { cout << "Je rentre dans WndProc" << endl; switch (message) { break; case WM_GESTURE: return ProcessGestureMessage(hWnd, wParam, lParam); // one of my function case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }That's basically my dll. My problem:
The FindWindow returns me a non-zero, so the dll recognizes my JAVA JFrame.
The setGestureConfig is executed without error with the handler (HWND) of my window with FindWindow found.
But ... WndProc, which is supposed to activate each évenènement, is never called ...
I tried to make a call via registreClassEx MyRegisterClass (presented above) but with wcex.lpszClassName = L"SunAwtFrame" I have the error 1410 (class is already present ...why ?) it's necessary ?
my dll is loaded only once, L"SunAwtFrame" is the right class, as it is with this title that FindWindow find the right window.
How do i associate WndProc with my Java Frame?
Sincerely,
All Replies
-
Wednesday, December 21, 2011 12:04 PM
If the window belongs to your Java program, then try subclassing it. Replace the window procedure using SetWindowLongPtr and keep the original one. After processing messages inside your window procedure, call the original one using CallWindowProc [http://blogs.msdn.com/b/oldnewthing/archive/2009/05/07/9592397.aspx]. You do not need to register a new class.
-
Wednesday, December 21, 2011 4:24 PM
A big thank :)
however, i have an other problem :s
if the message is WM_GESTURE, I get the message information (particulary the dwFlags).
At the end of my gest, I noticed that I receive many messages with dwFlags = 2 (GID_END) thendwFlags = 0. I do not know what is this 0
And I did not find what was the case for the movement of fingers on the panel of the frame ... (if I do the tests, dwFlags = 0 dwFlags when I move my fingers so i think it's 0 but ... not sure)
i get message like that :
LRESULT ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam) { //init the gesture GESTUREINFO gi; gi.cbSize = sizeof(GESTUREINFO); gi.dwFlags = 0; gi.ptsLocation.x = 0; gi.ptsLocation.y = 0; gi.dwID = 0; gi.dwInstanceID = 0; gi.dwSequenceID = 0; BOOL bResult = GetGestureInfo((HGESTUREINFO)lParam, &gi); //enqueue the gesture for a close using _eventQueue.push_back(gi); CloseGestureInfoHandle((HGESTUREINFO)lParam); return 0; }
I don't understang why I have many messages with dwFlags = 2 ( normally, only one shouch be sufficient, right?)0 si a good number for the move?
dwFlags is never equal to 4.
- Edited by gizmoIchitzo Wednesday, December 21, 2011 4:24 PM
-
Thursday, December 22, 2011 8:05 AM
After more research on the web, I discovered that my swith(message) was wrong ... (in the WndProc function)
That I want is WM_TOUCH and not WM_GESTURE, because I would recognize the touch up and touch down, not the gesture ... (shame on me ...
But if I create the case WM_TOUCH, nothing happens (this case is never true :( )
My Java Frame only recognizes gesture, but not the touch ... any idea of why?
I have add RegistertouchWindow but it returns me an error 5 (access denied )
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { cout << "message WndProc : " << message << endl; switch (message) { break; case WM_GESTURE: return 0; case WM_TOUCH: // never use :( WHY ? return ProcessGestureMessage(hWnd, wParam, lParam); case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
sincerely,
- Edited by gizmoIchitzo Thursday, December 22, 2011 8:13 AM
- Edited by gizmoIchitzo Thursday, December 22, 2011 8:19 AM
- Edited by gizmoIchitzo Thursday, December 22, 2011 8:52 AM
-
Thursday, March 29, 2012 3:32 PM
Hello again.
I still have a problem with my JFrame and the RegisterTouchWindow method :
When i use the RegisterTouchWindow(HWNDJFrame, 0) i received a error 5. According to msdn :
The function fails with ERROR_ACCESS_DENIED if the calling thread does not own the specified window.
But ... i don't know how to do to put my JFrame into the calling thread :-(
someone has an idea ?
-
Thursday, August 09, 2012 12:15 PM
Hi,
I am in same boat as you were in March, did you find a decent solution to the challenge?
Thanks!
- Edited by tenali_rama Friday, August 10, 2012 7:40 AM typo
-
Friday, March 15, 2013 1:58 PM
I'm trying to find a simple, straight forward example integrating multi-touch with Java. Did you ever get your application working?
Mike

