Message Loop in Windows Forms
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 9 of 9

Thread: Message Loop in Windows Forms

Threaded View

  1. #1
    Join Date
    May 2010
    .Net 4.0

    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:

    protected override void WndProc(ref Message m)
     base.WndProc (ref m);
     if (m.Msg==0x4a) // WM_COPYDATA
      // do your stuff here...
    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?


    Last edited by Danja91; May 13th, 2014 at 09:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center