Results 1 to 9 of 9

Thread: Mouse click sequel: Rodent's Revenge

  1. #1

    Thread Starter
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    There were like 2 or 3 or a billion posts with the same question: How do you simulate a mouse click?
    The answer was the same: Find the control's hWnd, and SendMessage with wMsg as WM_CLICK or 2 SendMessage's with wMsg as WM_LBUTTONDOWN then WM_LBUTTONUP.

    New question arose: How do you simulate a mouse click, but not clicking the hWnd, but clicking an area of the screen (Click X, Y)?

    ------------------

    - Yonatan

  2. #2
    Guest

    Post

    You may not like this because it includes another hWnd. Use the hWnd of the screen (desktop). I think it's zero, but I'm not sure.

  3. #3

    Thread Starter
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Zero is the hWnd of NOTHING. To get the screen hWnd you have to use the API GetDesktopWindow. Well, what do I DO with the screen's hWnd?

    ------------------

    - Yonatan

  4. #4
    Guest

    Post

    In C/C++, you'd use
    HWND GetDesktopWindow(VOID)
    to return the handle for the desktop. I haven't found it in VB, but this might help you. Maybe you can find an API for it. I've noticed that you use the API's alot.

  5. #5

    Thread Starter
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    No, I didn't ask how to get the screen's hWnd. I know how. I've done it a billion times.
    My question was what do I do with the hWnd? To simulate a mouse click I mean?
    Should I use an AOL such as SendMessageByPoint(hWnd (= GetDesktopWindow) As Long, wMsg (= WM_CLICK) As Long, lParam (= 0&) As Long, wParam As POINTAPI) ?!?!?
    Well, it's worth a try!

    ------------------
    Yonatan
    Teenage Programmer


  6. #6
    Guest

    Post

    You sure were rude when I was just trying to help you out. Now you're giving similar advice:
    Yonatan
    Member posted 12-08-1999 05:55 PM
    --------------------------------------------------------------------------------
    GetDC allocates a Device-Context for the hWnd specified. This hWnd can be either:
    0 (Zero) - Currently active desktop.
    128 - First desktop (the one created when Windows started).
    Any other number - A valid window handle.

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Try this:
    Code:
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Public Sub ClickMouse(X As Long, Y As Long)
        SetCursorPos X, Y
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Sub
    Passing your coordinates will click the left button on the mouse.

    Example: ClickMouse 500, 500

    ------------------

    Serge

    Software Developer
    Serge_Dymkov@vertexinc.com
    Access8484@aol.com
    ICQ#: 51055819


  8. #8
    Guest

    Post


    Ask Aaron Young. He's been able to help me
    with basically every VB question.


  9. #9

    Thread Starter
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    This post is old and I posted it back when I was (so to speak) an idiot... Sorry!

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

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