// Diary.cpp : Defines the class behaviors for the application. //#include "stdafx.h" #include "Diary.h" #include "DiaryDlg.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CDiaryAppBEGIN_MESSAGE_MAP(CDiaryApp, CWinApp) //{{AFX_MSG_MAP(CDiaryApp) //}}AFX_MSG_MAP ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CDiaryApp constructionCDiaryApp::CDiaryApp() { // TODO: add construction code here, this->is_old = FALSE; this->m_pos = NULL; // Place all significant initialization in InitInstance }///////////////////////////////////////////////////////////////////////////// // The one and only CDiaryApp objectCDiaryApp theApp;///////////////////////////////////////////////////////////////////////////// // CDiaryApp initializationBOOL CDiaryApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CDiaryDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }void CDiaryApp::Serialize(CArchive& ar) { if (ar.IsStoring()) { // storing code } else { // loading code } }void CDiaryApp::OnSave() { CFile file; if(file.Open("Diary.dia",CFile::modeCreate|CFile::modeWrite)) { CArchive ar(&file, CArchive::load); Serialize(ar); ar.Close(); file.Close(); } }int CDiaryApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class ::AfxMessageBox(""); return CWinApp::ExitInstance(); }
//#include "stdafx.h"
#include "Diary.h"
#include "DiaryDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CDiaryAppBEGIN_MESSAGE_MAP(CDiaryApp, CWinApp)
//{{AFX_MSG_MAP(CDiaryApp)
//}}AFX_MSG_MAP
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDiaryApp constructionCDiaryApp::CDiaryApp()
{
// TODO: add construction code here,
this->is_old = FALSE;
this->m_pos = NULL;
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CDiaryApp objectCDiaryApp theApp;/////////////////////////////////////////////////////////////////////////////
// CDiaryApp initializationBOOL CDiaryApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CDiaryDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}void CDiaryApp::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{ // storing code
}
else
{ // loading code
}
}void CDiaryApp::OnSave()
{
CFile file;
if(file.Open("Diary.dia",CFile::modeCreate|CFile::modeWrite))
{
CArchive ar(&file, CArchive::load);
Serialize(ar);
ar.Close();
file.Close();
}
}int CDiaryApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
::AfxMessageBox("");
return CWinApp::ExitInstance();
}
可以成功
BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_CLOSE)
MessageBox(...);
}
运行成功 我点小叉叉 程序自做主张 直接退出了 根本没有显示对话框。
不过我估计你是按默认的那个确定键退出的,所以可能在OnOK()里面也要处理一下。
你可以在窗口的OnClose里这么写if ( MessageBox("你确认真的要退出吗 ?","提示" ,MB_OKCANCEL)==IDOK)
CDialog::OnClose();
要不就Sleep下,绝对行滴OnClose