Results 1 to 3 of 3

Thread: Mouse Control, Coordinates and Getting Screen Resolution

  1. #1

    Thread Starter
    Junior Member SysAdmin2's Avatar
    Join Date
    Mar 2000
    Location
    Plainfield, IL, USA
    Posts
    26

    Post

    Here is the lowdown. I have a form that has a picture on it. I want the user to click on the picture and hold the mouse button down. Then..... the user will drag the mouse to a position anywhere in Windows (any position). Then the user will let go of the mouse button. Once they let go of the mouse button, I want to grab the mouse coordinates. I want to capture these coordinates, so I can automate the mouse movements and clicks so that the mouse will move and click on the objects on the desktop that the user selected. Example: User clicks on picture in my program. They drag the cursor over to an icon and let go of the mouse button. I capture the mouse coordinates. The user runs the program and i automatically go to the icon the user selected and double click. Understand?

    Also... is there a way to get the current screen resolution through code? 640 * 480? 800 * 600? I need to get that as well.

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    I don't think I quite understand your picture clickin' program, but here's the screen res:

    Code:
    XRes = Screen.Width / Screen.TwipsPerPixelX
    YRes = Screen.Height / Screen.TwipsPerPixelY
    Msgbox "Screen Resolution: " &  XRes & "x" & YRes, vbInformation

  3. #3
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    First of all the resolution:
    The easiest way to get it is the screen object.
    An example:
    Dim screenres$
    screenres = Screen.Width / Screen.TwipsPerPixelX & " x " & Screen.Height / Screen.TwipsPerPixelY
    'Who the ***** had the idiotic idea to use Twips instead of pixels?!

    Now you have the current screenresolutin in a string variable. Screen.Width / Screen.TwipsPerPixelX is the width of the screen (e.g. 800) and Screen.Height / Screen.TwipsPerPixelY stands for the height (e.g. 600).

    To get the mousecoordinates, you can use GetCursorPos Api. If you want to know, if the mousebutton has been clicked, you can use the GetAsyncKeystate api. Here is an example:

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const VK_LBUTTON = &H1

    Private Type POINTAPI
    x As Long
    y As Long
    End Type

    Private Sub Timer1_Timer()
    Dim mousecor As POINTAPI
    If GetAsyncKeyState(VK_LBUTTON) <> 0 Then
    GetCursorPos mousecor
    End If
    End Sub

    Mousecor.x will have the value of the mouse's x coordinate while mousecor.y will have the y coordinate.

    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

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