Click to See Complete Forum and Search --> : CLI/WinForms Project: Where's the Message Pump?


wildfire99
July 19th, 2007, 06:41 PM
I've started a new project in Visual Studio as a C++/CLI/WinForms app to try out this new UI code. The lack of proper documentation is aggravating, but oh well...

I'm coming from a raw Win32 background, so I'm used to dealing with windows messages directly in a WndProc() of some sort. I have DLL's that send my app custom-defined messages that notify me of events going on, say something like WM_DOSOMETHINGLOL defined as WM_USER + 100.

Where in the whole WinForms/CLI thing can I check or declare a handler for when my app receives the 'WM_DOSOMETHINGLOL' message? I can't find anything in any documentation anywhere for setting up message handlers for arbitrary message ID's.

Is there a good book I can buy/read for someone coming from old skool Win32 into .NET/WinForms/CLI? I sort of like it thus far but it's a bit convoluted since everything is sort of hidden, and most books on this only show you how to do it in MFC which is silly at this point in time.

wildfire99
July 19th, 2007, 09:05 PM
I think I figured out the message thing, at least immediately... I need to get thinking in terms of classes. From the microsoft site (and edited slightly to actually compile--thanks MS!), this goes in the "Form1" class (which is the main window form):


virtual void WndProc( Message% m ) override
{
int appActive;

// Listen for operating system messages.
switch ( m.Msg )
{
case WM_ACTIVATEAPP:

// The WParam value identifies what is occurring.
appActive = (int) m.WParam != 0;

// Invalidate to get new text painted.
this->Invalidate();
break;
}

Form::WndProc( m );
}


Is there a cleaner way to do this other than overriding the whole loop and doing old-skool message switching?

Also, if there is a good book on this stuff, I still would love to hear about it. None of the .net/c#/visual c++ books I've looked at have anything about message loops outside of MFC, let alone real-world app examples like this.

Krishnaa
July 20th, 2007, 03:16 AM
The message handlers can be added from the form's properties page, see the attached image and red markings.

wildfire99
July 20th, 2007, 04:28 AM
The message handlers can be added from the form's properties page, see the attached image and red markings.
Thanks... my hitch was that the message I wanted to handle was a custom-defined one, not a standard WM_LBUTTONDOWN or such. But I think I did get it, you just have to override the entire message loop, and pass whatever you don't process back to the form's regular wndproc handler. It's always nice to avoid that extra function call and check for every msg though.