下面实例是在退出程序点击退出按钮时,在主程序的根目录下生成一个Log记录,用来记录程序的退出时间,具体实现代码与调试代码如下:

void CDebugDlg::OnClose()
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 
 CFile file;
 CTime time=CTime::GetCurrentTime();

CString str1="记录系统退出时间为:";
 CString str2=time.Format("%y-%m-%d %H:%M:%S");
 CString str3=" \r\n";
 unsigned char pchData[MAX_PATH]={0};

file.Open("Log.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
 file.Read(pchData,MAX_PATH);

if (MessageBox("你是否确定现在退出软件?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
 {
  
  str1+=str2;
  str1+=str3;
  MessageBox(str1,"提示一");
  file.Write(str1,str1.GetLength());
  MessageBox(str1+(char*)pchData,"提示二");  //打印当前缓冲区文件中的数据

OnCancel();
 }

实例二:

相对实例一中的代码来说,只是在代码一的基础上,在log输出文件中增加了打印当前应用程序标题名,其中标题名由title变量变示,具体修改如下:

void CDebugDlg::OnClose()
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 
 CFile file;
 CTime time=CTime::GetCurrentTime();

CString str1="----系统退出时间为:";
 CString str2=time.Format("%y-%m-%d %H:%M:%S");
 CString str3=" \r\n";
 CString title="";
 unsigned char pchData[MAX_PATH]={0};

GetWindowText(title);  //获取应用程序标题名

file.Open("Log.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
 file.Read(pchData,MAX_PATH);

if (MessageBox("你是否确定现在退出软件?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
 {
  title+=str1;
  title+=str2;
  title+=str3;
  MessageBox(title,"提示一");

file.Write(title,title.GetLength());
  MessageBox(title+(char*)pchData,"提示二");  //打印当前缓冲区文件中的数据

OnCancel();
 }
}

最新文章

  1. JS无刷新分页插件
  2. fuck me on github
  3. AndroidDevTools下载地址
  4. [Effective JavaScript 笔记] 第6条:了解分号插入的局限
  5. 简介spring中MethodReplacer的用法
  6. How to download a website for offline usage
  7. DHTMLX 前端框架 建立你的一个应用程序 教程(八)-- 添加表单Form
  8. 《30天自制操作系统》读书笔记(2)hello, world
  9. Tr A(HDU 1575 快速矩阵幂模板)
  10. WPF制作的小型笔记本
  11. Java 9 揭秘(17. Reactive Streams)
  12. npm缺少css-loader,/style-compiler,stylus-loader问题,npm没有权限无法全局更新问题【已解决】
  13. Ruby http/net 中连接超时问题
  14. 采用模拟账号读取Exchange server未读邮件的注意事项(链接邮箱问题)【转】
  15. SQL 收集
  16. 山东第四届省赛: Boring Counting 线段树
  17. 使用Instruments中的CoreAnimation分析动画
  18. 回顾下TCP/IP协议
  19. Openstack镜像和密码
  20. DropDownList绑定数据的几种方式

热门文章

  1. wefwewewe
  2. incomplete type is not allowed
  3. 共享AFHTTPSessionManager 单例好处浅析
  4. Android:Asmack能登录但是获取不到联系人的问题
  5. java中多态的使用
  6. -webkit-overflow-scrolling
  7. 《JavaScript高级程序设计》读书笔记 ---RegExp 类型
  8. Zookeeper实现分布式锁服务(Chubby)
  9. linux命令随记
  10. oracle 索引 。其中全文检索最变态