views:

229

answers:

2

I posted this answer (more of an idea really) but haven't been able to find out for sure which message triggers a WinForms Form.Load event. From Spy++ and some reading I suggested it might be WM_SHOWWINDOW, but I'd like to be sure.

Also, other than Spy++ is there a better way to see exactly which windows message triggered a .Net event? Even after switching off some event types in Spy++ the log window fills up very quickly.

Thanks.

+2  A: 

There isn't a specific windows message which corresponds to the Load event on the Form class. The event is simply fired the before first time the window is made visible after the creation of the window handle of the Form.

It's used for initialization which requires the window handle of the Form to be created but before the Form is shown for the first time.

casperOne
So is it WM_SHOWWINDOW but only the 1st time that that message is processed for a particular form?
ng5000
@ng5000: I wouldn't say that. The documentation indicates that it is fired before a form is fired for the first time. ANYTHING that happens before it can trigger it, so it could be the message that creates the window as well. There is no way to know for sure, since that's an implementation detail
casperOne
A: 

I'm guessing here, but it might be instructive to configure your dev environment to use Microsoft's source server, then have a look through the System.Windows.Forms code. See Shawn Burke's blog entry Configuring Visual Studio to Debug .NET Framework Source Code.

Dan Blanchard