How to send mouse movements using SendMessage ()

I am trying to write a simple Windows form, consisting of buttons, one of the buttons sends mouse clicks to active applications, such as notepad. so I click on the button and the buttons will send mouse events to notepad or any application.

It only sends a right click or click,
I wrote this code for the dll definitions:

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg, int wParam,int lParam);

[DllImport("user32.dll")]
public static extern int FindWindow(String lbClassName,     StringlbWindowName);

// for events

private const uint WM_RBUTTONDOWN = 0x0204;
private const uint WM_RBUTTONUP = 0x0205;

// event handler

private void button6_Click(object sender, EventArgs e)
{
    int window = FindWindow(null, "Notepad");
    SendMessage(window, WM_RBUTTONDOWN, 0, 0);
    SendMessage(window, WM_RBUTTONUP, 0, 0);
}

This does not work!

How can I find out that mouse clicks clicked?
And why doesn't it work?

+4
source share
1 answer

First of all, you need to fix your DllImport signatures ...

static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

FindWindow , IntPtr, .

Spy ++ , , , . Spy ++ , .

0

All Articles