-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeDate.cpp
More file actions
66 lines (65 loc) · 1.5 KB
/
timeDate.cpp
File metadata and controls
66 lines (65 loc) · 1.5 KB
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
#include <Windows.h>
#include "globalVars.h"
#include "timeDate.h"
/*
time formats:
AM/PM - h:m:s(AM),h:m:s(PM)
Military - hh:mm:ss
*/
/*
date formats:
US -> m/d/yyyy
European -> d/m/yyyy
ISO -> yyyy/m/d
*/
TCHAR *amStr = _T(" (AM)");
TCHAR *pmStr = _T(" (PM)");
void getCurrentTime(int mode) {
SYSTEMTIME currTime;
GetLocalTime(&currTime);
formatTimeStr(currTime.wHour,currTime.wMinute,currTime.wSecond, mode);
}
void getCurrentDate(int mode) {
SYSTEMTIME currDate;
GetLocalTime(&currDate);
formatDateStr(currDate.wMonth,currDate.wDay,currDate.wYear, mode);
}
void formatTimeStr(WORD h,WORD m,WORD s, int mode) {
TCHAR timeStr[256];
TCHAR *dayNight;
if (mode == IDT_TIME_US) {
if (h > 12) {
dayNight = pmStr;
}
else {
dayNight = amStr;
}
h-=12;
_stprintf(timeStr, _T("%d:%d:%d"), h, m, s);
_tcscat(timeStr,dayNight);
}
else if (mode == IDT_TIME_MILITARY) {
_stprintf(timeStr, _T("%d:%d:%d"), h, m, s);
}
sendTimeDate2RE(timeStr);
}
void formatDateStr(WORD m,WORD d,WORD y, int mode) {
TCHAR dateStr[256];
if (mode==IDT_DATE_US) {
_stprintf(dateStr, _T("%d/%d/%d"), m, d, y);
}
else if (mode==IDT_DATE_EUR) {
_stprintf(dateStr, _T("%d/%d/%d"), d, m, y);
}
else if (mode == IDT_DATE_ISO) {
_stprintf(dateStr, _T("%d/%d/%d"), y, m, d);
}
sendTimeDate2RE(dateStr);
}
void sendTimeDate2RE(TCHAR formattedStr[]) {
CHARRANGE cr;
cr.cpMin = -1;
cr.cpMax = -1;
SendMessage(richEditControl,EM_EXSETSEL,0,(LPARAM)&cr);
SendMessage(richEditControl, EM_REPLACESEL, 0, (LPARAM)formattedStr);
}