Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   [Source] Getting X And Y Coordinates [VB6.0] (http://www.programmingforums.org/showthread.php?t=9069)

Mikael Mar 27th, 2006 12:54 PM

[Source] Getting X And Y Coordinates [VB6.0]
 
:

        Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
    x As Long
    Y As Long
End Type

Private Sub Timer1_Timer()
      Dim rect As POINTAPI
      Call GetCursorPos(rect)
      Form1.Cls
      x.Caption = "Current X = " & rect.x
      Y.Caption = "Current Y = " & rect.Y
End Sub



Add an Timer called timer1.
Add two labels called x and Y.
Set the timer1.interval to 5
Last but not least Put the code in the form.
Finito u just made x and y coordinates

brownhead Mar 27th, 2006 10:59 PM

^^Yep.. that does indeed work, but I usually prefer using a function and a with statement to get the job done.. because whenever I use this API.. I have to use it alot :\.. anyways, My favorite way to do it is below.. but his words too :D
:

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
    x As Long
    Y As Long
End Type
Private Function GetCursorPosEx() as Pointapi
GetCursorPos GetCursorPosEx
End Function
Private Sub Timer1_Timer()
With GetCursorPosEx
    X = "Current X = " & .x
    Y = "Current Y = " & .y
End with
end sub


Booooze Mar 28th, 2006 1:39 AM

This code is quite common. No offense though. Might help some new people. Just as a note, I first saw this code in the API guide. If your really into VB, then you should have it. Just google "API Guide".


All times are GMT -5. The time now is 9:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC