May 13th, 2014, 05:54 PM
Message Loop in Windows Forms
First, I hope this is the right forum. I thought that this should go into Managed C++ but someone else just posted a Windows Forms question there and was told that was the wrong place (but the right place wasn't specified). Please move me if necessary.
I'm trying to port a Win32 application over to Windows Forms so that I can have better graphical control over the interface. The program itself is pretty simple; in the main message loop it listens for a WM_CopyData containing a certain char array, and occasionally sends WM_CopyData itself after the user clicks a certain sequence of buttons.
I found a couple of pages discussing how to completely override the Windows Forms WndProc, but I rather like having the framework do all of the control and would prefer to only latch onto it, rather than replace it. So, what would be the best way to have a Win Forms application listen for Windows Messages continuously and execute a function upon receiving them?
Edit: If I do need to override WndProc, what is the syntax? I found the following code:
But when I stick that into my main.cpp file right after int main function, "protected" gets highlighted as a syntax error with the message " IntelliSense: expected a declaration". What am I doing wrong?
protected override void WndProc(ref Message m)
base.WndProc (ref m);
if (m.Msg==0x4a) // WM_COPYDATA
// do your stuff here...
Last edited by Danja91; May 13th, 2014 at 09:18 PM.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.