rendered paste body#include <windows.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include "resource.h"const char g_szClassName[] = "MyClass";const char txtBuf[1500];int fileOpened = 0;char fileBuffer[200] = "";char openFileBuffer[200] = "";char str[100];char set[1500] = "";FILE *fp;FILE *fp_o;HWND g_hTool = NULL;HWND hTool = NULL;HWND g_hEdit = NULL;BOOL CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK ToolDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK EditDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK SaveasDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK OpenDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK ExitDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ WNDCLASSEX wc; HWND hWnd; MSG msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLIP)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = IDR_MENU1; wc.lpszClassName = g_szClassName; wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLIP), IMAGE_ICON, 16, 16, 0); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Error registering class", "Error", MB_ICONEXCLAMATION | MB_OK); return 0; } hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName,"RevEdit - By RevolutioN", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, NULL, NULL, hInstance, NULL); if(hWnd == NULL) { MessageBox(NULL, "Error creating window", "Error", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;}BOOL CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_CREATE: g_hEdit = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_EDIT), hWnd, EditDlgProc); if(g_hEdit != NULL) { ShowWindow(g_hEdit, SW_SHOW); } else { MessageBox(hWnd, "Error creating editbox", "Error", MB_OK | MB_ICONEXCLAMATION); } break; case WM_CLOSE: { int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_EXIT), hWnd, ExitDlgProc); if(ret != IDC_EXIT_CANCEL) { fclose(fp); PostQuitMessage(0); } } break; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_FILE_SAVEAS: GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SAVEAS), hWnd, SaveasDlgProc); break; case ID_HELP_ABOUT: DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hWnd, AboutDlgProc); break; case ID_FILE_SAVENORMAL: if(fileOpened == 1) { GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); if(strcmp(txtBuf, set) != 0) { MessageBox(hWnd, "txtBuf != set", "Notice", MB_OK); MessageBox(hWnd, txtBuf, "Notice", MB_OK); fputs(txtBuf, fp); } } else if(fileOpened == 0) { GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SAVEAS), hWnd, SaveasDlgProc); } break; case ID_FILE_NEWDOC: if(fileOpened == 1) { fclose(fp); } DestroyWindow(g_hEdit); g_hEdit = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_EDIT), hWnd, EditDlgProc); if(g_hEdit != NULL) { ShowWindow(g_hEdit, SW_SHOW); } else { MessageBox(hWnd, "Error creating editbox", "Error", MB_OK | MB_ICONEXCLAMATION); } break; case ID_FILE_OPENNORMAL: DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPEN), hWnd, OpenDlgProc); break; } default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0;}BOOL CALLBACK ToolDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_SAVEAS: GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SAVEAS), hWnd, SaveasDlgProc); break; } } return 0;}BOOL CALLBACK EditDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { } return 0;}BOOL CALLBACK SaveasDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_SAVEAS_SAVE: { GetDlgItemText(hWnd, IDC_FILE, fileBuffer, 200); fp = fopen(fileBuffer, "w"); fputs(txtBuf, fp); fclose(fp); fileOpened = 1; MessageBox(NULL, "File saved", "Notice", MB_OK | MB_ICONINFORMATION); EndDialog(hWnd, IDC_SAVEAS_SAVE); } break; } break; case WM_CLOSE: EndDialog(hWnd, IDC_SAVEAS_SAVE); break; } return 0;}BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_CLOSE: EndDialog(hWnd, NULL); break; } return 0;}BOOL CALLBACK OpenDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_CLOSE: EndDialog(hWnd, NULL); break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_OPEN_OPEN: GetDlgItemText(hWnd, IDC_OPENFILE, openFileBuffer, 200); if((fp = fopen(openFileBuffer, "r")) == NULL) { MessageBox(hWnd, "File does not exist", "Error", MB_OK | MB_ICONEXCLAMATION); } else { fileOpened = 1; while(fgets(str, 100, fp) != NULL) { strcat(set, str); } SetDlgItemText(g_hEdit, IDC_TXT, set); fclose(fp); EndDialog(hWnd, NULL); fp = fopen(openFileBuffer, "w"); } break; } } return 0;}BOOL CALLBACK ExitDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_EXIT_SAVE: { if(fileOpened == 1) { GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); fputs(txtBuf, fp); } else if(fileOpened == 0) { GetDlgItemText(g_hEdit, IDC_TXT, txtBuf, 1500); DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SAVEAS), hWnd, SaveasDlgProc); } } fclose(fp); PostQuitMessage(0); break; case IDC_EXIT_DISCARD: if(fileOpened == 1) { fclose(fp); } PostQuitMessage(0); break; case IDC_EXIT_CANCEL: EndDialog(hWnd, IDC_EXIT_CANCEL); break; } case WM_CLOSE: EndDialog(hWnd, IDC_EXIT_CANCEL); break; } return 0;}