首页 > 期刊发表知识库 > C++文本编辑器

C++文本编辑器

发布时间:

C++文本编辑器

Microsoft Visual C++ 0 简体中文企业版 都在用这个,很好。

不用自己设计了,伤脑细胞的,vc为你写了个编辑器了。创建一个单文档程序,继承ceditview即可在加入onopendocumentboolccpptexteditdoc::onopendocument(lpctstrlpszpathname){if(!cdocument::onopendocument(lpszpathname))returnfalse;cstdiofiletxtfile;pen(lpszpathname,cfile::moderead);if(_hfile==invalid_handle_value){afxmessagebox(text("文件无效"));}cstringstrread,strtemp;while(adstring(strtemp))strread+=strtemp;lose();reinterpret_cast(m_head())->setwindowtext(buffer());returntrue;}

编译器是把你的代码(高级语言)解释为CPU指令的一种程序。你说的这个文本编辑器应该是开发环境,编辑器就是帮助你写出正确语法的代码、设置工程属性的一个环境。

文本编辑器c语言

void main(){ data while(1) { scanf("%d",&data); //这里判断输入的data变量 }}外面写不同的处理函数

正常的printf表示把显示字符输出给终端,而sprintf把输出给一个字符串,即buf。这条语句执行完buf的内容就是"edit+文件名"。system函数的功能是调用shell命令,edit正是编辑命令。

不为答题,特为吐槽:这个项目拿c#java甚至python全日工作都得写至少一个星期吧。你还用c……

简易文本编辑器c语言

不会

北京科技大学的吧。。。

#include #include #include "h"#include "h"suct line{int charnum;char *base;};typedef suct line SequListElemType;#include "h"#define MAXLINES 1000int key;int cureditline=0;int curscrtopline=0;int cureditcol=0;int funckey;int editwinx=2;int editwiny=3;int editwinlines=20;int mainover=0;FILE *curfile;char filename[255]="xt";SequList *Document;char ascii(int k);prinoc(int startfileline,int startscrline);readdoc(FILE *fp);editline(int curline,int maxcolnum){char s[2000];setscrcolor(BLUE,YELLOW);scpy(s,Document->elem[curline]base);getsing(editwinx,editwiny curline-curscrtopline,s,maxcolnum);free(Document->elem[curline]base);Document->elem[curline]base=(char *)malloc(slen(s) 1);scpy(Document->elem[curline]base,s);}prinoc(int startfileline,int startscrline){int i;int j;cursor_hide();i=startscrline;j=startfileline;setscrcolor(BLUE,YELLOW);gotoxy(editwinx,editwiny startscrline);while(i<=editwinlines && ilength){clearscrline(editwinx,editwiny i,78);putsxy(editwinx,editwiny i ,Document->elem[j -1]base);}while(i<=editwinlines)clearscrline(editwinx,editwiny i ,78);cursor_show();}getline(FILE *fp,char *l){int i=0;while(!feof(fp))if((l[i ]=fgetc(fp))=='\n')break;l[i-1]='\0';}closedoc(FILE *fp){int i;fclose(fp);for(i=0;ilength;i )free(Document->elem[i]base);SequListDesoy(Document);}readdoc(FILE *fp){char *newline;char s[20000];int linenum=0;suct line curline;if(!fp) return;while(!feof(fp)){getline(fp,s);linenum ;newline=(char *)malloc(slen(s) 1);scpy(newline,s);base=newline;harnum=slen(newline);SequListInsert(Document,linenum,curline);}}char ascii(int k){char c;c=(k<<8)>>8;if(c>=32&&c<127)return c;elsereturn 0;}insertchar(char *s,char c,int pos){int i;for(i=slen(s) 1;i>pos;i--)s[i]=s[i-1];s[i]=c;}deletechar(char *s,int pos){int i;int j;j=slen(s);for(i=pos;i<=j;i )s[i]=s[i 1];}clearscrline(int x,int y,int num){int i;for(i=0;i0){cureditline--;gotoxy(editwinx,editwiny cureditline);editline(cureditline,78);}break;case KEYDown:if (cureditlinelength-1){cureditline ;gotoxy(editwinx,editwiny cureditline);editline(cureditline,78);}break;case KEYCl_y:deleteline(cureditline 1);if(Document->length==0)insertnewline(cureditline 1);if(cureditline>=Document->length)insertnewline(cureditline 1);prinoc(cureditline 1,cureditline-curscrtopline);gotoxy(editwinx,editwiny cureditline);editline(cureditline,78);break;case KEYLeft:case KEYRight:break;case KEYCl_s:break;case ESC:cursor_hide();dofunc(getmenuitem());break;case KEYAlt_x:mainover=1;break;default:gotoxy(editwinx,editwiny cureditline-curscrtopline);editline(cureditline,78);break;}}closedoc(curfile);setscrcolor(BLACK,WHITE);clrscr();cursor_show();}

文本编辑器c语言代码

北京科技大学的吧。。。

notepad++ ,notepad2,editplus,UE都可以 ,推荐notepad++,确实挺好用

不为答题,特为吐槽:这个项目拿c#java甚至python全日工作都得写至少一个星期吧。你还用c……

c语言实现文本编辑器

北京科技大学的吧。。。

我的C语言是自学的,懂一小点。虽然我没有你说的那种源代码,但我有记事本的源代码,你想看看吗?记事本(主程序)#include #include "h"static char g_szClassName[] = "MyWindowClass";static HINSTANCE g_hInst = NULL;#define IDC_MAIN_TEXT 1001BOOL 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; lStructSize = sizeof(ofn); hwndOwner = hwnd; lpstrFilter = "文本文件 (*xt)\0*xt\0所有文件 (**)\0**\0\0"; lpstrFile = szFileName; MaxFile = MAX_PATH; lpstrDefExt = "txt"; if(bSave) { 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 { 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, "欢迎使用jiyingjun的源代码" , "关于", 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; WndCbSize = sizeof(WNDCLASSEX); WndCstyle = 0; WndClpfnWndProc = WndProc; WndCbClsExtra = 0; WndCbWndExtra = 0; WndChInstance = g_hInst; WndChIcon = LoadIcon(NULL, IDI_APPLICATION); WndChCursor = LoadCursor(NULL, IDC_ARROW); WndChbrBackground = (HBRUSH)(COLOR_WINDOW+1); WndClpszMenuName = "MAINMENU"; WndClpszClassName = g_szClassName; WndChIconSm = 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 MwParam;}记事本(资源文件)#include "h"A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "ico"MAINMENU MENU { POPUP "文件(&F)" { MENUITEM "打开(&O)", CM_FILE_OPEN MENUITEM "另存为(&S)", CM_FILE_SAVEAS MENUITEM SEPARATOR MENUITEM "关闭", CM_FILE_EXIT } POPUP "帮助(&H)" { MENUITEM "关于(&A)", CM_ABOUT }}记事本(头文件)#define CM_FILE_SAVEAS 9072#define CM_FILE_EXIT 9071#define CM_FILE_OPEN 9070#define CM_ABOUT 9069

  • 索引序列
  • C++文本编辑器
  • 文本编辑器c语言
  • 简易文本编辑器c语言
  • 文本编辑器c语言代码
  • c语言实现文本编辑器
  • 返回顶部