Rev 557 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 552 | chris | 1 | /* |
| 2 | * com_gebauz_PonPonChun_JNITest.cpp |
||
| 3 | * |
||
| 4 | * Created on: 18.04.2013 |
||
| 5 | * Author: chiu |
||
| 6 | */ |
||
| 7 | |||
| 8 | |||
| 9 | #include <iostream> |
||
| 553 | chris | 10 | #include <Windows.h> |
| 554 | chris | 11 | #include <Windowsx.h> |
| 558 | chris | 12 | #include <CommCtrl.h> |
| 552 | chris | 13 | |
| 14 | #include "com_gebauz_PonPonChun_JNITest.h" |
||
| 15 | |||
| 16 | using namespace std; |
||
| 17 | |||
| 18 | JNIEXPORT void JNICALL Java_com_gebauz_PonPonChun_JNITest_hello(JNIEnv *env, jobject jthis, jstring data) |
||
| 19 | { |
||
| 20 | jboolean iscopy; |
||
| 21 | const char *charData = env->GetStringUTFChars(data, &iscopy); |
||
| 22 | cout << "Hello " << charData << endl; |
||
| 23 | env->ReleaseStringUTFChars(data, charData); |
||
| 24 | } |
||
| 25 | |||
| 554 | chris | 26 | WNDPROC wpOrigEditProc; |
| 27 | HWND hwnd; |
||
| 558 | chris | 28 | #define WM_REGISTERTOUCH (WM_USER + 0x0001) |
| 554 | chris | 29 | |
| 555 | chris | 30 | void HandleTouch(HWND hwnd, WPARAM wParam, LPARAM lParam) |
| 31 | { |
||
| 32 | UINT cInputs = LOWORD(wParam); |
||
| 33 | PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; |
||
| 34 | if (NULL != pInputs) |
||
| 35 | { |
||
| 36 | if (GetTouchInputInfo((HTOUCHINPUT)lParam, |
||
| 37 | cInputs, |
||
| 38 | pInputs, |
||
| 39 | sizeof(TOUCHINPUT))) |
||
| 40 | { |
||
| 41 | // process pInputs |
||
| 42 | |||
| 43 | wchar_t text[200]; |
||
| 44 | wsprintf(text, L"WM_TOUCH %d", cInputs); |
||
| 45 | |||
| 46 | ::SetWindowText(hwnd, text); |
||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | if (!CloseTouchInputHandle((HTOUCHINPUT)lParam)) |
||
| 51 | { |
||
| 52 | // error handling |
||
| 53 | } |
||
| 54 | } |
||
| 55 | else |
||
| 56 | { |
||
| 57 | // GetLastError() and error handling |
||
| 58 | } |
||
| 59 | delete [] pInputs; |
||
| 60 | } |
||
| 61 | else |
||
| 62 | { |
||
| 63 | // error handling, presumably out of memory |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 558 | chris | 67 | |
| 554 | chris | 68 | // Subclass procedure |
| 69 | LRESULT APIENTRY WindowSubClassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
| 70 | { |
||
| 71 | switch (uMsg) |
||
| 72 | { |
||
| 558 | chris | 73 | case WM_REGISTERTOUCH: |
| 554 | chris | 74 | { |
| 558 | chris | 75 | if (!RegisterTouchWindow(hwnd, TWF_WANTPALM)) |
| 76 | { |
||
| 77 | cout << "error registering touch window: " << GetLastError() << endl; |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | |||
| 81 | cout << "Registered touch" << endl; |
||
| 82 | } |
||
| 83 | break; |
||
| 84 | case WM_TOUCH: |
||
| 85 | /*{ |
||
| 554 | chris | 86 | short xPos = GET_X_LPARAM(lParam); |
| 87 | short yPos = GET_Y_LPARAM(lParam); |
||
| 88 | |||
| 89 | wchar_t text[200]; |
||
| 90 | wsprintf(text, L"HAHA %d, %d", xPos, yPos); |
||
| 91 | |||
| 558 | chris | 92 | ::SetWindowText(hwnd, text); |
| 93 | }*/ |
||
| 555 | chris | 94 | HandleTouch(hwnd, wParam, lParam); |
| 558 | chris | 95 | //cout << "TOUCH" << endl; |
| 554 | chris | 96 | break; |
| 97 | } |
||
| 98 | |||
| 99 | return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam); |
||
| 100 | } |
||
| 101 | |||
| 553 | chris | 102 | JNIEXPORT void JNICALL Java_com_gebauz_PonPonChun_JNITest_test(JNIEnv *env, jobject jthis, jlong jhwnd) |
| 103 | { |
||
| 554 | chris | 104 | hwnd = (HWND)jhwnd; |
| 553 | chris | 105 | |
| 554 | chris | 106 | wpOrigEditProc = (WNDPROC)::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)WindowSubClassProc); |
| 558 | chris | 107 | ::SendMessage(hwnd, WM_REGISTERTOUCH, 0, 0); |
| 554 | chris | 108 | |
| 558 | chris | 109 | /*BOOL result = ::SetWindowSubclass(hwnd, WindowSubClassProc2, 1, 0); |
| 110 | |||
| 111 | if (!result) |
||
| 112 | cout << "error subclassing" << endl;*/ |
||
| 113 | |||
| 554 | chris | 114 | //::SetWindowsHookEx(WH_CALLWNDPROC, &CallWndProc, NULL, ::GetCurrentThreadId()); |
| 556 | chris | 115 | |
| 558 | chris | 116 | /* jclass thisClass = env->GetObjectClass(jthis); |
| 556 | chris | 117 | |
| 557 | chris | 118 | jclass cls = env->FindClass("com/gebauz/PonPonChun/JNITest$Feedback"); |
| 119 | |||
| 120 | if (cls == NULL) |
||
| 121 | { |
||
| 122 | cout << "Class not found" << endl; |
||
| 123 | return; |
||
| 124 | } |
||
| 125 | |||
| 126 | cout << "After FindClass" << endl; |
||
| 127 | |||
| 128 | jmethodID midInit = env->GetMethodID(cls, "<init>", "(I)V"); |
||
| 129 | if (NULL == midInit) return; |
||
| 130 | |||
| 131 | cout << "Before construction" << endl; |
||
| 132 | |||
| 133 | jobject newObj = env->NewObject(cls, midInit, 1337); |
||
| 134 | |||
| 135 | cout << "After construction" << endl; |
||
| 136 | |||
| 137 | jfieldID fidMessage = env->GetFieldID(cls, "test", "Ljava/lang/String;"); |
||
| 138 | if (NULL == fidMessage) return; |
||
| 139 | env->SetObjectField(newObj, fidMessage, env->NewStringUTF("Hahahahahah")); |
||
| 140 | |||
| 141 | jfieldID fidY = env->GetFieldID(cls, "y", "F"); |
||
| 142 | if (NULL == fidY) return; |
||
| 143 | env->SetFloatField(newObj, fidY, 13.37f); |
||
| 144 | |||
| 145 | cout << "After Get Field ID" << endl; |
||
| 146 | |||
| 147 | jmethodID midCallBack = env->GetMethodID(thisClass, "callBack", "(Lcom/gebauz/PonPonChun/JNITest$Feedback;)V"); |
||
| 556 | chris | 148 | if (NULL == midCallBack) return; |
| 557 | chris | 149 | env->CallVoidMethod(jthis, midCallBack, newObj); |
| 556 | chris | 150 | |
| 557 | chris | 151 | cout << "Calling Callback" << endl; |
| 152 | |||
| 558 | chris | 153 | env->DeleteLocalRef(newObj);*/ |
| 553 | chris | 154 | } |