views:

85

answers:

1

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.

+1  A: 

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.

1800 INFORMATION
MessageFilter returns always "false", so no messages are filtered in fact. But I try use PostMessage instead of SendMessage, thanks.
TcKs
The PostMessage was the right tip. Now, it looks good. Thanks!
TcKs