aardio实现悬浮窗

admin2021-10-28  3.1K+

//取剪贴板图像
import win.ui;
/*DSG{{*/
var winform = win.form(text = "aardio form"; right = 100; bottom = 100; border = "none"; max = false; min = false; mode = "popup"; parent = ...; title = false) winform.add()
/*}}*/

import win;

global.isDragging = false;
global.oldWindowsX = 0;
global.oldWindowsY = 0;
global.oldCursorX = 0;
global.oldCursorY = 0;
global.newWindowsX = 0;
global.newWinY = 0;
global.newCursorX = 0;
global.newCursorY = 0;

// 创建弹出菜单
// https://www.cnblogs.com/yaoyue68/p/4858811.html
var popmenu = win.ui.popmenu(winform);
popmenu.add('关闭',
function(id) { 
    win.close(winform.hwnd);
})

winform.wndproc = function(hwnd, message, wParam, lParam) {
    select(message) {
    case 0x201
        /*_WM_LBUTTONDOWN*/
        {
            //console.log("_WM_LBUTTONDOWN")
            isDragging = true;
            oldCursorX,
            oldCursorY = win.getCursorPos();
            oldWindowsX,
            oldWindowsY = win.getPos(winform.hwnd);
            //console.log(oldWindowsX)
            win.setCapture(winform.hwnd);
            //bx,by = win.toClient(winform.hwnd,x,y);
            //return;
        }
    case 0x202
        /*_WM_LBUTTONUP*/
        {
            //console.log("_WM_LBUTTONUP")
            win.releaseCapture();
            isDragging = false;
        }
    case 0x200
        /*_WM_MOUSEMOVE*/
        {
            if (not isDragging) {
                return
            }
            newCursorX,
            newCursorY = win.getCursorPos();
            newWindowsX = oldWindowsX   newCursorX - oldCursorX;
            newWindowsY = oldWindowsY   newCursorY - oldCursorY;
            win.setPos(winform.hwnd, newWindowsX, newWindowsY, 100, 100);
        }
    case 0x205
        /*_WM_RBUTTONUP*/
        {
            {
                var x, y = win.getMessagePos(); //获得鼠标位置
                popmenu.popup(x, y, true) //popup弹出坐标,第三个参数如上
            }
        }
    }
}

win.setTopmost(winform.hwnd);
winform.show() win.loopMessage();

类似百度网盘一样的悬浮窗,可以随鼠标拖动,并响应按钮点击。

转载请注明原文地址: https://aardio.net/read-251.html
最新回复(1)
  • Mr_MAO2021-11-3
    引用2

    用winform.hitCaption()可以很方便的实现该功能.

    //创建类似于百度网盘那样可拖动的悬浮窗(*更简便的方法)
    import win.ui;
    /*DSG{{*/
    var winform = win.form(text="";right=60;bottom=60;bgcolor=8421376;border="none";max=false;min=false;mode="popup";title=false)
    /*}}*/
    
    winform.wndproc = function(hwnd, message, wParam, lParam) {
        select(message) {
            case 0x201/*_WM_LBUTTONDOWN*/{
            //点击左键移动窗体
                winform.hitCaption()
            }
            case 0x205/*_WM_RBUTTONUP*/{
            //右键菜单
                var popmenu = win.ui.popmenu(winform);
                popmenu.add('关闭',
                function(id) { 
                    win.close(winform.hwnd);
                })     
                popmenu.popup()
            }    
        }
    }
    win.setTopmost(winform.hwnd); //窗口置顶
    winform.show();
    win.loopMessage();
aardio问答
aardio编程语言