Simulate hold button down? Can anybody help me?


P

peetersb

Hello,

I want to holddown a button. I use the win32 API like this:

private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_MOUSEACTIVATE = 0x21;
private const int MK_LBUTTON = 0x0001;

[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);

I tryed post en sendmessage:

bool t = PostMessage(this.buttonHandle, WM_LBUTTONDOWN,
System.IntPtr.Zero, System.IntPtr.Zero);

The method returns true, but nothing happend. I don't see the button
is down?
I also tryed it to move the mouse point first to the button, then send
the WM_LBUTTONDOWN but also no result.
Anybody an idee?

Greets
 
Ad

Advertisements

K

kndg

Hello,

I want to holddown a button. I use the win32 API like this:

private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_MOUSEACTIVATE = 0x21;
private const int MK_LBUTTON = 0x0001;

[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);

I tryed post en sendmessage:

bool t = PostMessage(this.buttonHandle, WM_LBUTTONDOWN,
System.IntPtr.Zero, System.IntPtr.Zero);

The method returns true, but nothing happend. I don't see the button
is down?
I also tryed it to move the mouse point first to the button, then send
the WM_LBUTTONDOWN but also no result.
Anybody an idee?

Greets

Hi,

Actually, I'm curious
1. why would you want to do that?
2. why do you go that route (the trouble using Win32 API)? It does work
(as the method returns true) but you have update the button yourself (by
sending the paint message?).

Anyway, my idea is this,

Derived a class from Button and add a method that call the base class
OnMouseDown().
For example,

public class MyFancyButton : Button
{
public void PerformMouseDown()
{
OnMouseDown(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
}

public void PerformMouseUp()
{
...
}
}

You can modify the method to take the mouse co-ordinate or any other
parameters in MouseEventArgs().

Regards.
 
Ad

Advertisements

P

peetersb

From my application I want to click a button on an other windows
application(not mine).


I want to holddown a button. I use the win32 API like this:
private const int WM_LBUTTONDOWN = 0x0201;
         private const int WM_MOUSEACTIVATE = 0x21;
         private const int MK_LBUTTON = 0x0001;
         [DllImport("user32.dll", SetLastError = true)]
         public static extern bool PostMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg, IntPtr wParam, IntPtr lParam);
I tryed post en sendmessage:
bool t = PostMessage(this.buttonHandle, WM_LBUTTONDOWN,
System.IntPtr.Zero, System.IntPtr.Zero);
The method returns true, but nothing happend. I don't see the button
is down?
I also tryed it to move the mouse point first to the button, then send
the WM_LBUTTONDOWN but also no result.
Anybody an idee?

Hi,

Actually, I'm curious
1. why would you want to do that?
2. why do you go that route (the trouble using Win32 API)? It does work
(as the method returns true) but you have update the button yourself (by
sending the paint message?).

Anyway, my idea is this,

Derived a class from Button and add a method that call the base class
OnMouseDown().
For example,

public class MyFancyButton : Button
{
   public void PerformMouseDown()
   {
     OnMouseDown(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
   }

   public void PerformMouseUp()
   {
     ...
   }

}

You can modify the method to take the mouse co-ordinate or any other
parameters in MouseEventArgs().

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top