大佬教程收集整理的这篇文章主要介绍了node-ffi模块的安装以及基于electron生成windows桌面应用程序,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
原文地址:
node-ffi:Node.js Foreign Function Interface
node-ffi
is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without wriTing any C++ code. It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C,which can add reams of boilerplate code to your otherwise simple C. See the example/factorial for an example of this use case.
WARNING:node-ffi
assumes you kNow what you're doing. You can pretty easily create situations where you will segfault thE interpreter and unless you've got C debugger skills,you probably won't kNow what's going on.
上面是 node-ffi 的介绍,英语不好,就不翻译了。
使用上一篇文章里的项目,在 package.json的 dependencies节点上加上node-ffi 依赖:
"dependencies": { "electron": "^1.6.11","ffi": "2.2.0" }
然后安装缺失的 npm包(参考之前的文章),注意,安装 ffi npm 包之前需要安装 python2.7,否则 ffi 会编译总是失败,导致安装不成功,具体安装参考:https://github.com/nodejs/node-gyp#installation。
const ffi = require('ffi')
然后运行程序,出现如下错误:
参考资料:https://github.com/electron/electron/blob/master/docs-translations/zh-CN/tutorial/using-native-node-modules.md,原来是需要把 ffi 重新编译为适合 electron的模块。
打开 nodejs 命令行窗口,先执行如下命令:
set python=python安装路径\python.exe
设置 python 的路径,切换到项目目录,然后执行如下命令:
"./node_modules/.bin/electron-rebuild" "./node_modules/ffi"
编译完成后,运行程序,漂亮的界面终于出现了。
上篇文章中的仿 QQ 登录界面还有一个小问题,就是鼠标右键点击窗口的任意地方,都会弹出系统菜单:
现在使用 ffi 调用 user32.dll 中的GetSy@L_988_33@menu 函数来解决这个问题,首先新建一个 user32.js 文件,为了展示 ffi ,我多定义了几个API函数:
const ffi = require('ffi') exportS.User32 = ffi.Library('user32',{ 'GetWindowLongPtrW': ['int',['int','int']],'SetWindowLongPtrW': ['int','int','long']],'GetSy@L_988_33@menu': ['int','bool']],'DestroyWindow': ['bool',['int']] });
const user32 = require('./app/scripts/user32').User32
win.once('ready-to-show',() => { let hwnd = win.getNativeWindowHandle() //获取窗口句柄。 user32.GetSy@L_988_33@menu(hwnd.readUInt32LE(0),true); 禁用系统菜单. win.show() })
再运行项目,系统菜单就消失的无影无踪了。
最后,所有代码都已经提交到了github:https://github.com/starts2000/ElectronQQLogin,欢迎获取。
以上是大佬教程为你收集整理的node-ffi模块的安装以及基于electron生成windows桌面应用程序全部内容,希望文章能够帮你解决node-ffi模块的安装以及基于electron生成windows桌面应用程序所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。