• 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
          }
      })
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    窗口鼠标拖拽移动

    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;
          }
        }
      });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    调用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())
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

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

  • 相关阅读:
    2.10 PE结构:重建重定位表结构
    Scala下载和配置
    ios 网站打包操作步骤介绍
    【CMake】浅谈使用 colcon build 时 CMakeLists 的配置方法-1.使用第三方开源库
    [SWPU2019]Web3
    蓝桥杯打卡Day11
    OpenWRT、Yocto 、Buildroot和Ubuntu有什么区别
    后端大厂面试-15道题
    简记C语言清空输入残留内容
    Excel中行列范围的转换
  • 原文地址:https://blog.csdn.net/qq_42289686/article/details/132649000