UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> X/Y mouse coordinates in form control.    
 
   
Carlos1815
post Oct 3 2008, 02:03 PM
Post #1

UtterAccess Enthusiast
Posts: 99
From: Orlando, Fl



Hello! The title of this post sounds convoluted, but please allow me to explain:
I have a form with an Image control on it. The picture in the Image frame depends on whatever the user loads up; I have a command button that gets the file path of a graphic, and that graphic is displayed in the Image control. Then, I have some code that allows the user to click and drag on the graphic and the coordinates of the mouse pointer when the left mouse button is down and the coordinates of the mouse pointer when the left mouse button is released. Those coordinates are displayed on some unbound text boxes. The code for grabbing the x/y coordinates is as follows:
In a Module:
******************************************
Option Compare Database
Option Explicit
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Function GetX() As Long
Dim n As POINTAPI
GetCursorPos n
GetX = n.X
End Function
Public Function GetY() As Long
Dim n As POINTAPI
GetCursorPos n
GetY = n.Y
End Function
******************************************
Then, this in the form's code:
******************************************
Private Sub ImageFrame_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX = GetX()
Me.txtMouseY = GetY()
End Sub
Private Sub ImageFrame_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX2 = GetX()
Me.txtMouseY2 = GetY()
End Sub
******************************************
This actually all works as intended, but there's a small hitch that I need to find a way to fix. The coordinates of the mouse pointer are taken from the position of the mouse pointer in the whole monitor screen, and I only want coordinates of the mouse pointer's position from inside the Image control, taking into account that the upper left corner of the Image control would be 0, 0; not wherever it is located on the monitor screen. This gets exascerbated when, in my particular case, the users have dual monitors, and the X coordinates in particular are grossly inflated to reflect the mouse pointer's position on monitor 2.
Is there a way I can get it so when the mouse pointer is located in the Image control on the form, x/y coordinates are calculated using only the Image controls dimensions, not the dimensions of my entire monitor screen and where that form is located on my screen?
Thanks in advance to anyone who can steer me in the right direction!
Carlos
Go to the top of the page
 
+
Doug Steele
post Oct 3 2008, 02:33 PM
Post #2

UtterAccess VIP
Posts: 18,612
From: St. Catharines, ON (Canada)



I'm obviously missing something. Aren't the X/Y coordinate for the mouse in the control the values of X and Y in the MouseDown and MouseUp parameter list?
Go to the top of the page
 
+
Carlos1815
post Oct 3 2008, 02:54 PM
Post #3

UtterAccess Enthusiast
Posts: 99
From: Orlando, Fl



Yes. The idea is the user will be creating a "hot spot" area, and those coordinates are read by authorware to set the hot spot interaction. My concern is that the coordinates of the mouse pointer when the user clicks and drags the mouse in the Image control, only the dimensions of the Image control (which happen to be 618 by 679 px) are used in the determination of the coordinates of the mouse pointer. But, the x/y coordinates that are calculated are according to the mouse pointer's location on the computer monitor.
o if the form with the image control is positioned in the middle of the screen, the x/y coordinates of the mouse pointer will be padded to reflect the position of the form on the screen. I just want the coordinates of the mouse pointer in the image control, as if the upper left hand corner of the image control is x =0 , y = 0; and the lower right corner of the image control is x = 618, y = 679; so when the mouse pointer is positioned in the image control, only those coordinates of the control I just mentioned are used to determine the position of the mouse in the image control.
What's happening now is since I have dual monitors, with the form with the image control on the second monitor, the x coordinate comes up something like x = 2100 or x = 2200 when I move the mouse pointer to the image control when the form is showing on the second monitor screen. I want to avoid that. So no matter where or on which screen (most of the designers that will be using this app have dual monitors) the form is located, the image control on the form will always be considered: the upper left hand corner is x =0 , y = 0; and the lower right corner of the image control is x = 618, y = 679.
Please say that clears it up, because I can't write all that again... wink.gif
Carlos
Go to the top of the page
 
+
datAdrenaline
post Oct 3 2008, 03:05 PM
Post #4

UtterAccess Editor
Posts: 16,782
From: Northern Virginia, USA



What Doug is saying is that you do not need your API code ... just use the X and Y variables declared in the MouseUp/Down events ... they are X and Y with respect to the top left of the image control being 0 ...


Private Sub ImageFrame_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX = X
Me.txtMouseY = Y
End Sub

Private Sub ImageFrame_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX2 = X
Me.txtMouseY2 = Y
End Sub
Go to the top of the page
 
+
Carlos1815
post Oct 3 2008, 03:19 PM
Post #5

UtterAccess Enthusiast
Posts: 99
From: Orlando, Fl



Ok, wow, that worked pretty well, but there's still and issue:
While the upper left coordinates are indeed 0, 0; the numbers seem to spiral to unbelievable amounts when I move the mouse and click on the image control. So clicking on the upper left hand corner does give me a 0,0 x/y coordinate, going to the middle of the image control, I get something like 5000, 8000 coordinates! I managed to make it more realistic by adding a little math to the code:
*************************************
Private Sub ImageFrame_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX = X / 15
Me.txtMouseY = Y / 15
End Sub
Private Sub ImageFrame_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.txtMouseX2 = X / 15
Me.txtMouseY2 = Y / 15
End Sub
*************************************
But, is that normal? Do I have to resort to mathmatical trickery to get the coordinates to come put logical? Is there something I'm missing or is that a bug in Access? I got rid of the API module, so that's not messing with the code.
Carlos
Go to the top of the page
 
+
datAdrenaline
post Oct 3 2008, 03:28 PM
Post #6

UtterAccess Editor
Posts: 16,782
From: Northern Virginia, USA



Yep ... I beleive the values you are seeing are in "twips" ...
There are 1440 twips in an inch.
Go to the top of the page
 
+
Carlos1815
post Oct 3 2008, 03:48 PM
Post #7

UtterAccess Enthusiast
Posts: 99
From: Orlando, Fl



Ahhhh, that explains a lot. Alrighty then, thank you so much for your help, guys!! You've saved me a heap of time and trouble.
arlos
Go to the top of the page
 
+
datAdrenaline
post Oct 8 2008, 12:13 PM
Post #8

UtterAccess Editor
Posts: 16,782
From: Northern Virginia, USA



You're welcome! ... Good luck with your project!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 27th November 2014 - 06:41 AM