-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
63 lines (49 loc) · 1.26 KB
/
Source.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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <new>
#include <string>
#include <stdexcept>
#include "common.h"
#include "CommandEnum.h"
#include "CaesarCipher.h"
#include "TextEditor.h"
FILE* filePtr = nullptr;
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
enum Mode;
BOOL WINAPI ConsoleHandler(DWORD);
int main()
{
if (!SetConsoleCtrlHandler(ConsoleHandler, TRUE)) {
fprintf(stderr, "Failed to set control handler\n");
return EXIT_FAILURE;
}
SetConsoleTextAttribute(hout, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN);
system("cls");
TextEditor* textEditor = nullptr;
textEditor = new TextEditor(50, 50, "caesarDLL");
bool ifContinue = true;
while (ifContinue)
{
textEditor->PrintMainMenu();
Mode command = textEditor->GetUserCommand();
if (command != UNDEFINED)
{
textEditor->ExecuteCommand(command, &ifContinue);
}
}
delete textEditor;
Sleep(100);
return 0;
}
BOOL WINAPI ConsoleHandler(DWORD signal) {
if (signal == CTRL_C_EVENT || signal == CTRL_CLOSE_EVENT || signal == CTRL_BREAK_EVENT ||
signal == CTRL_LOGOFF_EVENT || signal == CTRL_SHUTDOWN_EVENT) {
printf("\nProgram interrupted. Cleaning up...\n");
Sleep(1000);
if (filePtr != nullptr)
fclose(filePtr);
exit(0);
}
return TRUE;
}