我也遇到这种情况:以前用system suite版本在debug模式下(release下没有试)编译成功的程序, 改装vs2005 专业版后在release下编译成功,而在debug下却出错,如下:错误 1 fatal error C1853: “Debug\test.pch”预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 C 中使用它(或相反) g:\My Documents\Visual Studio 2005\Projects\c c++ c++.net合并\test\test.cpp 3
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace TestSaveOnQuitSystem { public partial class Form1 : Form { public Form1() { InitializeComponent(); Application.AddMessageFilter(MyMsgFilterClass.GetMsgFilter()); MyMsgFilterClass.GetMsgFilter().ExitWindowEvent += new EventHandler(Form1_ExitWindowEvent); } void Form1_ExitWindowEvent(object sender, EventArgs e) { //处理 }
} public class MyMsgFilterClass : IMessageFilter { public static MyMsgFilterClass GetMsgFilter() { if (s_obj == null) { s_obj = new MyMsgFilterClass(); } return s_obj; } private MyMsgFilterClass() : base() { } private static MyMsgFilterClass s_obj = null; #region IMessageFilter 成员 private const int WM_QUERYENDSESSION = 0x0011; public event EventHandler ExitWindowEvent = null; bool IMessageFilter.PreFilterMessage(ref Message m) { if (m.Msg == WM_QUERYENDSESSION) { //写你的保存代码。或者在事件里写保存代码 if (ExitWindowEvent != null) { ExitWindowEvent(this, new EventArgs()); } return true; } return false; } #endregion } }
事件委托给form的close事件呀
改装vs2005 专业版后在release下编译成功,而在debug下却出错,如下:错误 1 fatal error C1853: “Debug\test.pch”预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 C 中使用它(或相反) g:\My Documents\Visual Studio 2005\Projects\c c++ c++.net合并\test\test.cpp 3
btnSave_Click(Nothing,Nothing)
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestSaveOnQuitSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); Application.AddMessageFilter(MyMsgFilterClass.GetMsgFilter());
MyMsgFilterClass.GetMsgFilter().ExitWindowEvent += new EventHandler(Form1_ExitWindowEvent);
} void Form1_ExitWindowEvent(object sender, EventArgs e)
{
//处理
}
} public class MyMsgFilterClass : IMessageFilter
{
public static MyMsgFilterClass GetMsgFilter()
{
if (s_obj == null)
{
s_obj = new MyMsgFilterClass();
}
return s_obj;
} private MyMsgFilterClass()
: base()
{
} private static MyMsgFilterClass s_obj = null;
#region IMessageFilter 成员
private const int WM_QUERYENDSESSION = 0x0011;
public event EventHandler ExitWindowEvent = null;
bool IMessageFilter.PreFilterMessage(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
//写你的保存代码。或者在事件里写保存代码
if (ExitWindowEvent != null)
{
ExitWindowEvent(this, new EventArgs());
}
return true;
}
return false;
} #endregion
}
}