If not, try PInvoke to call Win32 API SendMessage.
Best regards,
yhhuang
VS.NET, Visual C++
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
Could you please provide me an example or link me to one? I am a
relatively newbie, so this is new to me.
Thank you.
//myControl must be a Button, MenuItem or RadioButton or a class that
inherites from one of these
myControl.PerformClick();
If you want to use it on another object that responds to a click then
you can use the following class. This does not pay attention to whether
or not you are clicking the control or alt buttons. It also does not
allow you to specify the location that you are clicking on. This just
sends a click message to the control. It is basic but it should help you
along and give you an idea.
public sealed class MessageSender
{
private const UInt32 WM_LBUTTONDOWN = 0x201;
private const UInt32 WM_LBUTTONUP = 0x202;
[DllImport("user32.dll")]
private static extern int SendMessage( IntPtr handle, UInt32 message,
int wParam,
int lParam);
public static void SendClick(Control receiver)
{
if (receiver != null)
{
SendMessage(receiver.Handle,WM_LBUTTONDOWN,0,0);
SendMessage(receiver.Handle,WM_LBUTTONUP,0,0);
}
}
}
Regards,
Jason Sacks
csharpe...@attbi.com
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thank you.
Jason Sacks <csharpe...@attbi.com> wrote in message news:<#vslQW23BHA.2208@tkmsftngp05>...
"The type or namespace name 'DllImport' could not be found (are you
missing a using directive or an assembly reference?)"
Is there something that I am forgetting?
Thanks in advance.
Jason Sacks <csharpe...@attbi.com> wrote in message news:<#vslQW23BHA.2208@tkmsftngp05>...
using System.Runtime.InteropServices;
--
For mail, please use my surname where indicated:
st...@surname.reno.nv.us (Steve Brecher)
"Steve Brecher" <Steve_...@see.sig.at.end> wrote in message news:<eBuA7L#3BHA.2144@tkmsftngp07>...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
/platform/CommCtls/winui/hooks_7vaw.asp
This topic pretty in depth and it would take quite a while for me to
write how to do this in C#. Basically you create a hook into the windows
messages. You record the mouse messages (location and button). Then you
can play it back with the .
You may want to do a WH_JOURNALRECORD and a WH_JOURNALPLAYBACK. I would
help more but I have a lot of work to do on my own :-P
I tried your solution with the DLLImport and SendMessage API, but I
still have some problems:
- As you said yourself I can only use this solution together with an
object. What I would like to have is a solution that just sends a Mouse
Click event from the location where the mouse is at that moment,
especially when outside the program window.
- I would also like to implement clicking for other buttons, such as the
right or middle mouse button. I found numerous event names for this,
i.e. WM_RBUTTONDOWN, but I couldn't find the hex numbers you were using
for the click events you were giving in your sample code. Where can I
find the other hex values?
Thanks and greetings,
Sascha
Regards,
Jason Sacks
csharpe...@attbi.com
public static void SendClick(Control receiver, Point location)
{
if ( receiver != null )
{
SendMessage(receiver.Handle, WM_LBUTTONDOWN, 0, (location.Y *
0x10000) + location.X);
SendMessage(receiver.Handle, WM_LBUTTONUP, 0, (location.Y *
0x10000) + location.X);
}
}
But there is still a problem:
When I send a mouseclick to a window with mouse coordinates, it is still
only the specified window which gets clicked. If there is a button at
the specified location, it doesn't get clicked but the window underneath
it. To make it click that button you have to find out which object is
currently at the mouse position. I tried to use the windowfrompoint api
command, but I got strange exceptions.
Any solutions or hints?
thanks,
Sascha
private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
[DllImport("user32.dll")]
private static extern void mouse_event(
UInt32 dwFlags, // motion and click options
UInt32 dx, // horizontal position or change
UInt32 dy, // vertical position or change
UInt32 dwData, // wheel movement
IntPtr dwExtraInfo // application-defined information
);
public static void SendClick(Point location)
{
Cursor.Position = location;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr());
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr());
}
Why did none of you guys suggest this solution? Is there any sideeffect
or disadvantage I should know about? But this was the only solution so
far that did exactly what I wanted: Click at any given location and
execute the click event on any object the mouse might be over then,
especially if outside the windows form.
Thanks for your help anyways,