0

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?

Ian Hickman
  • 311
  • 1
  • 4
  • 11
  • What interfaces are you using to host it? It may support one of the standard OLE interfaces that will let you do this... – i_am_jorf Sep 16 '09 at 16:11

1 Answers1

0

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.

Community
  • 1
  • 1
Paul Williams
  • 16,585
  • 5
  • 47
  • 82
  • 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 Sep 17 '09 at 09:23
  • Ahh, I see that it's possible to catch all message with WndProc: http://www.codeproject.com/KB/dotnet/devicevolumemonitor.aspx – Ian Hickman Sep 17 '09 at 10:12
  • 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 Sep 23 '09 at 12:56