Simulate hold button down? Can anybody help me?

  • Thread starter Thread starter peetersb
  • Start date Start date
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
 
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.
 
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.
 
Back
Top