CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: api

  1. #1
    Join Date
    Aug 2001
    Posts
    17

    api

    Ok i have been working on this a while and still cant get this to work:

    I have it set so that when i hit the button it gets the x and y coords for me and places them into the feilds for me:

    This part i have working
    But I need to be able to click the button and then move the mouse into windows and be able to target any where I want and have it put the x and y coords into the feilds for me, as it is right now when I click the button it automaticly puts the coords into the feild but only from the point where I click it on the button itself

    (create a form and have one button in it and two text boxes and using the code below.)

    PLEASE HELP ME!!!!!!!!!!!!


    here is the code:


    private Sub record_Click()
    ' Create instance of POINTAPI
    Dim CursorLocal as POINTAPI

    ' Locate the cursor using the API
    GetCursorPos CursorLocal

    ' Displays the X Y coordinates for the user.
    Text1 = CursorLocal.x
    Text2 = CursorLocal.x
    End Sub




    Here is the module:

    option Explicit

    Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long

    ' point type returned by GetCursorPos API
    public Type POINTAPI
    x as Long
    y as Long
    End Type



    HEEEEEEEEEEEELP

    Thank you in advance.


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: api

    You need to capture the mouse so other windows don't intercept your click... try this:


    option Explicit
    private Type POINTAPI
    X as Long
    Y as Long
    End Type
    private Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Long
    private Declare Function ReleaseCapture Lib "user32" () as Long
    private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long
    Dim Pt as POINTAPI

    private Sub Command1_Click()
    'caption mouse so other windows won't get clicks
    SetCapture (me.hwnd)
    End Sub

    private Sub Form_MouseDown(Button as Integer, Shift as Integer, X as Single, Y as Single)
    'get the current cursor position
    GetCursorPos Pt
    me.CurrentX = 0
    me.CurrentY = 0
    'Clear the screen
    me.Cls
    me.print "Cursor position:"
    'print the mouse coördinates to the form
    me.print "X:" + Str$(Pt.X) + " Y:" + Str$(Pt.Y)

    'Release mouse to other windows
    ReleaseCapture
    End Sub




    After you click the button you can click anywhere and get the coords... you must click it again for the next time because I'm releasing it after each click...


  3. #3
    Join Date
    Aug 2001
    Posts
    9

    Re: api

    Hi,u can put your codes into form_Mousemove:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim CursorLocal As POINTAPI

    ' Locate the cursor using the API
    GetCursorPos CursorLocal
    ' Displays the X Y coordinates for the user.
    Text1 = CursorLocal.X
    Text2 = CursorLocal.Y
    End Sub
    Tsinghua


  4. #4
    Join Date
    Aug 2001
    Posts
    17

    Re: api

    WORKS GREAT!!!!!!
    i had to change little but got it to work


  5. #5

    Re: api


    Text2 = CursorLocal.x '<-- Text2 = CursorLocal.Y




    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured