记事本代码
c语言的记事本源代码
if((fp=fopen("tongxunlu.txt","a+"))==NULL)
{ printf(" 无法打开文件~~~\n");
}
while(!feof(fp))
{ i++;
p2=p1;
p1=(link *)malloc(LEN);
printf("Thank your use\n");
else
if(identify=='n'||identify=='N')
exit(0);
else
printf(" 请输入(Y/N):");
{ printf(" 无法打开文件~~~\n");
exit(0);
} //打开文件,并将文件中内容复制到链表中,若文件中无记录,则链表头指针为空
char identify;
// char fullname[10];
link *head,*p,*p1,*p2,*p3;
int choose;
char absorb;
int i;
head=NULL;
welcome();
head=NULL;
p2->next=NULL;
fclose(fp);
if(head==NULL)
p1=p2=(link *)malloc(LEN);
fread(p1,LEN,1,fp);
head=p1;
#include<stdio.h>
#include<stdlib.h>
C语言记事本代码
C语言记事本代码#include<stdio.h>#include<malloc.h>#include<string.h>#include<stdlib.h>#include<ctype.h>#define NULL 0#define MAX 100typedef struct lnode{char date[MAX]; //存放数据struct lnode * prior ; //前驱struct lnode * next ; //后继int number ; //记录一个节点的字符数~如果是头节点就记录他的节点个数int quese ; //记录节点在链表中的位置}lnodetype;lnodetype * l ; //设置两个全局变量,分别是头节点指针和尾节点指针lnodetype * end ;//**********这个函数是用来初始化的**********//int iniatelist (lnodetype ** l , lnodetype ** end){(*l) = (lnodetype *)malloc (sizeof (lnodetype) ) ;if ( (*l) == NULL ){printf ("没有只够的内存空间~程序即将退出~");return 0 ;}(*l)->prior =(*l)->next = NULL ; //这是双链表(*l)->number = (*l)->quese = 0;(*end) = (*l) ;printf ("程序初始化完毕~");return 0;}//**********这个函数是用来建立节点,并且插入元素的**********// int link(lnodetype ** l, lnodetype ** end){lnodetype *s ;s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;if ( s == NULL ){printf ("内存空间不够,程序即将退出~") ;return 0 ;}(*end)->next = s ;s->prior = (*end) ;(*end) = (*end)->next ;(*l)->number++ ; //增加一个节点,头节点的number就加1s->quese = (*l)->number ; //这个是记录节点在链表中的位置printf ("%d行", s->quese ) ; //这个是节点在整个链表中的位置gets(s->date) ;s -> number = strlen(s->date) ;return 0 ;}//**********这个是打印链表的函数**********//int prin (lnodetype ** l, lnodetype ** end){lnodetype * p ;int i ;int j = 0;int couter = (*l)->number ;p = (*l)->next ;for (i=0; i < couter; i++){printf ( "%d行" , i+1 ) ;j = 0;while ( ( p->date[j]>='a' && p->date[j]<='z') || (p->date[j]>='A' && p->date[j]<='z') ||p->date[j]>='0' && p->date[j]<='9'){printf ( "%c" , p->date[j] ) ;j++ ;}printf ("n") ;p = p->next ;}return 0 ;}//*********这个查找和编辑相应行的函数**********//int search (lnodetype ** l, lnodetype ** end ){int number ;scanf ("%d" , &number) ;int i ;lnodetype * p ;p = (*l)->next ;for ( i=0; i<number-1; i++ )p = p->next ;printf ("%d行" , number ) ;gets (p->date) ;return 0 ;}//**********这个是在文本文件里搜索字符串的函数**********// int searchstr(lnodetype ** l , lnodetype ** end){char ptr[100] ;int arrycouter ;int mystrcmp( char *, char * , int ) ;printf ( "ok!现在输入你查找的字符串~" ) ;scanf ( "%s" , ptr ) ;arrycouter = strlen (ptr) ;lnodetype * s ;s = (*l)->next ;char * p ;int i = 1 ;int couter = 0 ;int number = (*l)->number ;p = (char *)s->date ;while ( i && number ){// i=1是,证明没有找到,向第二个节点继续寻找while ( i && ( ( (*p >= 'a') && (*p <= 'z') ) ||( (*p >= 'A') && (*p <= 'Z') ) ) ){i = mystrcmp ( p , ptr , arrycouter );if ( i == 1 ){printf ("字符串已经在第%d行,第%d个字符开始,",s->quese, couter+1 );i = 0 ;}else{p++ ;couter++;i = 1 ;}}s = s->next ;p = (char *)s->date ;number -- ;}if ( i == 1 )printf ("字符串在本文档中不存在~");return 0 ;}//**********(1)这个函数是用来实现退出不保存功能的**********// int exitunsave(lnodetype ** l, lnodetype ** end){lnodetype * s ;while( (*l) != (*end) ){ //如果不保存的话,最好是把节点的空间都释放,节省空间s = (*end) ;(*end) = (*end)->prior ;free( s ) ;}return 0 ;}//**********(2)这个函数是用来实现退出但保存功能的**********// int quitandsave( lnodetype ** l , lnodetype ** end ){FILE * fp ;char ch ;char filename[20] ;lnodetype * p;int i ;int j ;int couter = (*l)->number ;p = (*l)->next ;printf ("请输入文件名:") ;scanf ("%s" , filename ) ;if ( (fp = fopen( filename , "w" )) == NULL ){printf ("文件不能打开~n");return 0 ;}for ( i=0; i<couter; i++ ){ //有几个节点就进行多少次的存贮ch = p->date[0] ;j = 1 ;while (ch != '\0'){fputc (ch , fp) ;ch = p->date[j] ;j++ ;}p = p->next ;fputc ( '#' , fp ) ; //注意在每个节点的后面加上结束的符号}fputc ( '@' , fp ) ; //整个文件关闭的标志fclose ( fp ) ; //注意关闭文件,return 0 ;}//**********由于库函数比较字符串提供的功能不满足要求,故自己写了一个**********/int mystrcmp( char * p ,char * sour ,int number ){while ( number && (*p) == (*sour) &&( ( (*p >= 'a') && (*p <= 'z') ) || ( (*p >= 'A')&& (*p <= 'Z') ) )){p++ ;sour++ ;number-- ;}if ( number == 0 )return 1 ;elsereturn 0 ;}//**********这个函数是用来实现统计字符串功能的**********//int coutword(lnodetype ** l , lnodetype ** end){ //考虑到只统计一行的单词没有意义,故统计整个文本int yes = 1 ; //这个是进入单词的标志int no = 0 ; //在单词外面的时候的标志int i , j ,inaword ,count = 0 ;inaword = no ;lnodetype * s = (*l)->next ;for (j=0; j<(*l)->number; j++){for ( i=0; (s->date[i]>='a' && s->date[i]<='z') || (s->date[i]>='A' && s->date[i]<='z') ||(s->date[i]>='0' && s->date[i]<='9' ) ||(s->date[i]==' '); i++ ){if ( s->date[i] == ' ' )inaword = no ;elseif ( inaword == no ){inaword = yes ;count++ ; //计算单词}}s = s->next ;inaword = 0 ; //注意这里,把标志置为0了~}printf ( "n文本一共有 %d 行" , (*l)->number ) ;printf ("n此文本一共有 %d 个单词!" , count ) ;return count ;}//**********这个函数是用来实现计算文本行数功能的**********// int linecouter(lnodetype ** l , lnodetype ** end ){int couter ;couter = (*l)->number ;return couter ;}//**********这个函数是整和一上所有功能的菜单函数**********// int editmenu(lnodetype ** l , lnodetype ** end ){char choice ;char * p = "cls" ;int i = 1 ; //这两个变量是用来控制循环的int j= 1 ;system (p) ;prin (&(*l) , &(*end)) ;while (j){printf ("*********************************** e: 编辑相应行*************************************n") ;printf ("*********************************** s: 搜索字符串*************************************n") ;printf ("*********************************** t: 统计单词个数***********************************n") ;printf ("*********************************** q: 退出编辑***************************************n") ;scanf("%c",&choice);scanf("%c" , &choice) ; //,,,,莫名其妙的问题,非要两个请求输入语句才肯停下来~switch (choice){case 'e' : {i = 1 ;while (i){search( &(*l) , &(*end) );system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 继续编辑 0 结束编辑n") ;scanf ("%d" , &i) ;}}break;case 's' : {i = 1 ;while (i){searchstr( &(*l) , &(*end) );getchar();getchar();system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 继续搜索 0 结束搜索n") ; scanf ("%d" , &i) ;}}break;case 't' : {coutword ( &(*l) , &(*end) ) ;getchar() ;}break;default : return 0 ;}system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 回到编辑菜单 0 结束编辑n") ; scanf ("%d" , &j) ;if (j == 1)system (p) ;elsereturn 0 ;}return 0 ;}//**********实现第一个模块:新建空白文档**********// int newtext( lnodetype ** l ,lnodetype ** end ) {printf ( "新文本文件:n" ) ;int i = 1 ;char judstr[MAX] ;lnodetype * temp ;char jud ;char * p = "cls" ;while ( 1 ){link( &(*l) , &(*end) ) ;jud = (*end)->date[0] ;if ( jud == '5' ){ //输入‘5’结束一切temp = (*end) ;(*end) = (*end)->prior ;free (temp) ;while (1){printf ( "******************************* out :退出不保存****************************n") ;printf ( "******************************* edit :编辑信息*****************************n") ;printf ( "******************************* quit :退出而不存盘**************************n") ;printf ( "******************************* qas :退出且存盘****************************n") ;printf ( "******************************* con :继续输入~*****************************n") ;gets(judstr) ;if ( !strcmp(judstr , "out") ){exitunsave( &(*l) , &(*end) ) ;return 0 ;}elseif ( !strcmp(judstr , "qas") ){quitandsave( &(*l) , &(*end) ) ;return 0 ;}elseif ( !strcmp(judstr , "edit") ){editmenu (l , end) ;return 0;}system (p) ;}return 0 ;}}return 0 ;}//**********这个是装入文件的函数**********// int loadtaxt( char * filename ){FILE * fp ;lnodetype * l ;char ch ;int i = 0 ;char * p = "cls" ;char judstr[MAX] ;lnodetype * head ;lnodetype * end ;iniatelist ( &head , &end) ;l = end = head ;if ( (fp = fopen( filename, "r+")) == NULL ){ printf ("文件不能打开~n") ;return 0 ;}ch = fgetc ( fp ) ;while ( ch != '@' ){lnodetype *s ;s = (lnodetype *)malloc ( sizeof (lnodetype) ) ; if ( s == NULL ){printf ("内存空间不够,程序即将退出~") ;return 0 ;}end->next = s ;s->prior = end ;end = end->next ;l->number++ ;s->quese = l->number ;printf ("%d行", s->quese ) ;while ( ch != '#'){s->date[i] = ch ;ch = fgetc (fp) ;i++ ;}i = 0;while ( (end->date[i]>='a' && end->date[i]<='z') ||(end->date[i]>='A' && end->date[i]<='z') ||(end->date[i]>='0' && end->date[i]<='9' ) ||(end->date[i]==' ') ){printf ( "%c" , end->date[i] ) ;i++ ;}end->date[i] = '\0' ; //注意在节点的最好加上这个,以让退出保存功能函数知道此节点已结束printf ( "n" ) ;i = 0;ch = fgetc ( fp ) ;}fclose (fp) ;printf ("n文件成功装入~n") ;while (1){printf ( "******************************* out :退出不保存****************************n") ;printf ( "******************************* edit :编辑信息*****************************n") ;printf ( "******************************* qas :退出且存盘****************************n") ;printf ( "******************************* con :继续输入~*****************************n") ;scanf("%s",judstr);if ( !strcmp(judstr , "out") ){exitunsave( &l , &end ) ;return 0 ;}elseif ( !strcmp(judstr , "qas") ){quitandsave( &l , &end ) ;return 0 ;}elseif ( !strcmp(judstr , "edit") ){editmenu (&l , &end) ;return 0 ;}system (p) ;}return 0 ;}//**********主函数**********// void main ( void ){//iniatelist (&l , &end) ;//newtext(&l , &end) ;char filename[MAX] ;scanf ( "%s" , filename ) ; loadtaxt( filename ) ;}很不容易做的程序~~~通过编译。
记事本(代码)
char t; //选择是否继续输入
flag:
printf("请输入第%d个学生信息\n",a+1);
printf("学号:");
scanf("%d",>[a].xuehao);
printf("姓名:");
scanf("%s",>[a].name);
for(int k=i;k<a;k++)
if(gt[i].xuehao>gt[k].xuehao)
{
gts=gt[i];
gt[i]=gt[k];
gt[k]=gts;
}
{
for(l=0;l<a;l++)
{
gt[l]=gt[l+1];
}
}
}
if(x==2)
{
printf("请输入该学生的姓名\n");
scanf("%s",&q);
for (i=0;i<a;i++)
{
int l; //用于for循环
int i; //用于表示删除编号
int x; //选择
char q[10]; //被删除的姓名
int cx; //被删除的学号
printf("1.按学号删除\n");
char q[10]; //被修改的姓名
int cx; //被修改的学号
printf("1.按学号修改\n");
printf("2.按姓名修改\n");
记事本源代码
记事本源代码先上效果图。
这个记事本操作简便,功能强⼤,在记事本的基础上添加了将内容发送短信和发送邮件的功能。
这个应⽤也已经功过了微软的认证。
115⽹盘⾥⾯的是最新的。
QQ:29992379下载地址:Memo.xap实体类1: public class Note2: {3: public string NoteGuid { get; set; }4: public string NoteContent { get; set; }5: public string NoteTime { get; set; }6: }在独⽴存储中⽣成存储结构。
1: if (!IsolatedStorageSettings.ApplicationSettings.Contains("Notes"))2: {3: List<Note> notes = new List<Note>();4: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;5: IsolatedStorageSettings.ApplicationSettings.Save();6:7: }绑定⽂章的列表,并按编号倒排序。
1: public partial class MainPage : PhoneApplicationPage2: {3: // 构造函数4: public MainPage()5: {6: InitializeComponent();7: BingData();8: }9: List<Note> notes = new List<Note>();10: private void BingData()11: {12: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;13:14: var descInfo = from i in notes orderby i.NoteTime descending select i;//linq对⽂章列表的排序15:16: MainListBox.ItemsSource = descInfo;17: }18:19: private void ApplicationBarIconButton_Click(object sender, EventArgs e)20: {21: NavigationService.Navigate(new Uri("/Add.xaml", UriKind.RelativeOrAbsolute));22: }23:24: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)25: {26: e.Cancel = true;27: App.Quit();28: base.OnBackKeyPress(e);29: }30:31: private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)32: {33: NavigationService.Navigate(new Uri("/About.xaml", UriKind.RelativeOrAbsolute));34: }35:36: private void StackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)37: {38: string noteguid = ((TextBlock)(((StackPanel)sender).Children.First())).Tag.ToString();39: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid, UriKind.Relative));40: }41: }⽂章显⽰的页⾯以及⼀系列功能1: public partial class DetailsPage : PhoneApplicationPage2: {3: // 构造函数4: public DetailsPage()5: {6: InitializeComponent();7: }8: string noteguid;9: protected override void OnNavigatedTo(NavigationEventArgs e)10: {11: BingData();12: noteguid = NavigationContext.QueryString["noteguid"].ToString();13: foreach (var item in notes)14: {15: if (item.NoteGuid==noteguid)16: {17: ContentText.Text = item.NoteContent;18: TimeText.Text = item.NoteTime;19: return;20: }21: }22: }23:24: List<Note> notes = new List<Note>();25: private void BingData()26: {27: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;28: }29:30: private void Edit_Click(object sender, EventArgs e)31: {32: NavigationService.Navigate(new Uri("/Edit.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 33: }34:35: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)36: {37: e.Cancel = true;38: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));39: base.OnBackKeyPress(e);40: }41:42: private void Del_Click(object sender, EventArgs e)43: {44: for (int i = 0; i < notes.Count; i++)45: {46: if (notes[i].NoteGuid==noteguid)47: {48: notes.RemoveAt(i);49: }50: }51: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;52: IsolatedStorageSettings.ApplicationSettings.Save();53: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));54: }55:56: private void Email_Click(object sender, EventArgs e)57: {58: EmailComposeTask email = new EmailComposeTask();59: email.Body = ContentText.Text.ToString();60: email.Show();61: }62:63: private void Message_Click(object sender, EventArgs e)64: {65: SmsComposeTask sms = new SmsComposeTask();66: sms.Body = ContentText.Text.ToString();67: sms.Show();68: }69: }⽂章的编辑页⾯代码1: public partial class Edit : PhoneApplicationPage2: {3: public Edit()4: {5: InitializeComponent();6: }7:8: private void ApplicationBarIconButton_Click(object sender, EventArgs e)9: {10: foreach (var item in notes)11: {12: if (item.NoteGuid == noteguid)13: {14: item.NoteContent = ContentText.Text;15: item.NoteTime=TimeText.Text;16: }17: }18:19: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;20: IsolatedStorageSettings.ApplicationSettings.Save();21: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 22: }23: string noteguid;24: protected override void OnNavigatedTo(NavigationEventArgs e)25: {26: BingData();27: noteguid = NavigationContext.QueryString["noteguid"].ToString();28: foreach (var item in notes)29: {30: if (item.NoteGuid==noteguid)31: {32: ContentText.Text = item.NoteContent;33: TimeText.Text = item.NoteTime;34: return;35: }36: }37: }38:39: List<Note> notes = new List<Note>();40: private void BingData()41: {42: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;43: }44: }。
纯C++代码写的记事本
#include "windows.h"#include "wyyapi.h"#include "inttypes.h"#include <string>#include "stdio.h"LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);HMENU wyymenu=NULL;int i=0;BOOL CreateTopMenu(){wyymenu=CreateMenu();HMENU wyypopup=CreateMenu();HMENU wangpopup=CreateMenu();AppendMenu(wyypopup,MF_STRING,IDM_OPEN,"&打开");AppendMenu(wyypopup,MF_STRING,IDM_EXIT,"&退出");AppendMenu(wangpopup,MF_STRING,IDM_NEW,"&刷新");AppendMenu(wangpopup,MF_STRING,IDM_SAVE,"&保存");AppendMenu(wyymenu,MF_POPUP,(intptr_t)wyypopup,"&王云勇");AppendMenu(wyymenu,MF_POPUP,(intptr_t)wangpopup,"&王云");return true;}int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){char wclassname[]="wyy";WNDCLASSEX wc;wc.cbSize=sizeof(WNDCLASSEX);wc.style=CS_HREDRAW|CS_VREDRAW|CS_NOCLOSE;wc.lpfnWndProc=MainWndProc;wc.cbClsExtra=0;wc.cbWndExtra=0;wc.hInstance=hInstance;wc.hIcon=LoadIcon(hInstance,(LPSTR)IDI_MAIN);wc.hCursor=LoadCursor(NULL,IDC_ARROW);wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wc.lpszMenuName=NULL;wc.lpszClassName=wclassname;wc.hIconSm=LoadIcon(hInstance,(LPSTR)IDI_MAIN);RegisterClassEx(&wc);CreateTopMenu();HWND hwnd=CreateWindowEx(WS_EX_LEFT,wclassname,"王云勇首富",WS_CAPTION,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,wyymenu,hInstance,NULL);if(hwnd==NULL){MessageBox(NULL,"窗口出错","error",MB_OK);return -1;}ShowWindow(hwnd,nCmdShow);UpdateWindow(hwnd);MSG msg;while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){FILE *wyywy;static int i=0;HDC hdc;PAINTSTRUCT ps;static std::string str;static char *sf;static wchar_t *sfwyy;OPENFILENAME ofn;static char szFile[256];static char szFileTitle[256];memset(&ofn,0,sizeof(ofn));ofn.lStructSize=sizeof(ofn);ofn.hwndOwner=hwnd;ofn.lpstrFilter="保存的文件(*.txt)\0*.txt\0\0";ofn.nFilterIndex=1;ofn.lpstrFile=szFile;ofn.nMaxFile=sizeof(szFile);ofn.lpstrFileTitle=szFileTitle;ofn.nMaxFileTitle=sizeof(szFileTitle);ofn.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER;switch(message){case WM_COMMAND:switch(LOWORD(wParam))MessageBox(hwnd,TEXT("王云勇"),TEXT("首富"),MB_OK); break;case IDM_EXIT:exit(0);break;case IDM_NEW:{str.clear();i=i+8;InvalidateRect(hwnd,NULL,1);}break;case IDM_SAVE:{if(GetSaveFileName(&ofn)){sf=ofn.lpstrFile;strcat(sf,".txt");size_t len=strlen(sf)+1;size_t con=0;sfwyy=(wchar_t*)malloc(len*sizeof(wchar_t));mbstowcs_s(&con,sfwyy,len,sf,_TRUNCATE);if((wyywy=_wfopen(sfwyy,L"wt+"))==NULL){MessageBox(hwnd,TEXT("出错"),TEXT("首富"),MB_OK); MessageBox(hwnd,TEXT("返回"),TEXT("首富"),MB_OK); break;}_wsetlocale(0,L"chs");if(fwprintf(wyywy,L"%s",str)>0){MessageBox(hwnd,TEXT("保存成功"),TEXT("首富"),MB_OK);} if(fclose(wyywy)==0){MessageBox(hwnd,TEXT("王云勇成功"),TEXT("首富"),MB_OK);} }}default:break;}break;case WM_PAINT:{hdc=BeginPaint(hwnd,&ps);if(i==0){TextOut(hdc,0,0,str.c_str(),str.length());}EndPaint(hwnd,&ps);}break;{i=0;str=str+char(wParam);InvalidateRect(hwnd,NULL,0);return 0;}case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd,message,wParam,lParam); }。
记事本代码
记事本代码#include<iostream.h>#include<string.h>#include<ctype.h> //为了以下使用isdigit(string)函数作铺垫typedef struct node{char a[100]; //每行100字符node * next; //关于此处next的作用还不清楚,但不可去掉}node;class notepad{public:notepad(){i=1;line=0;}~notepad(){}void operator_interface();void input();void ct_input();void delete1();void copy();void paste();void open();void save();char * find();void print();char store[100]; //储存需复制内容private:char * ptr_array[100]; //指针数组,记录100行行指针int linelen[100]; //最大100行int line; //当前总行数char d[30]; //记录操作数据int k,l; //记录当前查找行ilint i; //文档录入初始标记};void notepad::operator_interface(){cout<<"********************************************************"<<en dl;cout<<"***0.继续录入文档"<<endl;cout<<"***1.输入文档内容"<<endl;cout<<"***2.删除某些内容"<<endl;cout<<"***3.复制某些内容"<<endl;cout<<"***4.粘贴某些内容"<<endl;cout<<"***5.打开文档内容"<<endl;cout<<"***6.是否保存文档"<<endl;cout<<"***7.获取操作帮助"<<endl;cout<<"***8.我要结束操作"<<endl;cout<<"********************************************************"<<en dl;}void notepad::input(){-99"<<endl; cout<<"输入总行数,格式:01char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){line=(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl; }void notepad::ct_input(){if(line!=0){int i=line+1;cout<<"输入要录入的总行数,格式:01-99"<<endl;char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){ line=line+(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl;}else cout<<"当前文档并无内容,请先输入1录入文档"<<endl; }void notepad::print(){cout<<endl<<endl;int j=1;cout<<"当前文档内容为:"<<endl;while(j<=line){cout<<"第"<<j<<"行 ";char *q=ptr_array[j];while(*q!='\0'){cout<<*q;q++;}cout<<endl;j++;}cout<<endl;}char * notepad::find(){ //暂未解决跨行查找问题k=1;cin>>d;l=strlen(d);char *n=d;int c=1;char *m=ptr_array[k];while(k<=line){if(*m=='\0'){k=k+1;if(k<=line)m=ptr_array[k];}if(*m!='\0'&&*m!=*n)m++;while(*n!='\0'&&*m!='\0'&&*m==*n){ m=m+1;n=n+1;c=c+1;}if(*n=='\0'){return m-c+1;}else {n=d;c=1;}}return NULL;}void notepad::delete1(){char * dp1;char * dp2;cout<<"请输入要删除的文本前几位字符,注意区分"<<endl;dp1=find();int l1=k;cout<<"请输入要删除的文本末几位字符,注意区分"<<endl;dp2=find();int l2=k;if(dp1==NULL||dp2==NULL||l1>l2)cout<<"输入错误"<<endl;else{dp2=dp2+l;if(l1==l2){while(*dp2!='\0'){*dp1=*dp2;dp1++;dp2++;}*dp1='\0';linelen[l1]=strlen(ptr_array[l1]);}else {if(l1+1<l2){for(intt1=l1+1,t2=l2;t2<=line;t1++,t2++)ptr_array[t1]=ptr_array[t2]; line=line-l2+l1+1;l2=l1+1;}*dp1='\0';char *dp21=ptr_array[l2];while(*(dp2-1)!='\0'){*dp21=*dp2;dp21++;dp2++;}linelen[l1]=strlen(ptr_array[l1]);linelen[l2]=strlen(ptr_array[l2]);}if(linelen[l1]==0){for(int v=l1;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}if(linelen[l2]==0){for(int v=l2;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}}}void notepad::copy(){char * cp1;char * cp2;cout<<"请输入要复制的文本前几位字符,注意区分"<<endl; cp1=find();int l1=k;cout<<"请输入要复制的文本末几位字符,注意区分"<<endl; cp2=find();int l2=k;char *pt=store;if(cp1!=NULL&&cp2!=NULL&&l1<=l2){cp2=cp2+l;while(cp1!=cp2){if(*cp1=='\0'){l1++;cp1=ptr_array[l1];}else {*pt=*cp1;pt++;cp1++;}}*pt='\0';}else cout<<"输入错误"<<endl; }void notepad::paste(){cout<<"请输入要粘贴位置的前几位字符(在首字符后粘贴)"<<endl; char *pat=find();if(pat!=NULL){int choice2;cout<<"请选择要粘贴内容:1/从内存中0/我自己输入"<<endl; cin>>choice2;if(!choice2)cin>>store;char *ppt=store;for(char *pat1=pat;*(pat1+1)!='\0';pat1++); //定位至末尾int pl=strlen(store);*(pat1+pl+1)='\0';while(pat1!=pat){ //移位*(pat1+pl)=*pat1;pat1--;}pat++;for(int u=1;u<=pl;u++){*pat=*ppt;ppt++;pat++;}linelen[k]=linelen[k]+pl;}else cout<<"输入错误"<<endl;}void notepad::open(){print();}void notepad::save(){cout<<"是否保存文件,1/是0/否"<<endl;char g[10];int choice1;cin>>g;char *choi=g;if(*(choi+1)=='\0'&&isdigit(*choi)){ choice1=*choi-'0';if(choice1==1)cout<<"文件已保存"<<endl; else if(choice1==0){for(int w=1;w<=line;w++){ //相当于析构函数的作用ptr_array[w]=NULL;linelen[w]=0;}line=0;}else cout<<"输入错误"<<endl;}else cout<<"输入错误"<<endl; }void main(){cout<<"欢迎使用本程序,您可以在要输入文档内容时通过切换输入法实现输入汉字,byhk"<<endl;notepad b;b.operator_interface();char f[10];int choice;cin>>f;char *choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)){ //错误输入处理机制choice=*choic-'0';}else choice=9;while(choice!=8){switch(choice){case 0:b.ct_input();break;case 1:b.input();break;case 2:b.delete1();b.print();break;case 3:{b.copy();cout<<endl;char *p_t=b.store;int fzcd=strlen(b.store);cout<<"你所要复制的内容长度为"<<endl<<fzcd<<endl; cout<<"你所要复制的内容为"<<endl;while(*p_t!='\0'){cout<<*p_t;p_t++;}cout<<endl;}break;case 4:b.paste();b.print();break;case 5:b.open();break;case 6:b.save();break;case 7:b.operator_interface();break;case 8:break;default:break;}if(choice==9||(choice>=0&&choice<=7)){ //输入错误时的操作及输入正确时 //的继续操作判断if(choice==9)cout<<"你输入的操作有误,请重新输入,输入 7 获取操作帮助"<<endl;else cout<<"继续你的操作,输入 7 获取操作帮助"<<endl;cin>>f;choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)) //错误输入处理机制choice=*choic-'0';else choice=9;}}cout<<"感谢您的使用"<<endl; }。
记事本程序源代码汇总
import java.awt.event.*;import java.awt.*;import java.io.*;import ng.String;class jsb implements ActionListener{Dialog bb;String strt;int i;FileDialog fd;File file;public Frame f;public TextArea p1;public MenuBar menubar;public Menu menu1,menu2,menu3;public MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10; jsb(String s{ i=0;f=new Frame(s;p1=new TextArea("";f.setSize(500,500;f.setBackground(Color.white;f.setVisible(true;menubar=new MenuBar(;menu1=new Menu("文件";menu2=new Menu("编辑";menu3=new Menu("帮助";item1=new MenuItem("新建";item2=new MenuItem("打开";item3=new MenuItem("保存";item4=new MenuItem("另存为";item5=new MenuItem("退出";item6=new MenuItem("全选";item7=new MenuItem("复制";item8=new MenuItem("剪切";item9=new MenuItem("粘贴";item10=new MenuItem("关于";f.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e {f.setVisible(false;System.exit(0;}};menu1.add(item1;menu1.add(item2;menu1.add(item3;menu1.add(item4;menu1.add(item5;menu2.add(item6;menu2.add(item7;menu2.add(item8;menu2.add(item9;menu3.add(item10;menubar.add(menu1;menubar.add(menu2;menubar.add(menu3;f.setMenuBar(menubar;item1.addActionListener(this;item2.addActionListener(this;item3.addActionListener(this;item4.addActionListener(this;item5.addActionListener(this;item6.addActionListener(this;item7.addActionListener(this;item8.addActionListener(this;item9.addActionListener(this;item10.addActionListener(this;f.setLayout(new GridLayout(1,1;f.add(p1;f.pack(;}public void actionPerformed(ActionEvent e { String ss;ss=p1.getText(.trim(;if (e.getSource(==item5{if (i==0 &&(ss.length(!=0{bc(;}else{System.exit(0;}}if (e.getSource(==item1{if (i==0&&(ss.length(!=0{bc(;}else{p1.setText("";i=0;f.setTitle("文件对话框"; } }if (e.getSource(==item2{fd=new FileDialog(f,"打开文件",0;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"文件对话框"; FileReader fr=new FileReader(file; BufferedReader br=new BufferedReader(fr; String line = null;String view = "";while((line=br.readLine(!=null{view += line+"\n";}p1.setText(view;br.close(;fr.close(;}catch(IOException expIn{}}if (e.getSource(==item3{if (i==0{bc(;}else{try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本";FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{i=0;}}}if (e.getSource(==item4{bc(;}if (e.getSource(==item10{bb=new Dialog(f,"关于";Label l1=new Label("本记事本的完成感谢老师和同学的帮助!!"; bb.add(l1; bb.setSize(250,150;bb.setBackground(Color.white;bb.show(;bb.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e{bb.setVisible(false;bb.dispose(;}};}if (e.getSource(==item6{p1.setSelectionStart(0;p1.setSelectionEnd(p1.getText(.length(; }if (e.getSource(==item7{try{String str=p1.getSelectedText(;if(str.length(!=0{strt=str;}}catch(Exception ex{}}if (e.getSource(==item8{try{String str=p1.getSelectedText(;if(str.length(!=0{p1.replaceRange("",p1.getSelectionStart(,p1.getSelectionEnd(; } }catch(Exception ex{}}if (e.getSource(==item9{if(strt.length(>0{p1.insert(strt,p1.getCaretPosition(;}}}public void bc({fd=new FileDialog(f,"保存文件",1;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本"; FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{}} } public class EX0101 { public static void main(String args[] {jsb dd=new jsb("我的记事本";} }。
使用Windows自带的记事本编写简单代码
使用Windows自带的记事本编写简单代码在如今数字化的时代,编程不再是专业程序员的专属技能,普通人也可以通过简单的工具和基础的知识来体验编程的乐趣。
Windows 自带的记事本就是这样一个容易上手的工具,它虽然看似简单,但却能帮助我们编写一些简单的代码。
首先,让我们来了解一下记事本。
记事本是 Windows 操作系统中一个基本的文本编辑工具,它没有复杂的功能和花哨的界面,只有纯粹的文字编辑区域。
但这恰恰为我们编写代码提供了一个干净、简洁的环境。
当我们决定使用记事本编写代码时,第一步就是打开它。
在Windows 系统中,您可以通过点击“开始”菜单,然后在搜索框中输入“记事本”来找到并打开它。
或者,您也可以按下快捷键“Windows +R”,在弹出的“运行”对话框中输入“notepad”并回车。
接下来,让我们从一个简单的 HTML 代码开始入手。
HTML(超文本标记语言)是用于创建网页的基础语言。
以下是一个简单的 HTML代码示例,用于创建一个包含标题和段落的网页:```html<!DOCTYPE html><html><head><title>我的第一个网页</title></head><body><h1>这是一个标题</h1><p>这是一个段落。
</p></body></html>```在记事本中输入上述代码后,点击“文件”菜单,选择“另存为”。
在“文件名”框中,输入“my_first_webpagehtml”(注意,一定要加上“html”扩展名,否则浏览器无法正确识别它为 HTML 文件),然后选择保存类型为“所有文件”,最后选择一个您想要保存的位置,点击“保存”。
保存完成后,找到您保存的文件,双击它,它应该会在您的默认浏览器中打开,显示出您刚刚编写的网页内容,包含一个标题和一个段落。
除了 HTML,我们还可以使用记事本编写 Python 代码。
记事本源代码
import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.datatransfer.*;class MyMenuBar extends MenuBar{public MyMenuBar(Frame parent){parent.setMenuBar(this);}public void addMenus(String [] menus){for(int i=0;i<menus.length;i++)add(new Menu(menus[i]));}public void addMenuItems(int menuNumber,String[] items){for(int i=0;i<items.length;i++){if(items[i]!=null)getMenu(menuNumber).add(new MenuItem(items[i]));else getMenu(menuNumber).addSeparator();}}public void addActionListener(ActionListener al){for(int i=0;i<getMenuCount();i++)for(int j=0;j<getMenu(i).getItemCount();j++)getMenu(i).getItem(j).addActionListener(al);}}class MyFile{private FileDialog fDlg;public MyFile(Frame parent){fDlg=new FileDialog(parent,"",FileDialog.LOAD);}private String getPath(){return fDlg.getDirectory()+"\\"+fDlg.getFile();}public String getData() throws IOException{fDlg.setTitle("打开");fDlg.setMode(FileDialog.LOAD);fDlg.setV isible(true);BufferedReader br=new BufferedReader(new FileReader(getPath()));StringBuffer sb=new StringBuffer();String aline;while((aline=br.readLine())!=null)sb.append(aline+'\n');br.close();return sb.toString();}public void setData(String data) throws IOException{fDlg.setTitle("保存");fDlg.setMode(FileDialog.SA VE);fDlg.setV isible(true);BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));bw.write(data);bw.close();}}class MyClipboard{private Clipboard cb;public MyClipboard(){cb=Toolkit.getDefaultToolkit().getSystemClipboard();}public void setData(String data){cb.setContents(new StringSelection(data),null);}public String getData(){Transferable content=cb.getContents(null);try{return (String) content.getTransferData(DataFlavor.stringFlavor);//DataFlavor.stringFlavor会将剪贴板中的字符串转换成Unicode码形式的String 对象。
记事本源代码
//记事本源代码package jishiben;import java.awt.*;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.event.*;import java.io.*;import java.util.Calendar;import jishiben.FWindow.StyleDialog;public class FristWindow {public static void main(String[] args) {// TODO Auto-generated method stubnew FWindow("记事本");}}class FWindow extends JFrame implements ActionListener,WindowListener,ItemListener { public static Frame frame;JMenuBar menuBar;JPopupMenu menu;//用户在菜单栏上选择项时显示的菜单JMenu menu1,menu2,menu3,menu4,menu5;JMenuItemitem1,item2,item3,item4,item5,item21,item22,item23,item24,item25,item26,item27,item31,item3 2,item41,item51,item52;JMenuItem itemCopy,itemCut,itemPaste;JTextArea text;//显示纯文本的多行区域JScrollPane scrollPane;JComboBox listFont,listFSize;int save_status=0,status=0,huanhang_count=0;FWindow(String s){//窗口的监听addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent event)//关闭窗口的事件{if(save_status==0){//JOptionPane弹出要求用户提供值或向其发出通知的标准对话框//showConfirmDialog询问一个确认问题int check=JOptionPane.showConfirmDialog(null,"文件的文字已经改变,想保存文件吗?","警告",JOptionPane.YES_NO_CANCEL_OPTION);if(check==0){saveFile(status);}if (check==1) {System.exit(0);}if (check==2) {dispose();}}}});//位置setTitle("记事本");setSize(700,400);setLocation(120, 120);menuBar=new JMenuBar();setJMenuBar(menuBar);text=new JTextArea(30,40);text.setLineWrap(true);//滚动条scrollPane=new JScrollPane(text);//文本框的滚动条add(scrollPane);scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWA YS);scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);menu=new JPopupMenu();menu1=new JMenu("文件");menu1.addActionListener(this);//监听文件菜单menu2=new JMenu("编辑");menu3=new JMenu("格式");menu4=new JMenu("查看");menu5=new JMenu("帮助");menuBar.add(menu1);menuBar.add(menu2);menuBar.add(menu3);menuBar.add(menu4);menuBar.add(menu5);//文件菜单下菜单项的创建并监听item1=new JMenuItem("新建");item1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item1) {text.setText("");this.setTitle("无标题- 记事本");}}private void setTitle(String string){// TODO Auto-generated method stub}});//文件菜单下菜单项的打开并监听item2=new JMenuItem("打开");item2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item2) {File fl;JFileChooser jfc1=new JFileChooser("F:/");//选择打开文件的位置int num1=jfc1.showOpenDialog(null);if (num1==JFileChooser.APPROVE_OPTION) {try {fl=jfc1.getSelectedFile();this.setTitle(fl.getName());FileReader fr=new FileReader(fl);BufferedReader br=new BufferedReader(fr);String str;while((str=br.readLine())!=null){text.setText(str);}fr.close();br.close();} catch (FileNotFoundException e1) {// TODO: handle exceptione1.printStackTrace();}catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}//p12方法private void setTitle(String name){}});//文件菜单下菜单项的保存并监听item3=new JMenuItem("保存");item3.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item3) {File f2=null;JFileChooser jfc2=new JFileChooser();int num2=jfc2.showSaveDialog(null);if(num2==JFileChooser.APPROVE_OPTION){f2=jfc2.getSelectedFile();this.setTitle(f2.getName());try {FileWriter fw=new FileWriter(f2);BufferedWriter bw=new BufferedWriter(fw);bw.write(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}private void setTitle(String name){}});//另存为、退出//===================================另存为有问题===============================================//item4=new JMenuItem("另存为...");item4.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub/*if (e.getActionCommand().equals(" 另存为")) {Frame f=new Frame(" 保存");FileDialog fd=new FileDialog(f," 文件另存为",FileDialog.SA VE);fd.setVisible(true);try {String savepath=fd.getDirectory();String savename=fd.getFile();if (savename!=null) {PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));pw.write(text.getText(),0,text.getText().length());pw.flush();}} catch (Exception easve) {// TODO: handle exception}}*/if (e.getSource()==item4) {File f3=null;JFileChooser jfc3=new JFileChooser();int num3=jfc3.showSaveDialog(null);if(num3==JFileChooser.APPROVE_OPTION){f3=jfc3.getSelectedFile();this.setTitle(f3.getName());try {FileWriter fw=new FileWriter(f3);BufferedWriter bw=new BufferedWriter(fw);bw.write(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}private void setTitle(String name){}});item5=new JMenuItem("退出");//文件菜单下菜单项的退出并监听item5.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item5) {int a=JOptionPane.showConfirmDialog(null,"文件已被改变,是否保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION);if (a==1) {this.dispose();}else if(a==0){File f2=null;JFileChooser jfc2=new JFileChooser();int num2=jfc2.showSaveDialog(null);if (num2==JFileChooser.APPROVE_OPTION) {f2=jfc2.getSelectedFile();this.setTitle(f2.getName());try {FileWriter fw=new FileWriter(f2);BufferedWriter bw=new BufferedWriter(fw);bw.write(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}this.dispose();}}}}private void setTitle(String name){}private void dispose(){}});//KeyStroke 仅能对应于按下或释放某个特定的键//返回KeyStroke 的实例,指定该键在按下或释放时是否视为已激活//CTRL_MASK Ctrl 键修饰符常量。
记事本的程序设计及代码示例
记事本的程序设计及代码示例记事本是一种常见的应用程序,用于记录和编辑文本内容。
在本文中,我们将探讨记事本的程序设计,并给出一个基于Python语言的代码示例。
一、程序设计思路在设计记事本程序时,我们需要考虑以下几个方面:1. 用户界面设计:记事本的用户界面应简洁直观,方便用户输入和编辑文本内容。
可以采用菜单栏、工具栏和文本区域等组件,让用户可以进行打开、保存、复制、粘贴、查找替换等操作。
2. 功能设计:记事本应具备基本的文本编辑功能,如插入、删除、复制、粘贴和撤销等。
此外,还可以添加其他高级功能,如自动保存、自动换行、字体调整以及批量替换等。
3. 文件操作:记事本需要支持文件的打开和保存功能。
用户可以通过打开功能选择要编辑的文本文件,保存功能可以将编辑的内容保存为文件。
同时,还可以支持文件拖拽和快捷键操作。
二、代码示例下面是一个基于Python语言的记事本代码示例:```pythonimport tkinter as tkfrom tkinter import filedialogwindow = ()window.title("记事本")# 创建文本区域text_area = tk.Text(window)text_area.pack()# 打开文件函数def open_file():file_path = filedialog.askopenfilename() if file_path:with open(file_path, 'r') as file:text_area.delete(1.0, tk.END)text_area.insert(tk.END, file.read()) # 保存文件函数def save_file():file_path = filedialog.asksaveasfilename() if file_path:with open(file_path, 'w') as file:file.write(text_area.get(1.0, tk.END))menu_bar = tk.Menu(window)window.config(menu=menu_bar)# 添加文件菜单file_menu = tk.Menu(menu_bar, tearoff=False)menu_bar.add_cascade(label="文件", menu=file_menu)file_menu.add_command(label="打开", command=open_file)file_menu.add_command(label="保存", command=save_file)file_menu.add_separator()file_menu.add_command(label="退出", command=window.quit)# 运行主窗口window.mainloop()```以上代码使用Python的tkinter库创建了一个简易的记事本应用程序。
记事本代码
记事本代码Dim sFind As StringDim FileType, FiType As StringPrivate Sub Form_Load()Me.Height = 6000Me.Width = 9000End SubPrivate Sub Form_Resize()On Error Resume NextRichTextBox1.Top = 20RichTextBox1.Left = 20RichTextBox1.Height = ScaleHeight - 40RichTextBox1.Width = ScaleWidth - 40End SubPrivate Sub mnColor_Click()CommonDialog1.ShowColorRichTextBox1.SelColor = CommonDialog1.ColorEnd SubPrivate Sub mnCopy_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextEnd SubPrivate Sub mnCut_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextRichTextBox1.SelText = ""End SubPrivate Sub mnDisplace_Click()Dim Change As StringChange = InputBox("替换内容:", "替换")If Change <> "" ThenRichTextBox1.Text = ChangeEnd IfEnd SubPrivate Sub mnExit_Click()EndEnd SubPrivate Sub mnFont_Click()With CommonDialog1.Flags = 1.ShowFontRichTextBox1.SelFontSize = CommonDialog1.FontSizeRichTextBox1.SelBold = CommonDialog1.FontBoldRichTextBox1.SelItalic = CommonDialog1.FontItalicRichTextBox1.SelStrikeThru = CommonDialog1.FontStrikethruRichTextBox1.SelUnderline = CommonDialog1.FontUnderlineEnd WithEnd SubPrivate Sub mnOpen_Click()CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*" CommonDialog1.ShowOpenRichTextBox1.Text = ""FileName = CommonDialog1.FileNameRichTextBox1.LoadFile FileNameMe.Caption = "超级记事本:" & FileNameEnd SubPrivate Sub mnPaste_Click()RichTextBox1.SelText = Clipboard.GetTextEnd SubPrivate Sub mnNew_Click()RichTextBox1.Text = ""FileName = "未命名"Me.Caption = FileNameEnd SubPrivate Sub mnSave_Click()CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*" CommonDialog1.ShowSaveFileType = CommonDialog1.FileTitleFiType = LCase(Right(FileType, 3))FileName = CommonDialog1.FileNameSelect Case FiTypeCase "txt"RichTextBox1.SaveFile FileName, rtfTextCase "rtf"RichTextBox1.SaveFile FileName, rtfRTFCase "*.*"RichTextBox1.SaveFile FileNameEnd SelectMe.Caption = "超级记事本:" & FileNameEnd SubPrivate Sub muFind_Click()sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)RichTextBox1.Find sFindEnd SubPrivate Sub RichTextBox1_MouseUp(Button As Integer,Shift As Integer, X As Single, Y As Single)If Button = vbRightButton ThenPopupMenu mnPopEnd IfEnd SubPrivate Sub mnPopCut_Click()mnCut_ClickEnd SubPrivate Sub mnPopCopy_Click()mnCopy_ClickEnd SubPrivate Sub mnPopPaste_Click() mnPaste_ClickEnd Sub。
用C编写的记事本程序
最近想好好研究C,于是便拿记事本这个小程序练练手。
自己从网上找了一个挺不错的,就从这个开始学习吧。
一:代码先建立一文件夹->方便管理与查看拿我来说,在d盘根目录下新建note文件夹1.新建一note.rc资源文件,代码如下。
#include "sample.h"A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "sample.ico" //LOADONCALL 调入装入MAINMENU MENU{POPUP "文件(&F)"{MENUITEM "打开(&O)...", CM_FILE_OPENMENUITEM "另存为(&S)...", CM_FILE_SAVEASMENUITEM SEPARATORMENUITEM "关闭", CM_FILE_EXIT}POPUP "帮助(&H)"{MENUITEM "关于(&A)", CM_ABOUT}}2.新建sample.h,代码如下#define CM_FILE_SAVEAS 9072#define CM_FILE_EXIT 9071#define CM_FILE_OPEN 9070#define CM_ABOUT 90693.新建源程序note.c ,代码如下#include <windows.h>#include "sample.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;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;}二:编译,连接运行在编译之前需要一个sample.ico图标.打开运行,输入cmd,回车,进入dos命令行进入d:\note下1.用dir命令列一下当前目录包含文件。
记事本程序源代码汇总
记事本程序源代码汇总下面是一个简单的记事本程序的源代码:```#include <iostream>#include <fstream>#include <string>using namespace std;void showMencout << "**********************" << endl; cout << " 记事本程序 " << endl; cout << "**********************" << endl; cout << "请选择以下操作:" << endl;cout << "1. 新建记事本文件" << endl;cout << "2. 打开已有记事本文件" << endl; cout << "3. 查看记事本文件内容" << endl; cout << "4. 添加文本到记事本文件" << endl; cout << "5. 退出程序" << endl;cout << "**********************" << endl; void createFilstring filename;cout << "请输入新建记事本文件的文件名:";cin >> filename;//在当前目录创建一个新文件ofstream outFile(filename);outFile.close(;cout << "成功创建记事本文件:" << filename << endl; void openFilstring filename;cout << "请输入要打开的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl;} elsestring content;getline(inFile, content, '\0');cout << "记事本文件内容:" << endl;cout << content << endl;inFile.close(;}void viewFilstring filename;cout << "请输入要查看的记事本文件的文件名:"; cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl; } elsestring line;cout << "记事本文件内容:" << endl;while (getline(inFile, line))cout << line << endl;}inFile.close(;}void appendToFilstring filename;cout << "请输入要添加文本的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ofstream outFile(filename, ios::app);if (!outFile)cout << "无法打开文件:" << filename << endl;} elsestring content;cout << "请输入要添加的文本内容(以#结束):" << endl; while (true)getline(cin, content);if (content == "#")break;}outFile << content << endl;}outFile.close(;cout << "成功添加文本到记事本文件:" << filename << endl; }int maiint choice;doshowMenu(;cout << "请输入您的选择:";cin >> choice;switch (choice)case 1:createFile(;break;case 2:openFile(;break;case 3:viewFile(;break;case 4:appendToFile(;break;case 5:cout << "感谢使用记事本程序,再见!" << endl;break;default:cout << "无效的选择,请重新输入!" << endl;}} while (choice != 5);return 0;```这个记事本程序通过命令行界面提供了以下操作:1.新建记事本文件:用户输入一个文件名后,在当前目录下创建一个新文件作为记事本。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
PSTR szCmdLine, int iCmdShow )//第三个参数lpCmdLine是一个以空终止的字符串,指定传递给应用程序的命令行参数?
{
static TCHAR szAppName[] = TEXT( "demo" ) ;
return 0 ;
case WM_SIZE:
GetClientRect(hwnd, &rect) ;
MoveWindow( hwndChild[ID_EDITBOX], 0, 0, rect.right, rect.bottom-50, TRUE ) ;//调整文本编辑区
MoveWindow( hwndChild[ID_TXTPATH], 100, rect.bottom-31, 400, 20, TRUE ) ;//调整文本路径输入框
TextOut( hdc, 800, rect.bottom-30, szLineNum, lstrlen(szLineNum) ) ;
EndPaint( hwnd, &ps ) ;
return 0 ;
case WM_COMMAND:
wmId=LOWORD(wParam);
wmEvent=HIWORD(wParam);
return -1 ;
}
else{
fwrite(content, lstrlen(content), sizeof(char), fSvae);
MessageBox(NULL, TEXT("保存成功!"), TEXT("成功"), MB_OK | MB_ICONINFORMATION) ;
}
fclose(fSvae) ;
InvalidateRect(hwnd, NULL, FALSE) ;
break ;
default:
break ;
}
return 0 ;
default:
break ;
}
return 0 ;
case WM_DESTROY:
PostQuitMessage(0) ;
return 0 ;
}
return DefWindowProc( hwnd, message, wParam, lParam ) ;
SetWindowText( hwndChild[ID_TXTPATH], TEXT("") ) ;
return 0;
case IDM_OPEN:
GetWindowText( hwndChild[ID_TXTPATH], szPath, 256 );
SetWindowText( hwndChild[ID_EDITBOX], openbook(szPath) ) ;
return 0 ;
case WM_PAINT:
GetClientRect(hwnd, &rect) ;
hdc = BeginPaint( hwnd, &ps ) ;
TextOut( hdc, 20, rect.bottom-30, TEXT("输入名称:"), lstrlen(TEXT("输入名称:")) ) ;
//路径输入框
hwndChild[ID_TXTPATH] = CreateWindow( TEXT("edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL,
0, 0, 0, 0,
hwnd, (HMENU)ID_TXTPATH, hInst, NULL ) ;
case EN_UPDATE:
iLineCount = SendMessage( hwndChild[ID_EDITBOX], EM_GETLINECOUNT, 0, 0 ) ;
iCharCount = GetWindowTextLength( hwndChild[ID_EDITBOX] ) ;
wsprintf(szLineNum, "行数: %i字符数量: %i", iLineCount, iCharCount) ;
return 0 ;
}
int SavaInputContent( TCHAR *path, TCHAR *content )
{
FILE *fSvae ;
strcat(path,".txt");
fSvae = fopen( path, "wb" ) ;
if(fSvae == NULL)
{
MessageBox(NULL, TEXT("文件创建失败!"), TEXT("提示"), MB_OK | MB_ICONINFORMATION) ;
UpdateWindow( hwnd ) ;//窗口更函数。
while( GetMessage(&msg, NULL, 0, 0) ){
TranslateMessage( &msg ) ;
DispatchMessage( &msg ) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
wndclass.lpszClassName= szAppName ;
wndclass.lpszMenuName= (LPCSTR)IDC_MY;
if( !RegisterClass(&wndclass) ){
MessageBox( NULL, TEXT("无法注册窗口类!"), TEXT("错误"), MB_OK | MB_ICONERROR ) ;
switch(wmId){
case IDM_EXIT:
DestroyWindow(hwnd);
case IDM_SAVE:
iLength = GetWindowTextLength(hwndChild[ID_EDITBOX]) ;
szBuffer = (char *) malloc(sizeof(char) * GetWindowTextLength(hwndChild[ID_EDITBOX]) + 1);
HWNDhwnd ;
MSGmsg ;
WNDCLASSwndclass ;
wndclass.lpfnWndProc= WndProc ;
wndclass.style= CS_HREDRAW | CS_VREDRAW ;
wndclass.hInstance= hInstance ;
wndclass.cbClsExtra= 0 ;
int SavaInputContent( TCHAR *, TCHAR * ) ;
TCHAR *openbook(TCHAR *path);//保存输入的文字到文件
int WINAPI WinMain( HINSTANCE hInstance,//第一个参数hInstance表示该程序当前运行的实例的句柄
MessageBox(NULL, TEXT("路径不能为空"), TEXT("提示"), MB_OK | MB_ICONINFORMATION) ;
return -1 ;
}
SavaInputContent( szPatM_NEW:
SetWindowText( hwndChild[ID_EDITBOX], TEXT("") ) ;
return 0;
}
else
{
fseek(Fopen,0, SEEK_END);
int fileLen = ftell(Fopen);
ch = (char *) malloc(sizeof(char) * fileLen);
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
CW_USEDEFAULT , 0, CW_USEDEFAULT, 0,
hwnd, (HMENU)ID_EDITBOX, hInst, NULL ) ;
return 0;
case IDM_ABOUT:
DialogBox(NULL, (LPCTSTR)IDD_ABOUTBOX, hwnd, (DLGPROC)About);
break;
}
switch(LOWORD(wParam)){
case ID_EDITBOX:
switch(HIWORD(wParam)){
staticTCHAR szCharNum[32] ;
static int iLength ;
intiLineCount, iCharCount ;
switch( message ){
case WM_CREATE:
CreateChildWindow( hwnd, hwndChild, lParam ) ;
/*C语言Windows程序设计->简易文本编辑器->演示*/
#include <StdAfx.h>
#include <stdio.h>
#include "resource.h"
/*各控件所使用的ID*/
#define ID_EDITBOX 1//文本编辑框控件