CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Simulate a mouseclick with SendMessage

    Hi Folks,

    I'm trying to simulate a mouse click in some windows, sending this:

    Code:
    SendMessage(hWnd, WM_LBUTTONDOWN, (WPARAM)0, (LPARAM)MAKELPARAM(ptCursor.x, ptCursor.y));
    SendMessage(hWnd, WM_LBUTTONUP, (WPARAM)0, (LPARAM)MAKELPARAM(ptCursor.x, ptCursor.y));
    reason for that is, I don't want the cursor to move. SendInput works of course, but that moves the cursor around.

    Spy++ tells me those notifications do arrive, but nothing happens in the window ?

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Simulate a mouseclick with SendMessage

    It's a tricky business - I'm assuming those windows don't belong to your process? The behavior of your code depends on the OS. For example Vista can block some messages:
    Microsoft Windows Vista and later. Message sending is subject to User Interface Privilege Isolation (UIPI). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.
    Your only bet would be to use SendInput() with the MOUSEEVENTF_LEFTDOWN and second call with MOUSEEVENTF_LEFTUP flag.

    What is your reason to send those messages?

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