Hi David,
*
Can you tell me why you want to handle the form right after the form’s load?
Maybe I can help you.
To trap Windows’s message in C#, you should override the Form’s WndProc
method.
*
My sample code was listed below:
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace winformmessage
{
public class Form1 : System.Windows. Forms.Form
{
private const int WM_SHOWWINDOW=0 x18;
static bool firsttime=true;
private System.Componen tModel.Containe r components = null;
public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeCompo nent()
{
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);
}
#endregion
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
}
protected override void WndProc(ref Message m)
{
switch(m.Msg )
{
case WM_SHOWWINDOW:
if(firsttime)
{
MessageBox.Show ("You application run");
}
break;
default:
break;
}
base.WndProc (ref m);
}
}
}
You may use API Text viewer which is shipped with Visual Studio 6.0 to get
the message’s value or reference the following page if you don’t have that
tool available.
http://doc.ddart.net/msdn/header/include/winuser.h.html
Hope this helps.
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.
--------------------
| From: " David N" <dq*****@netiq. com>
| References: <#4************ **@TK2MSFTNGP10 .phx.gbl>
<uY************ **@cpmsftngxa06 .phx.gbl>
| Subject: Re: Event that is invoked after a form has loaded
| Date: Wed, 30 Jul 2003 09:21:14 -0700
| Lines: 62
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <Oa************ **@TK2MSFTNGP11 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1730 09
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| Hi Jeffrey,
|
| Thanks for your reply. How do I trap a Windows's message in C# anyway?
| Speaking otherwise, how do I trap the WM_SHOWWINDOW and/or WM_ACTIVATE?
|
| "Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> wrote in message
| news:uY******** ******@cpmsftng xa06.phx.gbl...
| >
| > Hi David,
| >
| > I think the form's OnLoad() event is fire when the WM_CREATE message is
| > sent.
| >
| > I use the Spy++ to monitor the messages during the creation of a form.
| > I found that the form's WM_SHOWWINDOW message was sent after the
| WM_CREATE.
| > When this message is sent, the form has already been created, so you can
| > override the form's WndProc method and process WM_SHOWWINDOW message.
| >
| > In addition, I found that the child controls of the form was created
after
| > the WM_SHOWWINDOW message was sent, so you should process form's
| > WM_ACTIVATE message to make sure that the child controls are created.
| >
| > Hope it helps.
| >
| > 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.
| >
| > --------------------
| > | From: " David N" <dq*****@netiq. com>
| > | Subject: Event that is invoked after a form has loaded
| > | Date: Tue, 29 Jul 2003 13:56:04 -0700
| > | Lines: 10
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#4************ **@TK2MSFTNGP10 .phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| > | NNTP-Posting-Host: pat-50.bel.netiq.co m 65.219.170.50
| > | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| > | Xref: cpmsftngxa06.ph x.gbl
| microsoft.publi c.dotnet.langua ges.csharp:1727 88
| > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
| > |
| > |
| > | Hi All,
| > |
| > | The OnLoad() event is invoked automatically when a form is being
loaded.
| > Do
| > | we have another event that is invoked automatically after a form has
| > | completed loading?
| > |
| > | Thanks.
| > |
| > |
| > |
| >
|
|
|