简体   繁体   English

在Winforms中重复Windows消息

[英]Repeat windows messages in Winforms

I want repeat sent windows messages to my winforms application. 我想重复发送Windows消息到我的Winforms应用程序。 Now, I have class implementing "IMessageFilter" which saves the selected messages (WM _KEYDOWN, WM _LBUTTONDOWN, etc...) to the list. 现在,我有了实现“ IMessageFilter”的类,该类将选定的消息(WM _KEYDOWN,WM _LBUTTONDOWN等)保存到列表中。

On key "Pause/Break" I copy the list of messages, clear original list, and resend the messages. 在“暂停/中断”键上,我复制消息列表,清除原始列表,然后重新发送消息。

In my test project is only one form with one menuitem, one tab and one richtextbox. 在我的测试项目中,只有一种形式带有一个菜单项,一个选项卡和一个RichTextBox。 The hWnd of controls are same during saving and repeating messages. 在保存和重复消息期间,控件的全部相同。

All works fine, but the sending messages has not efect :/. 一切正常,但是发送消息无效:/。

Sample code: 样例代码:

[System.Runtime.InteropServices.DllImport( "user32" )]
public static extern int SendMessage( IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam );

// ... in some method ...
SendMessage( msg.HWnd, msg.Msg, msg.WParam, msg.LParam );

It looks too easy, but don't know where can be problem. 看起来太简单了,但是不知道哪里可能出问题。

Do you still have the message filter applied? 您还应用了消息过滤器吗? Would that not interfere with sending the messages? 这样不会干扰发送消息吗? Other possibility could be that the message in question should not be sent, but posted. 其他可能性可能是所讨论的消息不应该发送,而应该发布。 Or, you may have to send the message from the correct thread for the target window. 或者,您可能必须从目标窗口的正确线程发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM