C#在Windows Mobile / WinCE平台发送(按键、点击鼠标等各种windows)消息
2010-02-04 14:26
597 查看
首先创建一个消息实例:
Message Msg = Message.Create(this.button1.Handle, 0x0100, (IntPtr) 0x21, (IntPtr)0);
第一个参数为窗口或控件的句柄;
第二个参数为windows消息ID(请查看 本人另一转帖——消息大全 http://blog.csdn.net/gulingeagle/archive/2010/02/04/5288973.aspx),上例中是 WM_KEYDOWN的16进制位值,表示
按下一个键;
第三个参数为消息 WParam
字段,通常是一个与消息有关的常量值,也可以是窗口或控件的句柄,
上例中是
PageUp键虚拟值的16进制位值,表示模拟按了PageUp键;
第四个参数为消息 LParam
字段,通常是一个指向内存中数据的指针,
上例中没有用到这个参数,因此赋零
;
一个问题是,当确定了消息ID,怎么填写WParam和
LParam参数呢?刚开始我也找了很久,后来找到了一个办法:
在MSDN
官方网站
上
的英文
版
(中文版尚无这部分内容)
:
http://msdn.microsoft.com/en-us/library/default.aspx
在搜索处填写消息ID号(如WM_KEYDOWN)进行搜索,之后在结果中找到:
标题为:“WM_KEYDOWN” 或 “WM_KEYDOWN Notification ()”的链接,里面即可找到WParam和
LParam参数值的说明,如
WM_KEYDOWN Notification链接里包含以下文字(不包含黑色文字):
wParam
Specifies the virtual-key code of the nonsystem key.(甚至连
The Virtual-Key 都列在后面
)
lParam
Specifies the repeat count, scan code, extended-key flag, context code,
previous key-state flag, and transition-state flag, as shown in the
following table.
Specifies
the repeat count for the current message. The value is the number of
times the keystroke is autorepeated as a result of the user holding
down the key. If the keystroke is held long enough, multiple messages
are sent. However, the repeat count is not cumulative.
Specifies the scan code. The value depends on the OEM.
Specifies
whether the key is an extended key, such as the right-hand ALT and CTRL
keys that appear on an enhanced 101- or 102-key keyboard. The value is
1 if it is an extended key; otherwise, it is 0.
Reserved; do not use.
Specifies the context code. The value is always 0 for a
WM_KEYDOWN
message.
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
Specifies the transition state. The value is always zero for a
WM_KEYDOWN
message.
然后通过MessageWindow发送模拟消息:
MessageWindow.SendMessage(ref Msg);
注意若要使用以上类,必须在项目中添加对 Microsoft.WindowsCE.Forms
命名空间的引用。
Message Msg = Message.Create(this.button1.Handle, 0x0100, (IntPtr) 0x21, (IntPtr)0);
第一个参数为窗口或控件的句柄;
第二个参数为windows消息ID(请查看 本人另一转帖——消息大全 http://blog.csdn.net/gulingeagle/archive/2010/02/04/5288973.aspx),上例中是 WM_KEYDOWN的16进制位值,表示
按下一个键;
第三个参数为消息 WParam
字段,通常是一个与消息有关的常量值,也可以是窗口或控件的句柄,
上例中是
PageUp键虚拟值的16进制位值,表示模拟按了PageUp键;
第四个参数为消息 LParam
字段,通常是一个指向内存中数据的指针,
上例中没有用到这个参数,因此赋零
;
一个问题是,当确定了消息ID,怎么填写WParam和
LParam参数呢?刚开始我也找了很久,后来找到了一个办法:
在MSDN
官方网站
上
的英文
版
(中文版尚无这部分内容)
:
http://msdn.microsoft.com/en-us/library/default.aspx
在搜索处填写消息ID号(如WM_KEYDOWN)进行搜索,之后在结果中找到:
标题为:“WM_KEYDOWN” 或 “WM_KEYDOWN Notification ()”的链接,里面即可找到WParam和
LParam参数值的说明,如
WM_KEYDOWN Notification链接里包含以下文字(不包含黑色文字):
wParam
Specifies the virtual-key code of the nonsystem key.(甚至连
The Virtual-Key 都列在后面
)
lParam
Specifies the repeat count, scan code, extended-key flag, context code,
previous key-state flag, and transition-state flag, as shown in the
following table.
0-15
Specifies
the repeat count for the current message. The value is the number of
times the keystroke is autorepeated as a result of the user holding
down the key. If the keystroke is held long enough, multiple messages
are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies
whether the key is an extended key, such as the right-hand ALT and CTRL
keys that appear on an enhanced 101- or 102-key keyboard. The value is
1 if it is an extended key; otherwise, it is 0.
25-28
Reserved; do not use.
29
Specifies the context code. The value is always 0 for a
WM_KEYDOWN
message.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31
Specifies the transition state. The value is always zero for a
WM_KEYDOWN
message.
然后通过MessageWindow发送模拟消息:
MessageWindow.SendMessage(ref Msg);
注意若要使用以上类,必须在项目中添加对 Microsoft.WindowsCE.Forms
命名空间的引用。
相关文章推荐
- 关于C# windows发送消息
- 使用C#编程将websphere MQ 5.3 windows客户端消息发送到linux服务器端
- C# 重写WndProc 拦截 发送 系统消息 + windows消息常量值(2)
- C#中的SendKeys发送按键消息
- C# 重写WndProc 拦截 发送 系统消息 + windows消息常量值(2)
- Python实现windows下模拟按键和鼠标点击的方法
- 关于C# windows发送消息
- C# TCP服务端 可以接收其他语言或平台发送的TCP消息
- 在C#程序中模拟发送键盘按键消息
- 在windows平台使用Apache James搭建邮件服务器以及使用C#向外网发送邮件
- Python实现windows下模拟按键和鼠标点击的方法
- Python实现windows下模拟按键和鼠标点击的方法
- c# wince/mobile 下支持触屏点击的 textbox 点击事件
- cocos2d-x 处理windows按键消息 鼠标移动消息
- C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- 在C#程序中模拟发送键盘按键消息
- C# 发送、接收和处理自定义的WINDOWS消息
- 发送消息 模拟鼠标点击 单击按钮和复选
- 用C#调用Windows API向指定窗口发送按键消息
- C# 重写WndProc 拦截 发送 系统消息 + windows消息常量值(1)