Windows Develop Bookmark and Share   
 index > Windows Forms General > ON_REGISTERED_MESSAGE
 

ON_REGISTERED_MESSAGE

I am working on a project where an existing application written VC++ 6.0 needs to communicate with an application being written in VC#.NET. We have attempted to use RegisterWindowMessage, PostMessage, and PeekMessage. We have verified that we are getting common message IDs and that PostMessage is working. PeekMessage, however is not working, and in the VC++ app I have found that using ON_REGISTERED_MESSAGE to create a message handler in my class works.

The question I have not been able to answer is how to do the corresponding function in the C# application (ON_REGISTERED_MESSAGE).

Any help is appreciated.
Terry3653510  Friday, March 30, 2007 4:58 PM

If your C# app is a Windows Form, you can try to override the message loop:

for instance:

Code Snippet

namespace WindowsApplication1 {

public partial class Form1 : Form {

public Form1 () {

InitializeComponent ();

}

protected override void WndProc (ref Message m) {

const int myMessage = 0x12345; // whatever your ID is...

switch (m.Msg) {

case myMessage: {

// ...

} break;

default: {

base.WndProc (ref m);

} break;

}

}

}

}

This should allow you to trap any message that is received by your form.

HTH

--mc

Mario Cossi  Friday, March 30, 2007 5:20 PM

If your C# app is a Windows Form, you can try to override the message loop:

for instance:

Code Snippet

namespace WindowsApplication1 {

public partial class Form1 : Form {

public Form1 () {

InitializeComponent ();

}

protected override void WndProc (ref Message m) {

const int myMessage = 0x12345; // whatever your ID is...

switch (m.Msg) {

case myMessage: {

// ...

} break;

default: {

base.WndProc (ref m);

} break;

}

}

}

}

This should allow you to trap any message that is received by your form.

HTH

--mc

Mario Cossi  Friday, March 30, 2007 5:20 PM
I don't believe there is a simple method of doing that. The less-than-simple method would involve override your form's WndProc method.
James Curran  Friday, March 30, 2007 5:22 PM
Hello,

The WndProc overide did not work. I capture messages that seem to be sent from my application to my application, however we have a C++ app that is using PostMessage with the BROADCAST paramater to broadcast to all top level windows.

When the PostMessage is called, the code never even breaks in the WndProc override. Is there any way I can capture this message?
MikeMugu  Wednesday, April 04, 2007 1:03 AM

You can use google to search for other answers

Custom Search

More Threads

• Linking scrollbars of listboxes
• Sort on programatically added datagridviewcolumn does not work
• List<T> to Binding<T>
• windows forms webbrowser
• hide cleanmgr window
• What is the proper way to directly access controls in another form?
• What's this "operation not valid due to the current state of the object"
• IPersistComponentSettings example for component
• How to change the color of the scroll bar in the Datagridview? VB.Net or VS2005(VB)
• .NET argument