473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MDI child, Overriden WndProc function and hidden child form

Hello:

I am encountering a very weird issue with MDI child, Overriden WndProc
function and hidden form.

Basically, the application has two forms, Form1(parent form),
Form2(Child form), Form2's WndProc method is overriden, if the message
is CLOSE message, just hide the form. I first initialize and show the
child form, then close it by clicking the Close(X) button, the
overriden WndProc method gets invoked, and the form is hidden. Then
from Form1(parent form), I explcitly call Form2.Close(), this time, the
overriden WndProc method is not called, instead, the flow goes to
Form2.Dispose() methid directly and clear all the resource. However, I
am expecting the overriden WndProc method should be invoked as well
when calling Form2.Close().

Interesting observation is that if I set form2.Visible = true before
calling Form2.Close(), this way, the overriden ProdWnc process would be
invoked.

COuld anyone shed a light on this issue? I am so frustrated with this
one.

Thanks a lot.

Below is the sample code for Form1 and Form2.
//
// FORM2
//

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Threadin g;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class Form2 : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form2()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

protected override void WndProc(ref Message m_)
{
if (m_.Msg == Win32.WM_CLOSE) // 0x0010
{
this.Hide();
}
else
{
base.WndProc(re f m_);
}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.Size = new System.Drawing. Size(300,300);
this.Text = "Form2";
// this.Closing += new
System.Componen tModel.CancelEv entHandler(this .Form_Closing);
}
#endregion

}
}
//
// FORM1
//
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;
using System.Windows. Forms;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
private System.Windows. Forms.Button button2;
private Form2 frm2;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this.button2 = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(128, 80);
this.button1.Na me = "button1";
this.button1.Si ze = new System.Drawing. Size(136, 56);
this.button1.Ta bIndex = 0;
this.button1.Te xt = "CloseForm2 ";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(120, 184);
this.button2.Na me = "button2";
this.button2.Si ze = new System.Drawing. Size(144, 40);
this.button2.Ta bIndex = 1;
this.button2.Te xt = "Initialize ";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.button2 );
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}

// protected override void WndProc(ref Message m_)
// {
// if (m_.Msg == Win32.WM_CLOSE) // 0x0010
// {
// this.Visible = false;
// MessageBox.Show ("I am here");
// }
// else
// {
// base.WndProc(re f m_);
// }
// }

private void button1_Click(o bject sender, System.EventArg s e)
{
frm2.Close();
}

private void Form1_Load(obje ct sender, System.EventArg s e)
{
this.IsMdiConta iner = true;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
if(frm2 == null)
{
frm2 = new Form2();
}

frm2.Text = "TestChild" ;
frm2.MdiParent = this;

frm2.Show();
frm2.Activate() ;
frm2.BringToFro nt();

}

}
}

Oct 18 '05 #1
0 2487

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5934
by: zobie | last post by:
In the parent of my MDI application I declare a child form private frmChild = null; which is to be activated on a menu click. In the click event I am using the following code: if (frmChild == null || !frmChild .IsHandleCreated) { frmChild = new frmChild ();
2
9005
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value changes, I call a method on the parent form to change some menu options, and then I need to close the child form. My code looks something like this: ...
1
3403
by: sshuangw | last post by:
Hello: I am encountering a werid problem, in my application, When I have hidden my form ("myform.Visible = false"), WndProc doesn't catch messages sent to the app. When the form is not hidden, WndProc successfully catches the message. What could be the possible reasons for this issue? Could anyone shed a light on this!
4
2017
by: Bonj | last post by:
Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main window's messages are routed to - what is the way of identifying from the lParam or wParam whether the message came from a child window or the parent? And what if the message uses some other data in the wParam or...
4
1528
by: mike2036 | last post by:
I'm having problems with the reliability of WndProc in my application. The application has a hidden form, which it instantiates in the Main() and then calls Application.Run(). There are cases where WndProc does not receive internal messages via PostMessageA(). Sometimes it works, sometimes it doesn't. It seems that calling...
0
335
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form), Form2's WndProc method is overriden, if the message is CLOSE message, just hide the form. I first initialize and show the child form, then close it by...
5
8026
by: midnight_use_only | last post by:
hi all, quick question, how do you submit a form to a parent window from a child popup window? i have the following and all online documentation *suggests* that it should work but it does NOT: // Parent window: <script language="JavaScript"> function popup(url, name) { window.open(url, name, "width=800,height=600,scrollbars=yes");
2
2258
by: Matt Brown - identify | last post by:
Hello, I'm very new to this level of programming and .net in general. My background is VB. I am attempting to use the WebBrowser control to load a flash movie, and it is a known issue that the WebBrowser control doesn't natively support mouse clicks (unless the form loses and regains focus).
2
2424
by: ewokspy | last post by:
I have read up a bit on WndProc. and I have the below in my code. But I have two issues. One it seems that the code only runs while the form is running code, so if I have the form on standby, hidden in the system tray, this function is never called. So I never run the shutdown code. How can I get this to run if the system is shutting down, and...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.