设计一个简单的文本编辑器,用C语言实现(高分悬赏)

基本要求(1)具有图形菜单界面(2)查找,替换(等长,不等长),插入(插串,文本块的插入);快移动(行块,列块移动),删除;(3)可正确存盘,取盘;(4)正确显示总行数。... 基本要求(1)具有图形菜单界面(2)查找,替换(等长,不等长),插入(插串,文本块的插入);快移动(行块,列块移动),删除;(3)可正确存盘,取盘;(4)正确显示总行数。 帮我回答的人 还会送100分的附加分的 直接发给我的 我才采纳啊 我只是 做下作业的 谢谢了 对于这些 我是一窍不通的 也可以 发给我 邮箱 注明名字 听老师说要写 10页纸左右 展开
 我来答
NorthSeal
2010-06-05 · TA获得超过121个赞
知道答主
回答量:180
采纳率:0%
帮助的人:134万
展开全部
如果是在DOS平台,那10页是不够的。
如果是在Win32平台,那可以用RichText控件来完成,那就简单多了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2010-06-05
展开全部
#include <windows.h>

#include "sample.h"

static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;

#define IDC_MAIN_TEXT 1001

BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;

hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{
LPSTR pszFileText;
pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
pszFileText[dwFileSize] = 0;
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE;
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}

BOOL SaveFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;

hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0)
{
LPSTR pszText;
pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}

BOOL DoFileOpenSave(HWND hwnd, BOOL bSave)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH];

ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;

ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "文本文件 (*.txt)\0*.txt\0所有文件 (*.*)\0*.*\0\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "txt";

if(bSave)
{
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;

if(GetSaveFileName(&ofn))
{
if(!SaveFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "保存文件失败.", "错误信息",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
else
{
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn))
{
if(!LoadFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "打开文件失败.", "错误信息",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
CreateWindow("EDIT", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |
ES_WANTRETURN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, (HMENU)IDC_MAIN_TEXT, g_hInst, NULL);

SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
break;
case WM_SIZE:
if(wParam != SIZE_MINIMIZED)
MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),
HIWORD(lParam), TRUE);
break;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CM_FILE_OPEN:
DoFileOpenSave(hwnd, FALSE);
break;
case CM_FILE_SAVEAS:
DoFileOpenSave(hwnd, TRUE);
break;
case CM_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case CM_ABOUT:
MessageBox (NULL, "一个Windows C 记事本程序" , "关于...", 0);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;

g_hInst = hInstance;

WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = "MAINMENU";
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "注册窗口失败", "错误信息",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}

hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"一个记事本程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
NULL, NULL, g_hInst, NULL);

if(hwnd == NULL)
{
MessageBox(0, "创建窗口失败", "错误信息",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
我只写到这里,可以存,取,
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式