Results 1 to 10 of 10

Thread: x,y coords recording

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    x,y coords recording

    I want to know if there is a superquick way to map x,y of the mouse to file and then later reading coordinates into memory (for speed) by command and then read by program to animate movements of objects?
    I've tryed using arrays and the split function but this eats up a lot of memory and the coords being read into the array on recording slow down as the size of the array grows.
    Also, it seams to me that there must be a function to read x,y coords as one point.
    Any help, input, or links for this subject?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Getcursorpos api returns the cursor position as an pointapi udt. You can use put# statement to write it to an open file, it will be stored as 8 bytes, so if you have an array of them it will be stored as 8*array length, you don't need to parse anything. Don't reallocate the array but each 100'd move, then allocate 100 more elements.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I believe kedaman's example of storing the data to the drive looks like the code below. The timing has a resolution of about 50ms, which you could reduce, or take out altogether.

    Code:
    Option Explicit
    
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private lastTick As Long
    Private myPoint As POINTAPI
    Private Type POINTAPI
            X As Long
            Y As Long
    End Type
    
    Private Sub Form_Load()
        Open "c:\logfile.txt" For Random As #1 Len = Len(myPoint)
        If (MsgBox("Do you want me to record mouse data, " & vbCrLf & "as opposed to playing back the recorded data ?", vbYesNo) = vbYes) Then
            Do
                DoEvents
                If ((GetTickCount - lastTick) > 50) Then
                    lastTick = GetTickCount
                    GetCursorPos myPoint
                    Put #1, , myPoint
                End If
            Loop
        Else
            Do Until EOF(1)
                Get #1, , myPoint
                With myPoint
                    Debug.Print .X & ":" & .Y
                End With
            Loop
        End If
        Close #1
    End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Thanks for the help guys. I was able to get as far but without using the getCursorPosition. I'm gona plug it in and see if the performance is any quicker. I'm doing a boatload of processing once I get each position and because of that I'm still running slower than the "live" drawing. Also to draw lines I'm gona take another performance hit getting currentx and y to keep the lines beginning and ending correctly so I'll keep my fingers crossed.

    Thanks Again
    JoeyO

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    What kind of processing are you doing as you get the cursor position? What kind of lines are you drawing and how? If you suspect there's something that could be enhanced, i might know what to do.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Still need a little more help

    This brought me up to speed. Thanks! But now my problem concerns using forms on MDI - I know "don't use MDI" but the project I'm building has evolved over two years and has built heavily into MDI before I knew how to avoid it. I'm within a couple of months of finishing and trying to work around it.

    Question: How do I use PointAPI to either get the points from a specified container such as mdi.activeform (instead of the MDI) or to locate points on a different container that correspond to the original PointAPI points from the MDI.

    In other words: PointAPI "puts" the points from the MDI form even though I'm drawing on the activeForm, when I "get" the points and try to draw them to the activeform they are offset by the distance the form is offset by "alligned" pictureboxes on top and side because MDI's X&Y is different from forms X&Y.

    Does Windows use the pointAPI to set the form's X&Y relative to the screen and scale? If not there must be a way to specify the container in PointAPI somewhere. If anyone knows this please let me know.

    Thanks

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    MDI isn't a bad interface, many professional applications like VB6 and Visual C++ use MDI, and it certainly makes things easier when the toolwindows aren't overlapping with either theirselves or the child forms.

    Your qwestions were hard to understand since you seemed to misunderstand the concept of Pointapi. Pointapi is an UDT, a structured datatype, not a method, if that confuses you, think about it as groups of variables.

    The problem you are describing thought sounds like you don't know how to convert between client and screen coordinates, there's an api called Clienttoscreen which takes the in client coordinate and converts it to screen coordinate, hwnd is the client window's handle, in your case mdi.activeform.hwnd. Alternatively you can use clienttoscreen to convert screen to client, by negating the dimensions on the coordinate.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    OK your confusion is understood as I was using "PointAPI" interchangebly with values returned from "getCursorPos". New problem though. When using "Kill" statement to erase file it's content is getting cached and re-appearing when I recreate it with "Open <filename>" statement. When I debug it's worse, the file populates with some of it's old content and picks up about 2K of garbage one time of which it brought back a portion of a web page in real text.
    Any ideas on how to erase the file content and save it from coruption without having to overwrite with empty spaces, 0's, or 1's? Or maybe even a better way to kill the file?

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    files are hard to kill

    I don't know much about how files are stored and how the fat works, but i've heard you have to overwrite it several times before it is totally unretrievable, kill would just remove the entrypoint of the file, while overwriting the previous contents with nulls would do better.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This used to be the case, but I dont know if it still is.
    Anyway, under DOS, to delete a file, the OS would simply delete the first letter of the name of the file.

    Then the FAT looks for files with full names, and would skip those that dont.

    Anyway you shouldnt have those problems.... try the following code :

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Open "c:\aaa.txt" For Output As #1
            Dim i As Long
            Randomize
            For i = 0 To 10000
                Print #1, Rnd & Rnd & Rnd
            Next i
        Close #1
        
        Kill "c:\aaa.txt"
        
        Open "c:\aaa.txt" For Input As #1
            MsgBox Input(LOF(1), 1)
        Close #1
        
    End Sub
    It should give a file not found error..
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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