重写了一个msgbox库 , 代码参考了win.dlg.message库

By admin at 2021-08-12 • 1人收藏 • 1533人看过

系统自带的msgbox挺简单好用, 但是不能设置弹出位置 , 有时候用起来会挡住后面一些重要的地方,

aardio里还有一个用plus写的win.dlg.message信息对话框库, 界面效果类似html弹窗.

有时候我们需要弹窗里响应[空格键]和[回车键]/[tab键]消息, 这样就需要对win.dlg.message库代码进行改造下, 所以我把这个库的代码复制出来进行了简单的修改, 使它能响应按键并且可以设置弹出位置,  用来适合当前的项目.


image.png


库 msgboxTest.aardio 代码如下:

import win.ui;
class msgBoxTest{
	ctor( parent ){
		this.parent = parent : ..win.getActive();
	};
	create = function(msg){ 
		if(!#msg) error("文本不能为空",2);
		var parentForm = this.parent;
		if(parentForm){
			if( !..win.isWindow(this.parent[["hwnd"]] || this.parent) ){
				parentForm = ..win.getActive() || ..mainForm[["hwnd"]];
			}	
		}

		var winform = ..win.form(text="提示";right=251;bottom=120;border="thin";max=false;min=false;mode="popup";sysmenu=false;parent=parentForm)
		if(!winform){
			return;
		}

		winform.add(
			btnCancel={cls="button";text="取消";left=127;top=83;right=248;bottom=116;tabstop=1;z=2};
			btnOK={cls="button";text="下一步";left=4;top=83;right=125;bottom=116;default=1;tabstop=1;z=1};
			message={cls="static";text=msg;left=0;top=0;right=252;bottom=78;align="center";bgcolor=0;color=65302;font=LOGFONT(h=-19);z=3}
		)  
		..win.setFocus(winform.btnOK.hwnd);
		winform.btnOK.oncommand = function(id,event){
			winform.endModal(true);
		} 
		winform.btnCancel.oncommand = function(id,event){
			winform.endModal(false);
		}

		return winform;	
	}
	show = function(msg,sw){
		if(!#msg) error("文本不能为空",2);
		var dlg = this.create(msg);
		if(dlg) return dlg.show(sw);
	}
	doModal = function(msg,posx,posy){
		if(!#msg) error("文本不能为空",2);
		var dlg = this.create(msg);
		if(!dlg) return;
		if(posx !=null and posy!=null)
		dlg.setPos(posx,posy);
		return dlg.doModal();
	}
	Test = function(msg,posx,posy){
		return this.doModal(msg,posx,posy);
	}
}

msgBoxTest.install = function(){
	..win.ui.ctrl.metaProperty.mixin({
		msgTest = function(str,posx,posy){
			return msgBoxTest(owner).Test( str,posx,posy ); 
		}; 
	})
}
msgBoxTest.install();

使用的时候只需要简单的调用即可.

代码示例如下:

import console
console.open()

import msgBoxTest;
mainForm.button.oncommand = function(id,event){
	console.log( mainForm.msgTest("XXX操作完成了吗?",300,500) );
}


工程下载:

msgboxDemo.zip




2022.11.13更新

将弹出位置改为设置一个控件作为参考, 将上面源码最后一行改为

msgBoxTest.install = function(){
    ..win.ui.ctrl.metaProperty.mixin({
        msgTest = function(str,winform){
            var rc = winform.getRect(true);
            var posx = rc.left+(rc.width()/2 - 123);
            var posy = rc.top+(rc.height()/2 - 92);
            return msgBoxTest(owner).Test( str,posx,posy ); 
        }; 
    })
}

使用的时候:

mainForm.msgTest(信息内容,mainForm.msglog)

这样就会在msglog这个控件的中心弹出窗口.


1 个回复 | 最后更新于 2022-06-12
2022-06-19   #1

有空研究下,能不能插入图片

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...