(C++) You need to write a program similar to NOTEPAD. The program will allow the user to type anything he/she wants. Letters, digits, special characters. In as many rows as he/she wants.
The user then can save the text he/she wrote, then later on load it to continue working on. Your program should allow the user to do the following:
-Navigate the screen using the arrow keys (go up if there is text above the cursor and down if there is text below cursor, right if there is text on the right side of cursor and left if there is text on left side of cursor: linked list)
-Cursor can not go outside screen.
-User can save the document on disk in text format
-User can load item from a file into the editor. So if I have my own TEXT file, I can load it into your editor to read it and edit it
-User can manipulate text by adding, deleting, copy/pasting….etc.
-Display a menu with the options/commands the user can use to operate your editor
You can use this code to manipulate the interface:
#include <stdafx.h>
#include <iostream>
#include <windows.h>
using namespace std;
void gotoxy(int x, int y) {
COORD pos = { x, y };
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output, pos);
}
Expert Answer
#include <windows.h>
#define IDI_APP_ICON 1
#define IDD_ABOUT 100
#define IDC_STATIC 101
#define IDM_MAINMENU 200
#define IDM_FILE_NEW 201
#define IDM_FILE_OPEN 203
#define IDM_FILE_SAVE 204
#define IDM_FILE_EXIT 205
#define IDM_HELP_ABOUT 206
class MainWindow
{
public:
MainWindow(HINSTANCE hInstance);
~MainWindow();
static LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void OnCommand(HWND hwnd, int id, HWND hCtl, UINT codeNotify);
bool Run(int nCmdShow);
private:
WNDCLASSEX m_wndClass;
static HINSTANCE m_hInstance;
HWND m_hwnd;
static char m_szClassName[];
};
class AboutDialog
{
public:
AboutDialog();
~AboutDialog();
static BOOL CALLBACK DialogProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int Run(HINSTANCE hInstance, HWND hParent);
private:
HWND m_hwnd;
};
AboutDialog::AboutDialog()
{
}
AboutDialog::~AboutDialog()
{
}
// Function: Run
// Returns: Result of the DialogBox
int AboutDialog::Run(HINSTANCE hInstance, HWND hParent)
{
int retval = DialogBox(
hInstance,
MAKEINTRESOURCE(IDD_ABOUT), // Dialog template
hParent, // Pointer to parent hwnd
DialogProc);
}
BOOL CALLBACK
AboutDialog::DialogProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int retVal = false;
switch(msg)
{
case WM_INITDIALOG:
retVal = true;
break;
case WM_COMMAND:
if(LOWORD(wParam)== IDOK)
EndDialog(hwnd, TRUE);
break;
case WM_CLOSE:
EndDialog(hwnd, TRUE);
break;
}
return retVal;
}
char MainWindow::m_szClassName[] = "DrawLite";
HINSTANCE MainWindow::m_hInstance = NULL;
MainWindow::MainWindow(HINSTANCE hInstance)
{
m_hInstance = hInstance; // Save Instance handle
m_wndClass.cbSize = sizeof(WNDCLASSEX); // Must always be sizeof(WNDCLASSEX)
m_wndClass.style = CS_DBLCLKS; // Class styles
m_wndClass.lpfnWndProc = MainWndProc; // Pointer to callback procedure
m_wndClass.cbClsExtra = 0;
m_wndClass.cbWndExtra = 0;
m_wndClass.hInstance = hInstance;
m_wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
m_wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
m_wndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW);
m_wndClass.lpszMenuName = MAKEINTRESOURCE(IDM_MAINMENU);
m_wndClass.lpszClassName = m_szClassName;
m_wndClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
}
MainWindow::~MainWindow()
{
}
LRESULT CALLBACK MainWindow::MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
//HANDLE_WM_COMMAND(hwnd, wParam, lParam, OnCommand);
break;
default:
return DefWindowProc (hwnd, msg, wParam, lParam);
}
return 0;
}
void MainWindow::OnCommand(HWND hwnd, int id, HWND hCtl, UINT codeNotify)
{
switch(id)
{
case IDM_FILE_EXIT:
PostQuitMessage(0);
break;
case IDM_HELP_ABOUT:
AboutDialog* dlg = new AboutDialog();
dlg->Run(m_hInstance, hwnd);
delete dlg; dlg = NULL;
break;
}
}
bool MainWindow::Run(int nCmdShow)
{
if(!RegisterClassEx(&m_wndClass))
return false;
m_hwnd = CreateWindowEx(
0,
m_szClassName,
"Draw Lite",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
400,
NULL,
NULL,
m_hInstance,
NULL
);
if(!m_hwnd)
return false;
ShowWindow(m_hwnd, nCmdShow);
return true;
}
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
MainWindow *winMain = new MainWindow(hInst);
if(!winMain->Run(nCmdShow))
{
delete winMain;
return 1; // error
}
// Run the message loop. It will run until GetMessage() returns 0
while (GetMessage (&msg, NULL, 0, 0))
{
// Translate virtual-key messages into character messages
TranslateMessage(&msg);
// Send message to WindowProcedure
DispatchMessage(&msg);
}
delete winMain;
return msg.wParam;
}