日期:2014-05-18 浏览次数:21055 次
[DllImport("coredll.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private void button1_Click(object sender, EventArgs e)
{
PostMessage(this.Handle, 16, IntPtr.Zero, IntPtr.Zero);
}
private void button2_Click(object sender, EventArgs e)
{
SendMessage(this.Handle, 16, IntPtr.Zero, IntPtr.Zero);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
MessageBox.Show("FormClosed");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("FormClosing");
}
------解决方案--------------------
建议在窗体的closing事件里写,就不需要在WndProc里写了
protected override void OnClosing(CancelEventArgs e)
{
if (MessageBox.Show("你的数据还没有保存,保存吗?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
e.Cancel = true;
}
base.OnClosing(e);
}
------解决方案--------------------
const int SC_CLOSE = 0xF060;
sendmessage SC_CLOSE看
------解决方案--------------------
发WM_COPYDATA,自己定义COPYDATASTRUCT
------解决方案--------------------