超级记事本案例
本帖最后由 axuanup 于 2024-1-22 14:23 编辑import fonts.ionicons;
import fonts.fontAwesome;
import fonts.imtip;
import win.ui;
/*DSG{{*/
mainForm = win.form(text="超级记事本";left=0;top=0;right=745;bottom=474;bgcolor=15780518;border="none";max=false)
mainForm.add(
bk={cls="bk";text='\uF040';left=5;top=5;right=38;bottom=25;dl=1;dt=1;font=LOGFONT(h=-18;name='FontAwesome');z=9};
listbox={cls="listbox";left=5;top=60;right=182;bottom=470;db=1;dl=1;dt=1;integralHeight=0;items={};vscroll=1;z=1};
["plus_删除"]={cls="plus";text='\uF4C5';left=78;top=36;right=108;bottom=56;dl=1;dt=1;font=LOGFONT(h=-18;name='Ionicons');notify=1;z=4};
["plus_同步"]={cls="plus";text='\uF0E2';left=148;top=36;right=178;bottom=56;dl=1;dt=1;font=LOGFONT(h=-18;name='FontAwesome');notify=1;z=7};
["plus_命名"]={cls="plus";text='\uF472';left=43;top=36;right=73;bottom=56;dl=1;dt=1;font=LOGFONT(h=-18;name='Ionicons');notify=1;z=5};
["plus_导入"]={cls="plus";text='\uF4C7';left=113;top=36;right=143;bottom=56;dl=1;dt=1;font=LOGFONT(h=-18;name='Ionicons');notify=1;z=6};
["plus_新建"]={cls="plus";text='\uF07C';left=8;top=36;right=38;bottom=56;dl=1;dt=1;font=LOGFONT(h=-18;name='imtip');notify=1;z=2};
richedit={cls="richedit";left=188;top=32;right=742;bottom=470;db=1;dl=1;dr=1;dt=1;link=1;multiline=1;vscroll=1;z=3};
static={cls="static";text="超级记事本";left=36;top=5;right=167;bottom=27;center=1;dl=1;dt=1;transparent=1;z=8}
)
/*}}*/
import console;
import fsys;
import fsys.dlg;
import godking.message;
import win.ui.tooltip;
import process;
//实例化消息框
var m = godking.message(mainForm)
//初始化窗体
var init = function() {
//判断路径是否存在
var fullpath = io.exist("\data")
if (fullpath) {
//搜索路径,返回目录下文件,目录数组
var fileList = fsys.list("\data")
mainForm.listbox.items = fileList;
mainForm.listbox.selIndex = 1;
mainForm.richedit.text = string.load("\data\"++mainForm.listbox.selText)
}
mainForm.text = "超级记事本 V1.0.7"
mainForm.static.text = mainForm.text;
import win.ui.menu;
//创建弹出菜单
mainForm.popmenu = win.ui.popmenu(mainForm);
mainForm.popmenu.add('打开路径', function(id) {
if (#mainForm.listbox.items > 0) {
process.explore(fsys.getParentDir("\data\"++mainForm.listbox.selText))
}
})
//如果 winform 的最大化按钮设为隐藏(false),则最大化按钮以及可拖动边框不会出现。
import win.ui.simpleWindow;
win.ui.simpleWindow(mainForm);
//在所有者窗口 winform 上创建 tooltip 提示控件
var tooltipCtrl = win.ui.tooltip(mainForm);
tooltipCtrl.addTool(mainForm.plus_新建, "新建txt文件")
tooltipCtrl.addTool(mainForm.plus_删除, "删除txt文件")
tooltipCtrl.addTool(mainForm.plus_命名, "重命名txt文件")
tooltipCtrl.addTool(mainForm.plus_导入, "导入txt文件")
tooltipCtrl.addTool(mainForm.plus_同步, "同步txt文件列表")
win.center(mainForm.hwnd, 0)
//***************************************************************************************
//下面创建托盘图标
import win.util.tray;
mainForm.tray = win.util.tray(mainForm)
mainForm.tray.tip = "超级记事本" //提示超级记事本
mainForm.onMinimize = function(lParam){
mainForm.tray = win.util.tray(mainForm);
mainForm.show(false); //隐藏窗口
return true;//阻击默认消息传递,取消最小化过程
}
mainForm.onTrayMessage = {
//鼠标右击
= function(wParam){
//弹出托盘菜单以前,一定要前置主窗口中,避免不点击菜单不会消失,父窗口隐藏也要这样做
win.setForeground(mainForm.hwnd)
/*
下面创建托盘弹出菜单。
如果程序要开机启动到托盘,最好在这里创建菜单,在用户点击前不要创建菜单,
避免系统启动时 DPI 缩放前创建的菜单字体偏小(出现这情况的机率很小)。
如果不想重复创建菜单最好写到一个库里,然后在这里 import 即可避免上述问题。
*/
import win.ui.menu;
mainForm.popmenu = win.ui.popmenu(mainForm);//创建弹出菜单
mainForm.popmenu.add('&打开软件',function(id){
//在下面输入菜单响应代码
mainForm.show(true);
});
mainForm.popmenu.add();//分隔线
mainForm.popmenu.add('&关闭软件',function(id){ mainForm.close() })
mainForm.popmenu.popup();
mainForm.popmenu.close();
};
= function(wParam){
//鼠标左击
mainForm.show(true);
};
}
//***************************************************************************************
//请先在 richedit 控件的设计器属性中指定「识别链接」为 true
mainForm.richedit.onHyperlink =function(message,href){
//在链接上弹起鼠标左键
if( message = 0x202 /*_WM_LBUTTONUP*/ ) {
import process;
process.openUrl(href);
}
}
//多行文本框如下支持按 tab 输入制表符,控件设计属性「tab控制键」必须为 false(默认值)。
mainForm.richedit.isDialogMessage = function(hParent,msg){}
}
init()
mainForm.listbox.wndproc = function(hwnd, message, wParam, lParam) {
select (message) {
case 0x205 /*_WM_RBUTTONUP*/ {
var x, y = win.getMessagePos();
var item = mainForm.listbox.hitTest(x, y, true);
if (item) {
mainForm.listbox.selIndex = item;
mainForm.popmenu.popup(x, y, true)
}
}
}
}
mainForm.listbox.oncommand = function(id, event) {
var fullpath = io.exist("\data")
if (fullpath) {
if (#mainForm.listbox.items > 0) {
var s = string.load("\data\"++mainForm.listbox.selText)
mainForm.richedit.text = s;
}
}
}
mainForm.richedit.enablePopMenu() //开启右键菜单
mainForm.richedit.onChange = function() {
if (owner.onModified) owner.onModified(true);
var fullpath = io.exist("\data")
if (fullpath) {
string.save("\data\"++mainForm.listbox.selText, owner.text, false)
}
}
mainForm.plus_新建.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
mainForm.plus_新建.oncommand = function(id, event) {
var name = m.input("新建文件", false)
if (name) {
string.save("\data\"++name++".txt", "", true)
var fileList = fsys.list("\data")
mainForm.listbox.items = fileList;
mainForm.listbox.selText = name ++".txt";
mainForm.richedit.text = string.load("\data\"++mainForm.listbox.selText)
}
}
mainForm.plus_删除.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
mainForm.plus_删除.oncommand = function(id, event) {
var fullpath = io.exist("\data")
if (fullpath) {
if (#mainForm.listbox.items > 0) {
var state = m.ask("是否删除->"++mainForm.listbox.selText)
if (state) {
fsys.delete("\data\"++mainForm.listbox.selText);
var fileList = fsys.list("\data")
mainForm.listbox.items = fileList;
mainForm.listbox.selIndex = 1;
mainForm.richedit.text = string.load("\data\"++mainForm.listbox.selText)
}
}
}
}
mainForm.plus_命名.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
mainForm.plus_命名.oncommand = function(id, event) {
var fullpath = io.exist("\data")
if (fullpath) {
if (#mainForm.listbox.items > 0) {
var name = m.input("修改名称", false)
if (name) {
fsys.rename("\data\"++mainForm.listbox.selText, "\data\"++name++".txt")
var fileList = fsys.list("\data")
mainForm.listbox.items = fileList;
mainForm.listbox.selText = name ++".txt";
mainForm.richedit.text = string.load("\data\"++mainForm.listbox.selText)
}
}
}
}
mainForm.plus_导入.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
mainForm.plus_导入.oncommand = function(id, event) {
}
mainForm.plus_同步.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
mainForm.plus_同步.oncommand = function(id, event) {
var fullpath = io.exist("\data")
if (fullpath) {
var fileList = fsys.list("\data")
mainForm.listbox.items = fileList;
mainForm.listbox.selIndex = 1;
mainForm.richedit.text = string.load("\data\"++mainForm.listbox.selText)
}
}
mainForm.show();
return win.loopMessage();
代码运行似乎有些问题 本帖最后由 rmajly 于 2024-2-9 15:40 编辑
报错,而且新建的txt文件很乱,不便管理
页:
[1]