Hi Saurabh,
I checked to see all messages that were being passed to IMessageFilter,
it seems that when we just create anew form and load it, only two
windows messages get passes to the filter.
One is a custom string message registered by the application, on my
system it had a number 0xC1FE
(
http://msdn.microsoft.com/library/d.../MessagesandMessageQueuesMessages/WM_USER.asp),
, note that messages in the range 0xC000 - 0xFFFF are string messages
for use by apps, i guess this is used by the framework somehow, the
second message was 0x000F which is WM_PAINT.
Now the question arises, how does the Form_Load event get fired. Well a
little investigating with Reflector showed that, It is getting called
from the Application.Run() method, specfically from the
Application.RunMessageLoopInner() method
this is the relevant code
//From Application.RunMessageLoopInner()
if (reason == -1)
{
if (this.messageLoopCount != 1)
{
throw new
InvalidOperationException(SR.GetString("CantNestMessageLoops"));
}
this.applicationContext = context;
this.applicationContext.ThreadExit += new
EventHandler(this.OnAppThreadExit);
if (this.applicationContext.MainForm != null)
{
this.applicationContext.MainForm.Visible = true;
}
}
In the above code when MainForm.Visible is set to true, at that time the
overriden Form.SetVisibleCore() method gets called
//From Form.SetVisibleCore
if (this.calledCreateControl && !this.calledOnLoad)
{
this.calledOnLoad = true;
this.OnLoad(EventArgs.Empty);
if (this.dialogResult != DialogResult.None)
{
value = false;
}
}
So it maintains a flag to check if OnLoad has been called or not, and
the first time the form becomes visible the event gets fired, there is
no windows message involved.
In fact i even tried loading another form from the main form just in
case this processing was special for the main form, but still i got the
same results, only 1 window message (WM_PAINT) was fired for the second
form.
Let me know if you get any other info on this.
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph