📄 notepad.c
字号:
U32 sendsms; //发送短信按钮
U32 infrared; //红外发送按钮
// U32 first;
U32 prev; //prev按钮
U32 next; //next按钮
// U32 last;
U32 textedit; //文本编辑栏
U32 keyboard; //软键盘
U32 kb; //键盘按钮,
U32 tskbar; //底部任务栏
//定义函数用变量
MSG msg;
S16 quit = 0;
S16 kbflag = 0; //判断软键盘是否打开,默认不打开软键盘
char newcontent[TEXT_SIZE + 1];
char size[6];
S16 dirnum = 0;
S16 filenum = 0;
S16 i = 0;
//初始化
memset(newcontent, 0x00, (TEXT_SIZE + 1)*sizeof(char));
memset(size, 0x00, 6);
for(i = 0; i < allnum; i++)
{
if(*(nowlist[i]->id) == 0) //当项目类型为文件时,跳出
break;
}
dirnum = i; //得出目录的个数
filenum = allnum - dirnum; //剩下的时文件个数
//创建窗口和控件
mainwin = CreateWindow(WNDCLASS_WIN, "阅读文件", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
save = CreateWindow(WNDCLASS_BUTTON, "\\保存", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_save);
sendsms = CreateWindow(WNDCLASS_BUTTON, "\\发送短信", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2 + 25, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_fasongduanxin);
infrared = CreateWindow(WNDCLASS_BUTTON, "红外", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2 + 50, 23, BUTTON_W, BUTTON_W, mainwin, 0, NULL);
prev = CreateWindow(WNDCLASS_BUTTON, "\\上一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2 + 75, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_prev);
next = CreateWindow(WNDCLASS_BUTTON, "\\下一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2 + 100, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_next);
// kb = CreateWindow(WNDCLASS_BUTTON, "kb", WS_CHILD|BS_REGULAR, 30, 220, BUTTON_W, BUTTON_W, mainwin, 0, NULL);
textedit = CreateWindow(WNDCLASS_EDITOR, nowlist[offset]->content, WS_CHILD|ES_MULTI_REGULAR, (LCD_WIDTH - 156)/2, 48, 156, 170, mainwin, TEXT_SIZE, NULL);
GetEditorStr(textedit, newcontent, TEXT_SIZE);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
kb = AddBtn2TskBar(tskbar, NULL, BS_ICON, BUTTON_W, (char *)zi_jianpan);
if(offset <= dirnum)
{
EnableWindow(prev, FALSE);
}
if(offset == (allnum - 1))
{
EnableWindow(next, FALSE);
}
//程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == save) //点击保存按钮
{
GetEditorStr(textedit, newcontent, TEXT_SIZE);
if(strlen(newcontent) == 0)
{
MessageBox(mainwin, "请输入文件内容!", "提醒", MB_ICONEXCLAMATION|MB_OK);
}
else
{
strcpy(nowlist[offset]->content, newcontent);
sprintf(size, "%u",strlen(newcontent));
strcpy(nowlist[offset]->size, size);
AddDirFile(nowlist[offset]);
MessageBox(mainwin, "保存完毕!!!", "提醒", MB_ICONEXCLAMATION|MB_OK);
}
}
else
if(msg.lparam == sendsms) //发送短消息
{
GetEditorStr(textedit, newcontent, TEXT_SIZE);
if(strlen(newcontent) == 0)
{
MessageBox(mainwin, "请输入文件内容!", "提醒", MB_ICONEXCLAMATION|MB_OK);
}
else
{
if(kbflag == 1)
{
DestroyWindow(keyboard);
TransmitSMS(newcontent);
keyboard = CreateWindow(WNDCLASS_KEYBD, "", WS_CHILD|KBS_HANDWRITE|0xff, 1, 144, 157, 70, mainwin, 0, NULL);
}
else
TransmitSMS(newcontent);
}
}
else
if(msg.lparam == infrared) //红外
{
GetEditorStr(textedit, newcontent, TEXT_SIZE);
if(strlen(newcontent) == 0)
{
MessageBox(mainwin, "请输入文件内容!", "提醒", MB_ICONEXCLAMATION|MB_OK);
}
else
{
//红外发送
;
}
}
else
if(msg.lparam == prev)
{
if(offset == (allnum - 1))
{
EnableWindow(next, TRUE);
}
offset -= 1;
if(offset == dirnum)
{
EnableWindow(prev, FALSE);
}
SetWindowText(textedit, nowlist[offset]->content, NULL);
}
else
if(msg.lparam == next)
{
if(offset == dirnum )
{
EnableWindow(prev, TRUE);
}
offset += 1;
if(offset == (allnum - 1))
{
EnableWindow(next, FALSE);
}
SetWindowText(textedit, nowlist[offset]->content, NULL);
}
else
if(msg.lparam == kb)
{
if(kbflag == 0)
{
DestroyWindow( textedit );
textedit = CreateWindow(WNDCLASS_EDITOR, newcontent, WS_CHILD|ES_MULTI_REGULAR, 2, 48, 156, 85, mainwin, TEXT_SIZE, NULL);
keyboard = CreateWindow(WNDCLASS_KEYBD, "", WS_CHILD|KBS_HANDWRITE|0xff, 1, 144, 157, 70, mainwin, 0, NULL);
kbflag = 1;
}
else
{
DestroyWindow( keyboard );
GetEditorStr(textedit, newcontent, TEXT_SIZE);
DestroyWindow( textedit );
textedit = CreateWindow(WNDCLASS_EDITOR, newcontent, WS_CHILD|ES_MULTI_REGULAR, 2, 48, 156, 170, mainwin, TEXT_SIZE, NULL);
kbflag = 0;
}
}
break;
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow( mainwin );
return;
}
//更名模块
void ChangeName(PROPERTY *nowitem)
{
//定义窗口和控件ID
U32 mainwin; //主窗口
U32 tip; //提示目录/文件名,静态框
U32 nameedit; //名称编辑栏
U32 ok; //确定按钮
U32 cancel; //取消按钮
U32 keyboard; //软键盘
U32 tskbar; //底部任务栏
//定义函数用变量
MSG msg;
S16 quit = 0;
char newname[NAME_SIZE + 1];
S16 parentlen, idlen, namelen, timelen, sizelen, contentlen;
S16 datalen;
char *data;
DBLACB *lacb;
U16 parentoffset;
U16 idoffset;
U16 nameoffset;
U16 timeoffset;
U16 sizeoffset;
U16 contentoffset;
// char temp[TEXT_SIZE + 1], temp2[TEXT_SIZE + 1];
S16 offset;
char *newdata;
char timetemp[TIME_SIZE + 1];
char temp[TIME_SIZE + 1];
//初始化
memset(newname, 0x00, (NAME_SIZE + 1));
memset(temp, 0x00, TIME_SIZE + 1);
memset(timetemp, 0x00, TIME_SIZE + 1);
//创建窗口和控件
mainwin = CreateWindow(WNDCLASS_WIN, "重命名", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
tip = CreateWindow(WNDCLASS_STATIC, "目录/文件名", WS_CHILD|SS_TEXT, (LCD_WIDTH - 100)/2, 30, 100, 20, mainwin, 0, NULL);
nameedit = CreateWindow(WNDCLASS_EDITOR, nowitem->name, WS_CHILD|ES_SINGLE_REGULAR, (LCD_WIDTH - 140)/2, 55, 140, 20, mainwin, (NAME_SIZE + 1), NULL);
ok = CreateWindow(WNDCLASS_BUTTON, "确定", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2, 85, 40, BUTTON_W, mainwin, 0, NULL);
cancel = CreateWindow(WNDCLASS_BUTTON, "取消", WS_CHILD|BS_REGULAR, (LCD_WIDTH + 40)/2, 85, 40, BUTTON_W, mainwin, 0, NULL);
keyboard = CreateWindow(WNDCLASS_KEYBD, "", WS_CHILD|KBS_HANDWRITE|0xff, 1, 144, 157, 70, mainwin, 0, NULL);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
lacb = LinkDataBase(NOTEPAD_DATA_BASE);
SetFocus(nameedit);
//程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == ok)
{
GetEditorStr(nameedit, newname, NAME_SIZE + 1);
if(strlen(newname) == 0)
{
MessageBox(mainwin, "请输入目录/文件名!", "提醒", MB_ICONEXCLAMATION|MB_OK);
}
else //当姓名不为空时,进行改名操作
{
data = LocalReadRecord(lacb, nowitem->index);
if(*(data + 12 + *((U16 *)(data + 14))) == 0) //是文件类型时
{
ByteReversal(&parentoffset, data + 12);
parentlen = (S16)strlen(data + 12 + parentoffset);
if(parentlen == 0)
parentlen -= 1;
ByteReversal(&idoffset, data + 14);
idlen = (S16)strlen(data + 12 + idoffset);
idlen -= 1;
ByteReversal(&nameoffset, data + 16);
namelen = (S16)strlen(data + 12 + nameoffset);
ByteReversal(&timeoffset, data + 18);
timelen = (S16)strlen(data + 12 + timeoffset);
ByteReversal(&sizeoffset, data + 20);
sizelen = (S16)strlen(data + 12 + sizeoffset);
ByteReversal(&contentoffset, data + 22);
contentlen = (S16)strlen(data + 12 + sizeoffset);
datalen = 12 + parentlen + idlen + namelen + timelen + sizelen + contentlen + 6;
offset = (S16)(strlen(newname) - strlen(nowitem->name));
if((newdata = (char *)Lmalloc(datalen + offset)) == NULL)
// if(MessageBox(0, "内存申请失败!","警告", MB_ICONEXCLAMATION|MB_OK) = IDOK)
return;
//改写偏移量
memcpy(newdata, (data + 12), 12);
Word2Bytes(newdata + 6, (U16)(timeoffset + offset));
Word2Bytes(newdata + 8, (U16)(sizeoffset + offset));
Word2Bytes(newdata + 10, (U16)(contentoffset + offset));
//改写内容
strcpy((newdata + parentoffset), (data + 12 + parentoffset));
strcpy((newdata + idoffset), (data + 12 + idoffset));
strcpy((newdata + nameoffset), newname);
//获取时间并存入data
{
ASIX_DATE date;
ASIX_TIME time;
ReadDateTime(&date, &time); //获取系统时间
sprintf(temp, "%u", date.year);
strcpy(timetemp, temp);
if(date.month < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.month);
strcat(timetemp, temp);
if(date.day < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.day);
strcat(timetemp, temp);
if(time.hour < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.hour);
strcat(timetemp, temp);
if(time.minute < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.minute);
strcat(timetemp, temp);
if(time.second < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.second);
strcat(timetemp, temp);
strcpy((newdata + timeoffset + offset), timetemp);
}
strcpy((newdata + sizeoffset + offset), (data + 12 + sizeoffset));
strcpy((newdata + contentoffset + offset), (data +12 + contentoffset));
LocalModifyRecord(lacb, nowitem->index, newdata, (U16)(datalen + offset));
Lfree(newdata);
}
else //是目录类型时
{
ByteReversal(&parentoffset, data + 12);
parentlen = (S16)strlen(data + 12 + parentoffset);
if(parentlen == 0)
parentlen -= 1;
ByteReversal(&idoffset, data + 14);
idlen = (S16)strlen(data + 12 + idoffset);
ByteReversal(&nameoffset, data + 16);
namelen = (S16)strlen(data + 12 + nameoffset);
ByteReversal(&timeoffset, data + 18);
timelen = (S16)strlen(data + 12 + timeoffset);
datalen = 12 + parentlen + idlen + namelen + timelen + 4;
offset = (S16)(strlen(newname) - strlen(nowitem->name));
if((newdata = (char *)Lmalloc(datalen + offset)) == NULL)
// if(MessageBox(0, "内存申请失败!","警告", MB_ICONEXCLAMATION|MB_OK) == IDOK)
return;
//改写偏移量
memcpy(newdata, (data + 12), 12);
Word2Bytes(newdata + 6, (U16)(timeoffset + offset));
//改写内容
strcpy((newdata + parentoffset), (data + 12 + parentoffset));
strcpy((newdata + idoffset), (data + 12 + idoffset));
strcpy((newdata + nameoffset), newname);
//获取时间并存入data
{
ASIX_DATE date;
ASIX_TIME time;
ReadDateTime(&date, &time); //获取系统时间
sprintf(temp, "%u", date.year);
strcpy(timetemp, temp);
if(date.month < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.month);
strcat(timetemp, temp);
if(date.day < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.day);
strcat(timetemp, temp);
if(time.hour < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.hour);
strcat(timetemp, temp);
if(time.minute < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.minute);
strcat(timetemp, temp);
if(time.second < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.second);
strcat(timetemp, temp);
strcpy((newdata + timeoffset + offset), timetemp);
}
LocalModifyRecord(lacb, nowitem->index, newdata, (U16)(datalen + offset));
Lfree(newdata);
}
strcpy(nowitem->name, newname);
quit = 1;
Lfree(data);
}
}
else
if(msg.lparam == cancel)
{
quit = 1;
}
break;
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow( mainwin );
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -