虚表 —— 钮中钮

光庆 4天前 107

 import win.ui;
import godking.vlistEx;
/*DSG{{*/
var winform = win.form(text="aardio form";right=711;bottom=607;bgcolor=16777215)
winform.add(
menu={cls="vlistEx";left=8;top=8;right=136;bottom=600;bgcolor=16777215;db=1;dl=1;dr=1;dt=1;z=3};
static={cls="static";left=139;top=7;right=140;bottom=600;bgcolor=16752414;clip=1;db=1;dl=1;dt=1;z=1};
vlist={cls="vlistEx";left=144;top=8;right=698;bottom=599;bgcolor=16777215;db=1;dl=1;dr=1;dt=1;z=2}
)
/*}}*/

str = /*************
[杀毒软件]
软件名称1=驱动精灵BATW
软件图标=https://img.onlinedown.net/download/202401/135322-65b1f7529ae05.jpg
软件介绍=360出品的杀毒软件
软件大小=65.2 MB
软件链接=https://sfdl.360safe.com/360sd/360sd_x64_std_7.0.0.1060.exe
——————————————————————————————————————
软件名称2=360浏览器
软件图标=https://img.onlinedown.net/download/202408/184132-66b9e6dc71d00.png
软件介绍=360出品的网页浏览软件
软件大小=98 MB
软件链接=https://down.360safe.com/se/360se15.3.6272.64.exe
——————————————————————————————————————
软件名称3=WPS办公
软件图标=https://img3.downza.cn/download/202109/183238-6141cbc684960.jpg
软件介绍=金山公司出品的办公软件
软件大小=155 MB
软件链接=https://official-package.wpscdn.cn/wps/download/WPS_Setup_18912.exe
——————————————————————————————————————
软件名称4=永中文字
软件图标=https://img3.downza.cn/download/202206/103057-6296cf61b8670.jpg
软件介绍=永中公司出品的办公软件
软件大小=125 MB
软件链接=https://dl.yozosoft.com/yozo/project/file/20240812_094642_267975/9.0.5004.101ZH.S1.exe
——————————————————————————————————————
软件名称5=苗
软件图标=http://img3.downza.cn/download/201812/093213-5c184e1da25b6.jpg
软件介绍=360出品的杀毒软件
软件大小=65.2 MB
软件链接=https://sfdl.360safe.com/360sd/360sd_x64_std_7.0.0.1060.exe
——————————————————————————————————————
*************/

var pageitemlist,pagelist = {},{};
for(i=1;5;1){
        var t = {fields={"序号","图标","软件名称","软件介绍","软件大小","下载"}};
        var  pattern = "软件名称"++i++"=(\C+)\r\n软件图标=(\C+)\r\n软件介绍=(\S+)\r\n软件大小=(\d+.?\d+\sMB)\r\n软件链接=(\S+.exe)\r\n"
        for s1,s2,s3,s4,s5 in string.gmatch( str, pattern ){
            var tt={};
            tt["序号"]="[@rowindex]";
            tt["图标"]="";
            tt["软件名称"]=s1;
            tt["软件介绍"]=s3;
            tt["软件大小"]=s4;
            tt["下载"]="";
            tt["地址"]=s5;
            tt["图标网址"]=s2;
            ..table.push(t,tt);
        }
        ..table.push(pageitemlist,t);
        ..table.push(pagelist,{"[@ownerDraw]","E:\图片素材\png\png60_清新网页设计\ ("++i++").png","标题 "++i});
}
winform.menu.setTable(pagelist /*数据表*/," "/*列标题*/,/*列宽*/,/*0左1中2右*/,/*字典转为数组*/,/*字符串转为Utf8*/,/*是否克隆新表*/);
winform.menu.setHeaderHeight(0);
winform.menu.setRowHeight(40);
winform.menu.padding=0;
winform.menu.lineWidthV=0;
winform.menu.lineWidthH=0;
winform.menu.hideScroll(true/*隐藏横向滚动条*/,false/*隐藏纵向滚动条*/);
winform.menu.setColumnType(1/*列号*/,5/*_vlistEx_ColType_Button*/,1/*0居中1缩放2填满*/,/*正常图片*/,/*鼠标悬停图片*/ );
winform.menu.selectedBkColor=null;
winform.menu.ownerDraw = function (row,col,hdc,x,y,w,h,param,...){
    //当列类型为 _vlistEx_ColType_Button 时,如果单元格内容为"[@ownerDraw]",使用该函数自绘按钮。
    //此时 param 值为:true:鼠标在当前单元格内;false:鼠标未在当前单元格内;
    import godking.paint;
    var p = godking.paint.fromHdc(hdc);
    if param {
        p.fillRoundRectF(x,y,w,h,20,0xFF1493FD);
    	p.fillEllipseF(x+5,y+5,h-10,h-10,0xFFFFFFFF)
    	p.drawImageF(x+10,y,h-20,h,winform.menu.getCellText(row,2),,true);
    	p.drawTextF(x+h,y,w,h,winform.menu.getCellText(row,3),::LOGFONT(name="宋体";h=14;color=0xFFFFFFFF;brush=null),0/*格式*/,0/*水平*/,1/*垂直*/)
    } elseif winform.menu.selIndex===row{
    	p.fillRoundRectF(x,y,w,h,20,0xFF50B82E);
    	p.fillEllipseF(x+5,y+5,h-10,h-10,0xFFFFFFFF)
    	p.drawImageF(x+10,y,h-20,h,winform.menu.getCellText(row,2),,true);
    	p.drawTextF(x+h,y,w,h,winform.menu.getCellText(row,3),::LOGFONT(name="宋体";h=14;color=0xFFFFFFFF;brush=null),0/*格式*/,0/*水平*/,1/*垂直*/)
    } else {
    	p.fillRoundRectF( x,y,w,h,20,0xB19EA7FD)
    	p.fillEllipseF(x+5,y+5,h-10,h-10,0x55FFFFFF)
    	p.drawImageF(x+10,y,h-20,h,winform.menu.getCellText(row,2),,true);
    	p.drawTextF(x+h,y,w,h,winform.menu.getCellText(row,3),::LOGFONT(name="宋体";h=14;color=0xFF000000;brush=null),0/*格式*/,0/*水平*/,1/*垂直*/)
    }
    var rect = ::RECT(x+w-14,y,x+w,y+14);
    if rect.contains(winform.menu.mouseX,winform.menu.mouseY){
		p.fillEllipse(rect ,0xFFFF0000);
    } else {
        p.fillEllipse(rect ,0xFF00AA00);
    }
    p.drawEllipse(rect /*绘制范围RECT*/,0xFFFFFFFF,/*线宽*/,/*线型*/)
    p.textAntiAlias = true;
    p.drawText(x+w-13,y,x+w,y+17,"×",::LOGFONT(name="Arial";h=20;color=0xFFFFFFFF;brush=null),0/*格式*/,1/*水平*/,1/*垂直*/);
    p.close();
    winform.menu.setButtonRects( row/*row*/, col/*col*/, {rect}/*按钮范围数组*/ );
}

import inet.http;
var mypic = ..raw.buffer(1024*1024*10);
winform.vlist.setHeaderHeight(50);
winform.vlist.headerAlign = 1;
winform.vlist.setRowHeight(45);
winform.vlist.textColor = 0x666666;
winform.vlist.selectedTextColor = 0xFF0000;
winform.vlist.lineColorH =0xCFCFCF; 
winform.vlist.lineWidthV = null; 
winform.vlist.addImg("正常按钮","https://d.xiazai8.com/pic/20240316/dfphijddtql.jpg");
winform.vlist.addImg("悬停按钮","https://d.xiazai8.com/pic/20240316/nmx5hgq2tap.png");

import thread.command;
thread.command.instance().resetImg =function(row,imgfile,len){
        if row and imgfile and len { 
            var buf = ..string.left(mypic,len);
            if winform.vlist.addImg(imgfile,buf/*图片文件*/,false/*是否替换*/,100/*宽度*/,100/*高度*/) {
                winform.vlist.redrawRow(row);
            }
        }
    }
    
import godking.paint;
winform.vlist.ownerDraw = function (row,col,hdc,x,y,w,h,param,...){
    var url = winform.vlist.getCellText(row,"图标网址");
    var buf = winform.vlist.getImg(url);
    if buf {
        var  p = godking.paint.fromHdc(hdc);
        p.drawImageF(x,y,w,h,buf/*图片*/,/*透明度或图片属性*/,true/*保持比例*/)
        p.close()
        return ; 
    }
    ..gdi.fillRect(hdc,0xEEEEEE,::RECT(x,y,x+w,y+h)); //没有加载图片前,可以先画一个灰色方框占位。
    thread.invoke( 
        function(row,imgfile,mypic){
            import inet.http;
            var pic = inet.http.get(imgfile);
            if type.isString(pic) {
                import thread.command;
                thread.lock("临界区名称");
                ..raw.copy(mypic,pic,#pic);
                thread.command.resetImg(row,imgfile,#pic);
                thread.unlock("临界区名称");
            }
        }
    ,row,url,..raw.toPointer(mypic));
}

winform.vlist.onClick = function(row/*行*/,col/*列*/,x,y){
    if col==6 {..win.msgbox(winform.vlist.getCellText(row,"地址"))}
}

winform.menu.onClick = function(row/*行*/,col/*列*/,x,y,buttonIndex/*按钮序号*/){
	if row {
		if !buttonIndex {
			winform.vlist.setTable(pageitemlist[row] /*数据表*/,/*列标题*/,{40,50,150,180,60,60}/*列宽*/,/*0左1中2右*/,/*字典转为数组*/,/*字符串转为Utf8*/,true/*是否克隆新表*/)
    		winform.vlist.setColumnType(2,6/*_vlistEx_ColType_OwnerDraw*/ );
    		winform.vlist.setColumnType(6,5/*_vlistEx_ColType_Button*/,1/*0居中1缩放2填满*/,"正常按钮"/*正常图片*/,"悬停按钮"/*鼠标悬停图片*/ );
    	} else {
    		winform.menu.delRow(row);
    		table.remove(pageitemlist,row);
    	}
	}
}

winform.show();
winform.menu.onClick(1);
win.loopMessage();

最新回复 (3)
  • 近我者赤 4天前
    0 引用 2
  • amin 3天前
    0 引用 3

    把这个工具栏分开弄的明明白白 。大佬提供了很好的的学习资料

  • 小肥羊 3天前
    0 引用 4
    不行不行,这个代码看着都复杂,有点整不过来
返回