Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse X & Y 1

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Hi I'm writting a function that will detirmine if the mouse is within a givin radious of an objects. This is mainly just to test my abbility so no code please, I just need to know what is the command or variable to detect the mouse X & Y.


Thanks,

*moo spelled backwords is oom
 
No I want to make a command for within a radius so I need Xy cordinates
 
use the timer function in conjunction with the GetCursorPos API call. :)

I'll be glad to give you more hints :) Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
whats the api call thats all I wanted,

Thanks
 
Okay I'm new to this data thing, how do I get the x and y out of the ip as point type

Thanks
 
How exactly do I use the command? ut say something about bypal argument.

No COde p;ease
just command help
 
use the api call i defined in the mouse rollover FAQ:


The following should be placed in a module:

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public MousePoint As POINTAPI

Public Type POINTAPI
x As Long
y As Long
End Type


place the following in your form:

Private Sub Timer1_Timer()
Dim xCord as Single
Dim yCord as Single

GetCursorPosition MousePoint
xCord = Mousepoint.x - (Form1.Left / Screen.TwipsPerPixelX + 4) 'add 4 pixels for the border
yCord = MousePoint.y - (Form1.Top / ScreenTwipsPerPixelY + 4) ' add 4 pixels for the border
End Sub

Thats almost the entire code :) hehe....
Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
OOPS!
I'm sorry.. I missed the part where you said no code.
Don't look at it:

You need to declare a simple TYPE called POINTAPI

In this type you will have two variables: x and y

then you access the type by creating a variable of the type POINTAPI. you populate the varable by alling the GetCursorPos function. Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
The easy way is to put a transparent label in the radius of the object .. then u can use mouseMove =)
/ola
 
Thanks for the help, while I could just draw a geometry around the object I'm doing this manly as an exersice, just to test my abilities and improve them whil I await the public release o my mp3 player.
 
I'm real sorry people, but the mouse returns an x (&Y) value in pixels relative to the top left corner of the screen, while the form returns x & y values relative to the forms top left corner is there any way to ccorrect this?
 
Bu getting us to tell you what to do isn't much of a test of your abilities, is it?
 
Check the ScreenToClient API. MSDN should enlighten u on its use. It should solve your screen/form X and Y problem.
 
thats a very simply math calculation from there.

do this:

Private Sub Timer1_Timer()
Dim xCord as Single
Dim yCord as Single

GetCursorPosition MousePoint
xCord = Mousepoint.x - (Me.Left / Screen.TwipsPerPixelX + 4)
yCord = MousePoint.y - (Me.Top / ScreenTwipsPerPixelY + 4)
End Sub

This will give you mouse position relative to your form.
Best Regards and many Thanks!
Michael G. Bronner X-)

"They who drink beer will think beer." Washington Irving
 
Stongm, I'm sorry that I don't automaticaly now every command in the whoe world, while u may I need some one to help me so I can go even farther.

Thanks to all that helped
 
MrMoocow,

Mine was an innocent and genuine question, in response to your query concerning the different coordinates. The solution, as given by Michael Bronner, demonstrates that the answer is a simple bit of math, and not a set of VB methods that you might be unfamiliar with.

Even without example code, an answer to that question along the lines of "Well, you've got the coordinates relative to the form, coordinates relative to the screen, and you can find out the coordinates of the form relative to the screen, so you just need to do some math" would merely lead to testing your ability to subtract some numbers from some other numbers, which I've got to assume is hardly a test at all. Whereas the real test of programming ability would have been to figure out that insight out for yourself. Hence my question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top