C# Programming
06-15-2009, 09:54 AM
I can get the WM_CREATE msg in WndProc when I click button1,but it didn't fired at the PreFilterMessage.
Follow is the source code.Thanks!
static class Program
{
///
/// ??????????
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
filter ft = new filter();
Application.AddMessageFilter(ft);
Form1 f = new Form1();
f.Show();
Application.Run();
}
}
public class filter : IMessageFilter
{
#region IMessageFilter ??
const int WM_CREATE = 0x00001;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_CREATE)
{
MessageBox.Show("A");
return true;
}
return false;
}
#endregion
}
public partial class Form1 : Form
{
#region Designer
///
/// ?????????
///
private System.ComponentModel.IContainer components = null;
///
/// ????????????
///
/// ?????????,? true;??? false?
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows ??????????
///
/// ?????????? - ??
/// ????????????????
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.******** = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(609, 265);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.Show();
}
const int WM_CREATE = 0x00001;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CREATE)
{ MessageBox.Show("B"); }
base.WndProc(ref m);
}
}
Follow is the source code.Thanks!
static class Program
{
///
/// ??????????
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
filter ft = new filter();
Application.AddMessageFilter(ft);
Form1 f = new Form1();
f.Show();
Application.Run();
}
}
public class filter : IMessageFilter
{
#region IMessageFilter ??
const int WM_CREATE = 0x00001;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_CREATE)
{
MessageBox.Show("A");
return true;
}
return false;
}
#endregion
}
public partial class Form1 : Form
{
#region Designer
///
/// ?????????
///
private System.ComponentModel.IContainer components = null;
///
/// ????????????
///
/// ?????????,? true;??? false?
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows ??????????
///
/// ?????????? - ??
/// ????????????????
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.******** = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(609, 265);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.Show();
}
const int WM_CREATE = 0x00001;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CREATE)
{ MessageBox.Show("B"); }
base.WndProc(ref m);
}
}