PC Review


Reply
Thread Tools Rate Thread

Grabing the FormLoad Message from the Message Queue

 
 
Saurabhdotnet
Guest
Posts: n/a
 
      1st Sep 2004
I have written a Custom Message Filter. And want to trace the Form_Load or
similar Message and write this to console. Can Anybody help me here.

Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As
Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage

If m.Msg <> ??? Then Console.WriteLine("Form Loaded")

End Sub

Its urgent..
- Saurabh


 
Reply With Quote
 
 
 
 
Sijin Joseph
Guest
Posts: n/a
 
      1st Sep 2004
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/de...es/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


Saurabhdotnet wrote:
> I have written a Custom Message Filter. And want to trace the Form_Load or
> similar Message and write this to console. Can Anybody help me here.
>
> Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As
> Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
>
> If m.Msg <> ??? Then Console.WriteLine("Form Loaded")
>
> End Sub
>
> Its urgent..
> - Saurabh
>
>

 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      2nd Sep 2004
Hi Saurabh,

You may implement IMessageFilter interface to get this done. For more
information and sample, please refer to the below 2 articles:
"Using IMessageFilter to create a generic filter for operating system
events"
http://www.codeproject.com/csharp/IM...terArticle.asp

"Trapping windows messages"
http://www.codeproject.com/dotnet/de...umemonitor.asp

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
=?Utf-8?B?U2F1cmFiaF9NVlA=?=
Guest
Posts: n/a
 
      2nd Sep 2004
Hi Jef,

I feel you didn't got my question correct. How could I trap the following
Messages using the my custom Message Filter.

WM_NULL 0x0000
WM_CREATE 0x0001
WM_DESTROY 0x0002
WM_MOVE 0x0003
WM_SIZE 0x0005
WM_ACTIVATE 0x0006
WM_ENABLE 0x000A
WM_SHOWWINDOW 0x0018
WM_MOUSEACTIVATE 0x0021
WM_ACTIVATEAPP 0x001C

My main motive is to trap a window message which comes only once when a Form
gets loaded. Few of the events are listed below.

I tried trapping the above messages, but I didn't received any of them.
Please help me, its urgent.

- Saurabh

""Jeffrey Tan[MSFT]"" wrote:

> Hi Saurabh,
>
> You may implement IMessageFilter interface to get this done. For more
> information and sample, please refer to the below 2 articles:
> "Using IMessageFilter to create a generic filter for operating system
> events"
> http://www.codeproject.com/csharp/IM...terArticle.asp
>
> "Trapping windows messages"
> http://www.codeproject.com/dotnet/de...umemonitor.asp
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>

 
Reply With Quote
 
Sijin Joseph
Guest
Posts: n/a
 
      2nd Sep 2004
Hi Jeffery,

Check out my reply, when a form is loaded only 2 messages get passed to
IMessageFilter, nothing else, as to how Form_Load is getting called, i
have detailed that in my reply.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph



Jeffrey Tan[MSFT] wrote:
> Hi Saurabh,
>
> You may implement IMessageFilter interface to get this done. For more
> information and sample, please refer to the below 2 articles:
> "Using IMessageFilter to create a generic filter for operating system
> events"
> http://www.codeproject.com/csharp/IM...terArticle.asp
>
> "Trapping windows messages"
> http://www.codeproject.com/dotnet/de...umemonitor.asp
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      3rd Sep 2004
Hi Saurabh,

Thanks for your feedback.

Oh, yes, I really reproduced out your problem. I will spend a little more
time on this issue. I will reply to you ASAP.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      6th Sep 2004
Hi Saurabh,

Sorry for letting you wait for so long time.

Actually, IMessageFilter is pre process before the normal translate /
dispatch cycle of the message pump, it will only see posted messages. While
the messages you listed are all pass to the Windows procedure through
SendMessage method, which will not be placed in the message pump. So the
IMessageFilter can not intercept them.

You may try to intercept these messages through overriding Form's WndProc
method, like this:
protected override void WndProc(ref Message m)
{
Console.WriteLine(m.Msg.ToString());
base.WndProc (ref m);
}

=================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      9th Sep 2004
Hi Saurabh,

Does my reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formload upon database startup reservedbcreater Microsoft Access 2 3rd May 2005 10:22 PM
great free tool for grabing screenshots! Kenny S Windows XP Help 0 15th Jun 2004 11:23 PM
great free tool for grabing screenshots! Kenny S Windows XP General 0 15th Jun 2004 11:23 PM
Blank text boxes on FormLoad JimPNicholls Microsoft Access Getting Started 1 6th Feb 2004 01:09 PM
FormOpen vs FormLoad Amit Microsoft Access Form Coding 2 12th Dec 2003 06:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:31 PM.