-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdafx.cpp
73 lines (63 loc) · 3.33 KB
/
stdafx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// stdafx.cpp : 僅包含標準 Include 檔的原始程式檔
// HM_Machine.pch 會成為先行編譯標頭檔
// stdafx.obj 會包含先行編譯類型資訊
#include "stdafx.h"
/*獲取路徑*/
CString GetModulePath()
{
TCHAR s_buf[MAX_PATH];
s_buf[0] = 0x0;
DWORD n_result = ::GetModuleFileName(NULL, s_buf, sizeof(TCHAR) * MAX_PATH);
TCHAR s_drive[MAX_PATH];
s_drive[0] = 0x0;
TCHAR s_dir[MAX_PATH];
s_dir[0] = 0x0;
/*errno_t n_err_no =*/
_tsplitpath(s_buf, s_drive, s_dir, NULL, NULL);
//assert(n_err_no == 0);
_tcscpy_s(s_buf, s_drive);
_tcscat_s(s_buf, s_dir);
return CString(s_buf);
}
/*寫入Log檔*/
void WriteLogFile(CFile &File,CString error_number,CString note)
{
//**事先要先宣告CFile傳入 & 宣告路徑給他OPEN**
//獲取系統時間
CString write_time;
CTime tmd;
tmd = CTime::GetCurrentTime();
write_time = tmd.Format("%Y/%m/%d\n%X");
//空格
CString write_blank;
write_blank = _T("\r\n");
//工作資訊
CString send;
send += write_time;
send += _T("\t");
send += error_number;
send += _T("\t");
send += note;
send += _T("\t");
send += write_blank;
File.SeekToEnd();
File.Write(send, send.GetLength()*sizeof(TCHAR));
}
/*寫入歷史訊息*/
void WriteHistory(CFile &File, CString write_account, CString write_action, CString write_alarm)
{
//獲取系統時間
CString write_date;
CString write_time;
CTime tmd;
tmd = CTime::GetCurrentTime();
write_date = tmd.Format("%Y/%m/%d");
write_time = tmd.Format("%X");
CArchive ar(&File, CArchive::store);
ar << write_date;
ar << write_time;
ar << write_account;
ar << write_action;
ar << write_alarm;
ar.Close();
}