electron笔记无边框窗口、DLL调用、DLL函数返回指针

无边框

const win = new BrowserWindow({
    width: 1290,
    height: 736,
    minHeight: 736,
    minWidth: 1040,
    maxHeight: 736,
    maxWidth: 1290,
    frame: false, // 无边框
    webPreferences: {
          // preload: process.env.WEBPACK_DEV_SERVER_URL ? __dirname + '/preload.js' : 'app://./preload.js',
          // devTools: true,
          // Use pluginOptions.nodeIntegration, leave this alone
          // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
          nodeIntegration: true,
          contextIsolation: false
      }
  })

窗口鼠标拖拽移动

ipcMain.handle("window-move-open", (event, canMoving) => {
    let winStartPosition = { x: 0, y: 0 };
    let mouseStartPosition = { x: 0, y: 0 };
    const currentWindow = BrowserWindow.getFocusedWindow();
    const currentWindowSize = currentWindow.getSize();

    if (currentWindow) {
      if (canMoving) {
        const winPosition = currentWindow.getPosition();
        winStartPosition = { x: winPosition[0], y: winPosition[1] };
        mouseStartPosition = screen.getCursorScreenPoint();
        if (movingInterval) {
          clearInterval(movingInterval);
        }
        movingInterval = setInterval(() => {
          if (!currentWindow.isDestroyed()) {
            if (!currentWindow.isFocused()) {
              clearInterval(movingInterval);
              movingInterval = null;
            }
            const cursorPosition = screen.getCursorScreenPoint();
            const x =
              winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
            const y =
              winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
            currentWindow.setBounds({
              x: x,
              y: y,
              width: currentWindowSize[0],
              height: currentWindowSize[1],
            });
          }
        }, 10);
      } else {
        clearInterval(movingInterval);
        movingInterval = null;
      }
    }
  });

调用dll
nodejs调用dll依赖ffi模块,如何安装ffi依赖?
推荐文章地址:https://blog.csdn.net/qq_28218253/article/details/121643328
需要注意的问题:
1.首先要判断dll是32位还是64位?

桌面左下角搜索,输入vs,选择vs开发者命令行工具, 输入dumpbin /headers XXX.dll,在这里插入图片描述
如果是x86 32 bit,则为32位,反之是64

2.根据dll是32位还是64位,选择对应的nodejs版本以及electron。
推荐文章地址:https://blog.csdn.net/qq_28218253/article/details/121643328
3.安装windows-build-tools出现卡住的问题?
推荐文章地址:https://blog.csdn.net/Ajucy/article/details/130380278

如何调用dll

const dllPath = process.cwd()+'\\5.6.0.8_64.dll';
let strPtr = refArray('uchar',16)
const library = ffi.Library(dllPath,{
  DyInit: ['int',[]],
  DyGetPushStreamUrl:[ref.refType(strPtr),[]],
  DyUnInit: ['int',[]],
  DyGetVersion: [ref.refType(strPtr),[]],
})
 let res =  library.DyGetVersion()
 console.log(res.toString())

dll函数返回指针数据
推荐文章地址:https://blog.csdn.net/RuanEmpty/article/details/115692244

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值