简体   繁体   中英

Repeat windows messages in Winforms

I want repeat sent windows messages to my winforms application. Now, I have class implementing "IMessageFilter" which saves the selected messages (WM _KEYDOWN, WM _LBUTTONDOWN, etc...) to the list.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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