Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 27th, 2006, 11:54 AM   #1
Mikael
Newbie
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0 Mikael is on a distinguished road
Send a message via MSN to Mikael
[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
Mikael is offline   Reply With Quote
Old Mar 27th, 2006, 9:59 PM   #2
brownhead
Programmer
 
Join Date: Mar 2006
Location: California
Posts: 37
Rep Power: 0 brownhead is on a distinguished road
Send a message via AIM to brownhead Send a message via MSN to brownhead
^^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
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
brownhead is offline   Reply With Quote
Old Mar 28th, 2006, 12:39 AM   #3
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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".
Booooze is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:36 AM.

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