手柄+ mouse_event [英] Handle+mouse_event

查看:64
本文介绍了手柄+ mouse_event的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何将控件的句柄传递给win32 api mouse_event。所以

它只会在该应用程序上创建click事件,即使

是它前面的任何其他窗口。我不知道要设置焦点。我只想直接在那个窗口发生点击事件




问候

Abhishek

解决方案

Abhishek,


控件上的Handle属性将返回你的句柄

look for。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


"阿布舍克巴克" < sh *** @activelement.comwrote in message

news:eY ************** @ TK2MSFTNGP02.phx.gbl ...





如何将控件的句柄传递给win32 api mouse_event。所以

它只会在该应用程序上创建click事件,即使

是它前面的任何其他窗口。我不知道要设置焦点。我只想直接在那个窗口发生点击事件




问候

Abhishek


您好Abhishek,


您是否尝试将鼠标输入发送到其他进程?您必须通过枚举窗口中的窗口来获取窗口句柄,然后查看文本并键入以查找特定控件。有一个你可以使用的Win32 API函数,比如

EnumWindows和EnumChildWindows。


要在你自己的应用程序中模拟一个点击,从中获取控件的句柄Control.Handle属性。


在任何一种情况下,在您检索句柄后,将其与WM_LBUTTONUP一起传递给外部SendMessage Win32 API函数。


(请注意,框架中的一些控件有一个PerformClick方法,如果你可以使用

,这将减少对互操作的需求。)


- -

Dave Sexton


" Abhishek" < sh *** @ activelement.com在消息新闻中写道:eY ************** @ TK2MSFTNGP02.phx.gbl ...





如何将控件的句柄传递给win32 api mouse_event。这样它就会在该应用程序上创建click事件

,即使前面有任何其他窗口也是如此。我不知道要设置焦点。我只是希望点击事件直接发生在

窗口。


问候

Abhishek


您好Abhiishek,


尝试发送WM_LBUTTONDOWN然后WM_LBUTTONUP并使用Control.Handle指定控件的句柄属性。我怀疑这个

是否可以跨进程工作,但您可以尝试使用EnumWindows或

EnumChildWindows Win32 API函数获取另一个应用程序中窗口的句柄。


私有虚拟SimulateClick(控制ctrl)

{

if(ctrl == null)

throw new ArgumentNullException(" ctrl");


int x = 8,y = 8;

int point = x +(y<< 16) ;


SendMessage(ctrl.Handle,WM_LBUTTONDOWN,0,point);

SendMessage(ctrl.Handle,WM_LBUTTONUP,0,point));

}


私有常量WM_LBUTTONUP = 0x0202,WM_LBUTTONDOWN = 0x0201;


[DllImport(" user32.dll" ;)]

public static extern int SendMessage(IntPtr hwnd,uint msg,int wparam,int lparam);

-

Dave Sexton


" Abhishek" < sh *** @ activelement.com在消息新闻中写道:eY ************** @ TK2MSFTNGP02.phx.gbl ...





如何将控件的句柄传递给win32 api mouse_event。这样它就会在该应用程序上创建click事件

,即使前面有任何其他窗口也是如此。我不知道要设置焦点。我只是希望点击事件直接发生在

窗口。


问候

Abhishek


Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if there
is any other window in front of it. I dont what to set focus. I just want
the click event to happen in that window directly.

Regards
Abhishek

解决方案

Abhishek,

The Handle property on the control will return the handle that you are
looking for.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if there
is any other window in front of it. I dont what to set focus. I just want
the click event to happen in that window directly.

Regards
Abhishek



Hi Abhishek,

Are you trying to send mouse input to a different process? You''ll have to obtain the window handle by enumerating the windows in
the process and view the text and type to find the specific control. There a Win32 API functions that you can use such as
EnumWindows and EnumChildWindows.

To simulate a click in your own application obtain the handle of the control from the Control.Handle property.

In either case after you retrieve the handle pass it to the external SendMessage Win32 API function along with WM_LBUTTONUP.

(Note that a few controls in the framework have a PerformClick method, which will alleviate the need for interop if you can use
them.)

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application
only even if there is any other window in front of it. I dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek



Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control''s handle using the Control.Handle property. I doubt this
will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application
only even if there is any other window in front of it. I dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek



这篇关于手柄+ mouse_event的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆