tags:

views:

102

answers:

1

Using VS2003 (.Net 1.1) We have an MFC MDI application that spawns a C# window as a COM client.

We need to catch all user input within the application and we're currently using CWinApp::PreTranslateMessage() to catch the commands headed to the MFC windows but this obviously doesn't catch the messages headed to the C# window.

What is the best way of catching all user input within the C# client?

A: 

Do you control the C# window? If so, C# forms have a WndProc method that you can override and filter the messages there.

If this where a standard WinForms app, you could add a handler to Application.AddMessageFilter to create a message hook inside C#. (See my post here.) I'm not sure this would work given the form is inside an MFC app.

Paul Williams
We do control the C# client.It has a number of different controls in it so do I have to write a WndProc method for each control? Or do all the messages pass through a "global" one somewhere?Also, I'd tried the AddMessageFilter route but sometimes the method was called but often it wasn't. Why is this?
Ian Hickman
Ahh, I see that it's possible to catch all message with WndProc:http://www.codeproject.com/KB/dotnet/devicevolumemonitor.aspx
Ian Hickman
After many attempts I couldn't get this to work. I wanted to capture the messages so that I could redirect the user to a login dialog but I ended up doing this in the MFC code and just disabled the C# window when logged out.
Ian Hickman