S
SQACSharp
I have to following class :
using System;
using System.Windows.Forms;
namespace Test
{
public class SubclassWindow : NativeWindow
{
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand, Name =
"FullTrust")]
protected override void WndProc(ref Message m)
{
if (m.Msg==666)
MessageBox.Show("blablabla!");
}
IntPtr ObjectHandle;
public new void AssignHandle(IntPtr handle)
{
ObjectHandle=handle;
Control ctl = Control.FromHandle(handle);
MessageBox.Show("Assign handle for control :"+ctl.Name);
base.AssignHandle(handle);
}
public new void ReleaseHandle()
{
Control ctl = Control.FromHandle(ObjectHandle);
MessageBox.Show("Release handle for control :"+ctl.Name);
base.ReleaseHandle();
}
}
}
Drop 2 buttons in a form with the following code and click events :
SubclassWindow wr;
private void button1_Click(object sender, System.EventArgs e) //
assign handle button
{
wr=new SubclassWindow();
wr.AssignHandle(button2.Handle); //we pass the button2
handle...juste for the test
}
private void button2_Click(object sender, System.EventArgs e) //
release handle button
{
wr.ReleaseHandle();
}
After clicking button1 (assign) and button2 (release) the next time I
try to click the button1 there is an error in the messagebox because
ctl.Name is null?????? What is wrong when releasing the handle?
Any explanation? workaround? How an this be possible???????
Thanks!
Mike
using System;
using System.Windows.Forms;
namespace Test
{
public class SubclassWindow : NativeWindow
{
[System.Security.Permissions.PermissionSet
(System.Security.Permissions.SecurityAction.Demand, Name =
"FullTrust")]
protected override void WndProc(ref Message m)
{
if (m.Msg==666)
MessageBox.Show("blablabla!");
}
IntPtr ObjectHandle;
public new void AssignHandle(IntPtr handle)
{
ObjectHandle=handle;
Control ctl = Control.FromHandle(handle);
MessageBox.Show("Assign handle for control :"+ctl.Name);
base.AssignHandle(handle);
}
public new void ReleaseHandle()
{
Control ctl = Control.FromHandle(ObjectHandle);
MessageBox.Show("Release handle for control :"+ctl.Name);
base.ReleaseHandle();
}
}
}
Drop 2 buttons in a form with the following code and click events :
SubclassWindow wr;
private void button1_Click(object sender, System.EventArgs e) //
assign handle button
{
wr=new SubclassWindow();
wr.AssignHandle(button2.Handle); //we pass the button2
handle...juste for the test
}
private void button2_Click(object sender, System.EventArgs e) //
release handle button
{
wr.ReleaseHandle();
}
After clicking button1 (assign) and button2 (release) the next time I
try to click the button1 there is an error in the messagebox because
ctl.Name is null?????? What is wrong when releasing the handle?
Any explanation? workaround? How an this be possible???????
Thanks!
Mike