php中文网 | cnphp.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 382|回复: 0

检测查找文件是否失败并提示

[复制链接]

2627

主题

2634

帖子

9336

积分

管理员

Rank: 9Rank: 9Rank: 9

UID
1
威望
0
积分
6587
贡献
0
注册时间
2021-4-14
最后登录
2024-4-26
在线时间
667 小时
QQ
发表于 2022-7-20 21:43:16 | 显示全部楼层 |阅读模式
[mw_shl_code=cpp,true]// StockNotifyNewsCheck.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "StockNotifyNewsCheck.h"
#include "StockNotifyNewsCheckDlg.h"
#include <direct.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

char gszSystemDir[MAX_PATH];                        // 系统路径
char gszIniFileName[MAX_PATH];                        // 主配置文件路径
/////////////////////////////////////////////////////////////////////////////
// CStockNotifyNewsCheckApp

void LogFile(char *String)
{
    try
    {
                char szPath[MAX_PATH];
                memset(szPath, 0, MAX_PATH);
                szPath[MAX_PATH-1] = 0;
                _snprintf(szPath, MAX_PATH-1, "%s\\Log", gszSystemDir);
                _mkdir(szPath);

                CFile        TmpFile;
        CString FileName;
        SYSTEMTIME SysTime;
        ::GetLocalTime(&SysTime);
        CTime curTime = CTime::GetCurrentTime();
        FileName.Format("%s\\Log\\NotifyNewsCheck%04d%02d%02d_%02d.log",
            gszSystemDir,
            curTime.GetYear(),
            curTime.GetMonth(),
            curTime.GetDay(),
                        curTime.GetHour());
        
        if(!TmpFile.Open(FileName,
            CFile :: typeBinary | CFile :: shareDenyNone |CFile :: modeWrite
            | CFile::modeCreate | CFile::modeNoTruncate,
            NULL))
        {
            return;
        }
        
        char TmpString[2560];
        
        _snprintf(TmpString, 2559, "%02d:%02d:%02d:%04d  %s\r\n",
            curTime.GetHour(),
            curTime.GetMinute(),
            curTime.GetSecond(),
            SysTime.wMilliseconds,
            String);
        TmpFile.SeekToEnd();
        TmpFile.Write(TmpString, strlen(TmpString));
        TmpFile.Close();
    }
    catch(...)
    {
        CString strLogErr = _T("");
        int err = ::GetLastError();
        strLogErr.Format("err:%d Content:%s ", err, String);
    }
}

void LogFile_Name(char *LogFileName, char *String)
{
    try
    {
                char szPath[MAX_PATH];
                memset(szPath, 0, MAX_PATH);
                szPath[MAX_PATH-1] = 0;
                _snprintf(szPath, MAX_PATH-1, "%s\\Log", gszSystemDir);
                _mkdir(szPath);
               
                CFile        TmpFile;
        CString FileName;
        SYSTEMTIME SysTime;
        ::GetLocalTime(&SysTime);
        CTime CurTime = CTime::GetCurrentTime();
        FileName.Format("%s\\Log\\%s.log",
            gszSystemDir,
            LogFileName);
        
        if(!TmpFile.Open(FileName,
            CFile :: typeBinary | CFile :: shareDenyNone |CFile :: modeWrite
            | CFile::modeCreate | CFile::modeNoTruncate,
            NULL))
        {
            return;
        }
        
        char TmpString[2560];
        
        _snprintf(TmpString, 2559, "%s\r\n",  String);
        TmpFile.SeekToEnd();
        TmpFile.Write(TmpString, strlen(TmpString));
        TmpFile.Close();
    }
    catch(...)
    {
        CString strLogErr = _T("");
        int err = ::GetLastError();
        strLogErr.Format("err:%d Content:%s ", err, String);
    }
}

BEGIN_MESSAGE_MAP(CStockNotifyNewsCheckApp, CWinApp)
        //{{AFX_MSG_MAP(CStockNotifyNewsCheckApp)
                // NOTE - the ClassWizard will add and remove mapping macros here.
                //    DO NOT EDIT what you see in these blocks of generated code!
        //}}AFX_MSG
        ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStockNotifyNewsCheckApp construction

CStockNotifyNewsCheckApp::CStockNotifyNewsCheckApp()
{
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CStockNotifyNewsCheckApp object

CStockNotifyNewsCheckApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CStockNotifyNewsCheckApp initialization

BOOL CStockNotifyNewsCheckApp::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

        //
        // 初始化程序路径
        //
        char szFileName[MAX_PATH];
        szFileName[MAX_PATH-1] = 0;
        memset(gszSystemDir, 0, MAX_PATH);
        ::GetModuleFileName(NULL, gszSystemDir, MAX_PATH-1);
        char *pDest = strrchr(gszSystemDir, '\\');
        if (pDest == NULL)
        {
                return FALSE;
        }
        *pDest = '\0';
        memset(gszIniFileName, 0, MAX_PATH);
        _snprintf(gszIniFileName, MAX_PATH-1, "%s\\config.ini", gszSystemDir);

        CStockNotifyNewsCheckDlg 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;
}
[/mw_shl_code]





上一篇:算法(背包问题)
下一篇:MSTS电源检测
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|php中文网 | cnphp.com ( 赣ICP备2021002321号-2 )51LA统计

GMT+8, 2024-4-26 20:50 , Processed in 0.190590 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

申明:本站所有资源皆搜集自网络,相关版权归版权持有人所有,如有侵权,请电邮(fiorkn@foxmail.com)告之,本站会尽快删除。

快速回复 返回顶部 返回列表