Click to See Complete Forum and Search --> : I love themouse! why won't he speak to me?
eyalW12
February 17th, 2006, 04:27 PM
Hello my fellow programmers,
excuse my lame English...
I've been searching for months for someone to help me on this,
I'm a Java programmer, but there some things that java just can't handle...
I need to get the mouse coordinates on windows.
herer the deal:
I program in Java, so i need someone to write me a tiny bit of code in C++ to help me complete a project I'm working on.
[Clerification: The mouse coordinates needed are the screen ones, NOT the application ones. Moreover, the mouse should be free to work on WIN, untill the mouse middle button is clicked and from there on untill it is released, coordinates needs to be captured]
contact me on my ICQ# 196601267
(please! its my 12G project...)
Programmers unite!...
Hack the planet...
blah blah blah...
UnfitElf
February 17th, 2006, 10:24 PM
Is this going to be windows based, or does your project require it to be used on different operating systems?
eyalW12
February 18th, 2006, 04:07 AM
Only on windows for now...
will u contact my icq?
Notsosuperhero
February 18th, 2006, 04:30 AM
Have a look at this function:
GetCursorPos() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/getcursorpos.asp)
UnfitElf
February 18th, 2006, 05:38 AM
I will try to help as much as possible but i do not have alot of time at the moment as i am already working on a large project.
Could you please post more specifics of what you require?
Thanks,
P.S. (i do not have ICQ)
You can send me an e-mail if you wish, tho i cannot give this prioritay over what i am already required to do.
eyalW12
February 18th, 2006, 06:15 AM
Thank you for your time, I really apreciate it.
It really sould not take a long time after we'll understend each other.
What is needed is integration of Java and C++,
a known interface which binds the two is JNI.
You should build a DLL file according to the JNI coding conventions (as they are stated below in the file) and then Java could call native functions declared on your DLL.
first we need to agree on what functions should be declared on the dll and then u could write them.
My idea is that I will call a function from ur dll which we'll call accept(), and then at ur side, the function waits for a middle mouse dragging action, which while at it, the function shall save the coordinates of the mouse, and when the middle mouse button is relased the function should return the coordinates.
(first u need to install java toolkit from sun.com so u'll have "jni.h" libary)
An unlimited array, called "Vector" in java, is spose to be returned from ur function.
the only thing I'm worried about is how will u create a java Object such as Vector, maybe in C++ u have ur own array type but u cant just send it back I guess...
here is the interface declared on "Test.h":
/* it is machine generated */
#include <jni.h>
/* Header for class Test */
#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Test
* Method: accept
* Signature: ()Ljava/util/Vector;
*/
JNIEXPORT jobject JNICALL Java_Test_accept
(JNIEnv *, jobject); //function declaration, dont change it, implement it
#ifdef __cplusplus
}
#endif
#endif
eyalW12
February 18th, 2006, 06:19 AM
In case the Vector thing wont work, a plan B is needed: just implement the next functions that
a. checks is the middle mouse is down.
b. returns the mouse x
c. returns the mouse y
(probebly sums in slower actions)
UnfitElf
February 18th, 2006, 05:04 PM
Ok, ive never done anything like this b4 in terms of JNI, so its completely new to me..
however just to see if we are on the right path counld you please test the following attachment. Small steps are good steps ;)
Thanks,
Daniel
UnfitElf
February 18th, 2006, 09:27 PM
If the above worked (i have no way of testing it) then try the folloing, it should be another step in the right direction..
With this one you should get a messagebeep on every mouse event.
Thanks
eyalW12
February 19th, 2006, 03:21 PM
thank u again for helping me, and dedicating ur time,
I've been searching for months for somebody...
I tried the first DLL and got the next response for the following main func.:
public static void main(String ar[])
{
System.out.println("Hello world from Java");
Test test = new Test();
test.accept();
}
output:
Hello world from Java
Exception in thread "main" java.lang.NullPointerException
at Test.accept(Native Method)
at Test.main(Test.java:13)
Hello Form C++ Dll
^^^^^^^^^^^^
meaning, ur function was called succesfully. we can say that for sure by the output. but an exception followed the input, sont know why. i guess its because of the "return" or Vector...
the second DLL output:
Hello world from Java
Exception in thread "main" java.lang.UnsatisfiedLinkError: accept
at Test.accept(Native Method)
at Test.main(Test.java:13)
I dont know what u wrote into both of the dll's, so send me the source so i could too understend what was intended to happen, what succesfuly happend or didn't happen. so we could discuss further tries.
for now, lets try the simple interface stated below which allows me to get the mouse x coord - this will be a good "return" try app:
[special attention to the return type called "jint" (java int i spose), do u know how to return that kind of type?]
/* machine generated */
#include <jni.h>
/* Header for class Test */
#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Test
* Method: getMouseX
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Test_getMouseX
(JNIEnv *, jobject); //the same routine... implementation needed
#ifdef __cplusplus
}
#endif
#endif
eyalW12
February 19th, 2006, 04:09 PM
Following whats written above, my last response,
I found this next page which i think specify an example as to how u can return java types from c++
http://www.devarticles.com/c/a/Java/Interfacing-With-C-From-Java-With-JNI-Part-2/2/
[u really need to install icq (www.icq.com) :) ]
UnfitElf
February 19th, 2006, 04:39 PM
Hi eyalW12,
good to know what first example at least called the function..
I have other commitments today however i have installed ICQ (324054990) and i should be able to spend some time on it tonight (in about 6-7 hours time).
Thanks
eyalW12
February 20th, 2006, 07:01 AM
k, i see u added me.
be online on ICQ when u're free
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.