威望0
积分7946
贡献0
在线时间763 小时
UID1
注册时间2021-4-14
最后登录2024-11-21
管理员
- UID
- 1
- 威望
- 0
- 积分
- 7946
- 贡献
- 0
- 注册时间
- 2021-4-14
- 最后登录
- 2024-11-21
- 在线时间
- 763 小时
|
[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] |
|