Click here to Skip to main content
15,896,915 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Convert CString to DWORD or CString to COLORREF Pin
orihime10-Feb-08 18:09
orihime10-Feb-08 18:09 
GeneralRe: Convert CString to DWORD or CString to COLORREF Pin
CPallini10-Feb-08 21:46
mveCPallini10-Feb-08 21:46 
Questionprivileged instruction exception in ultimate grid Pin
Anna Anna7-Feb-08 22:44
Anna Anna7-Feb-08 22:44 
GeneralRe: privileged instruction exception in ultimate grid Pin
Iain Clarke, Warrior Programmer8-Feb-08 1:12
Iain Clarke, Warrior Programmer8-Feb-08 1:12 
GeneralRe: privileged instruction exception - Problem solved Pin
Anna Anna8-Feb-08 3:27
Anna Anna8-Feb-08 3:27 
GeneralA very strange problem (to me at least) ..... Pin
Still learning how to code7-Feb-08 22:28
Still learning how to code7-Feb-08 22:28 
GeneralRe: A very strange problem (to me at least) ..... Pin
CPallini7-Feb-08 23:06
mveCPallini7-Feb-08 23:06 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code7-Feb-08 23:13
Still learning how to code7-Feb-08 23:13 
Here's the CLogFile class (.h and .cpp)

#if !defined(AFX_LOGFILE_H__55017EEE_12D9_4F35_9CBC_4C111B28982A__INCLUDED_)
#define AFX_LOGFILE_H__55017EEE_12D9_4F35_9CBC_4C111B28982A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// LogFile.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// LogFile

class CLogFile : public CStatic
{
// Construction
public:
CLogFile();

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(LogFile)
//}}AFX_VIRTUAL

// Implementation
public:
void Add(CString szMessage);
CFile fLogFile;
CString m_szRootPath;
void Start(BOOL bAppend);
CString m_szLogFile;
CString m_szLogFilePath;
CLogFile(CString szLogFile, BOOL bAppend = FALSE);
virtual ~CLogFile();

// Generated message map functions
protected:
//{{AFX_MSG(CLogFile)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LOGFILE_H__55017EEE_12D9_4F35_9CBC_4C111B28982A__INCLUDED_)





// LogFile.cpp : implementation file
//

#include "stdafx.h"
#include "LogFile.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLogFile

CLogFile::CLogFile()
{
}

CLogFile::~CLogFile()
{
}


BEGIN_MESSAGE_MAP(CLogFile, CStatic)
//{{AFX_MSG_MAP(LogFile)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogFile message handlers

CLogFile::CLogFile(CString szLogFile, BOOL bAppend)
{
m_szRootPath = "C:\\";
m_szLogFile = szLogFile;
m_szLogFilePath.Format("%s\\%s.log",m_szRootPath,szLogFile);
Start(bAppend);
}

void CLogFile::Start(BOOL bAppend)
{
CString szCopyFilePath, szFrom, szTo;
szCopyFilePath.Format("%s\\%s.bak",m_szRootPath,m_szLogFile);

// Push down LIFO stack of LogFiles
for( int iIndex = 5; iIndex > 0; iIndex--)
{
szFrom.Format("%s%sLog%i.bak",m_szRootPath,m_szLogFile,iIndex-1);
szTo.Format("%s%sLog%i.bak",m_szRootPath,m_szLogFile,iIndex);
CopyFile(szFrom,szTo,FALSE);
}
// Copy .log to .bak0
szTo.Format("%s%sLog%i.bak",m_szRootPath,m_szLogFile,iIndex);
CopyFile(m_szLogFilePath,szTo,FALSE);

BOOL bRC;
if(bAppend)
bRC = fLogFile.Open( m_szLogFilePath, CFile::modeWrite );
else
bRC =fLogFile.Open( m_szLogFilePath, CFile::modeCreate | CFile::modeWrite );

CString szMsg;
if(bRC == 0)
{
szMsg.Format("File not found %s",m_szLogFilePath);
AfxMessageBox(szMsg);
}
CTime TimeNow = CTime::GetCurrentTime();
CString szDate = TimeNow.Format( "%A, %B %d, %Y" );
//ASSERT( s == "Friday, March 19, 1999" );

CString sMessage, sText;

if(!bAppend)
{
sMessage = "Start of log file ";
sText.Format("%s - %s%c%c",sMessage,szDate,'\r','\n');

fLogFile.Write(sText.GetBuffer(512),sText.GetLength());

sMessage = "-----------------------------------------------------";
sText.Format("%s%c%c",sMessage,'\r','\n');
fLogFile.Write(sText.GetBuffer(512),sText.GetLength());
}
fLogFile.Close();

}

void CLogFile::Add(CString szMessage)
{
fLogFile.Open( m_szLogFilePath, CFile::modeWrite );
fLogFile.Seek( 0,CFile::end);
CString szText;
// Get current time
CTime TimeNow = CTime::GetCurrentTime();
CString szTime;
szTime.Format("%02i:%02i:%02i",TimeNow.GetHour(),TimeNow.GetMinute(),TimeNow.GetSecond());
szText.Format("%s %s%c%c",szTime,szMessage,'\r','\n');
fLogFile.Write(szText.GetBuffer(512),szText.GetLength());

fLogFile.Close();
}

Doug
QuestionRe: A very strange problem (to me at least) ..... Pin
CPallini7-Feb-08 23:16
mveCPallini7-Feb-08 23:16 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code7-Feb-08 23:58
Still learning how to code7-Feb-08 23:58 
GeneralRe: A very strange problem (to me at least) ..... Pin
CPallini8-Feb-08 0:05
mveCPallini8-Feb-08 0:05 
GeneralRe: A very strange problem (to me at least) ..... Pin
Matthew Faithfull8-Feb-08 0:09
Matthew Faithfull8-Feb-08 0:09 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code8-Feb-08 0:59
Still learning how to code8-Feb-08 0:59 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code8-Feb-08 1:31
Still learning how to code8-Feb-08 1:31 
QuestionRe: A very strange problem (to me at least) ..... Pin
CPallini8-Feb-08 2:17
mveCPallini8-Feb-08 2:17 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code8-Feb-08 2:37
Still learning how to code8-Feb-08 2:37 
GeneralRe: A very strange problem (to me at least) ..... Pin
CPallini8-Feb-08 2:50
mveCPallini8-Feb-08 2:50 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code8-Feb-08 3:23
Still learning how to code8-Feb-08 3:23 
QuestionRe: A very strange problem (to me at least) ..... Pin
David Crow8-Feb-08 2:49
David Crow8-Feb-08 2:49 
GeneralRe: A very strange problem (to me at least) ..... Pin
Still learning how to code8-Feb-08 5:19
Still learning how to code8-Feb-08 5:19 
Generalnon-const static member variale initialization Pin
George_George7-Feb-08 21:16
George_George7-Feb-08 21:16 
GeneralRe: non-const static member variale initialization Pin
Matthew Faithfull7-Feb-08 22:13
Matthew Faithfull7-Feb-08 22:13 
GeneralRe: non-const static member variale initialization Pin
George_George8-Feb-08 1:49
George_George8-Feb-08 1:49 
GeneralRe: non-const static member variale initialization Pin
Matthew Faithfull8-Feb-08 2:29
Matthew Faithfull8-Feb-08 2:29 
GeneralRe: non-const static member variale initialization Pin
led mike8-Feb-08 4:17
led mike8-Feb-08 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.