现在基于 js 和 web浏览器核心构建的 C/S 程序越来越多,比如微信桌面版(基于 duilibcef)、VS CODE(基于electron)等,出于了解的目的,最近学习了 electron。electron具体是什么,可以做什么,这里不做过多的介绍,网上很多相关的介绍,这里主要介绍在VS2017下怎么进行 electron 应用程序的开发。

一、环境搭建

  • 安装 node.js 及 npm。
  • 安装 vs2017 ,必须安装 node.js web开发包。

二、创建空白 Node.js 控制台应用程序项目

创建好的项目结构入下:

三、编写 electron Hello Word

参照 https://github.com/electron/electron/blob/master/docs/tutorial/quick-start.md

1、打开 package.json 加入:

"dependencies": {
"electron": "^1.6.6"
}

最后内容如下:

{
"name": "electron-hello-word",
"version": "0.0.0",
"description": "ElectronHelloWord",
"main": "app.js",
"author": {
"name": "Starts_2000"
},
"dependencies": {
"electron": "^1.6.6"
}
}

2、打开 app.js,输入以下内容:

'use strict';

const { app, BrowserWindow } = require('electron')
const path = require('path')
const url = require('url') // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 }) // and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
})) // Open the DevTools.
win.webContents.openDevTools() // Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
} // This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow) // Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
}) app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
}) // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

3、新建 index.html 文件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node
<script>document.write(process.versions.node)</script>,
Chrome
<script>document.write(process.versions.chrome)</script>,
and Electron
<script>document.write(process.versions.electron)</script>.
</body>
</html>

四、设置和运行

1、NPM 安装  electron 包

安装成功后可看到,点击解决方案上方的显示所有文件,可以看到

2、设置项目 Node.exe路径为:

.\node_modules\electron\dist\electron.exe

运行解决方案,就可以看到electron 的 Hello Word示例了:

使用 VS2017 和 js 进行桌面程序开发 - electron 之 Hello Word的更多相关文章

  1. 用python进行桌面程序开发

    Python是一种面向对象.直译式计算机程序设计语言,也是一种功能强大而完善的通用型语言,已经具有十多年的发展历史,成熟且稳定.这种语言具有非常简捷而清晰的语法特点,适合完成各种高层任务,几乎可以在所 ...

  2. Node.js 命令行程序开发资料

    Node.js 命令行程序开发教程http://www.ruanyifeng.com/blog/2015/05/command-line-with-node.html用Node.js创建命令行工具ht ...

  3. 用node-webkit(NW.js)创建桌面程序

    以往写windows桌面程序需要用MFC.C#之类的技术,那么如果你只会web开发技术呢?或者说你有一个网站,但是你想把你的网站打包成一个桌面应用程序,该如何做呢? 答案就是用node-webkit这 ...

  4. [Flutter] Windows桌面程序开发

    在今年5月的谷歌I/O 2019大会时, 谷歌就宣布了flutter已经支持全平台开发, 包括 android, ios, mac, linux, windows, web 等 . Flutter桌面 ...

  5. Python3的桌面程序开发利器:Eric6的环境搭建、使用

    本文旨在通过一个简单的demo,介绍基于Python3.PyQT5的环境下开发桌面应用程序的一种方案,当然开发Python的桌面应用程序不止是PyQT 这一种方案,还可以使用Python自带的Tkin ...

  6. 如何选择合适的Linux系统进行桌面程序开发?

    32 or 64 ? 众所周知,64位的Windows系统可以近乎完美地运行32位的应用程序,微软出于商业考虑做了这样一个兼容层.而Linux系统则划分的很清楚,默认情况下64位的Linux系统无法运 ...

  7. Node.js 命令行程序开发教程

    nodejs开发命令行程序非常方便,具体操作方式查看下面几篇文章 http://www.ruanyifeng.com/blog/2015/05/command-line-with-node.html ...

  8. Node.js 命令行程序开发教程 ---------http://www.ruanyifeng.com/blog/2015/05/command-line-with-node.html

    五.yargs 模块 shelljs 只解决了如何调用 shell 命令,而 yargs 模块能够解决如何处理命令行参数.它也需要安装. $ npm install --save yargs yarg ...

  9. 关于JS及应用程序开发的一些体会

    代码通常从 一,生命周期 二,业务流程 这几方面来看. JS Client可以和Server端分离. JS端的生命周期. Server端就是 JS能处理的只是HTTP协议.

随机推荐

  1. html或者php中 input框限制只能输入正整数,逻辑与和或运算

    有时需要限制文本框输入内容的类型,本节分享下正则表达式限制文本框只能输入数字.小数点.英文字母.汉字等代码. 例如,输入大于0的正整数 代码如下: <input onkeyup="if ...

  2. day5_ 导入模块和包

    ######################模块导入模块做的事1.产生新的名称空间2.以新建的名称空间为全局名称空间,执行文件的代码3.拿到一个模块名spam,指向spam.py产生的名称空间 imp ...

  3. mysqldump命令详解

    1.数据备份的重要性: 保护公司的数据 网站的7x24提供服务 2.MySQL数据库备份: --all-databases , -A 导出全部数据库. mysqldump -uroot -p --al ...

  4. 提升单元测试体验的利器--Mockito使用总结

    为神马要使用Mockito? 在编写单元测试的时候,为了尽可能的保证隔离性,我们时常需要对某些不容易构造或者不容易获取或者对外部环境有依赖的对象,用一个虚拟的对象来创建以便于测试.假设你正在开发的的代 ...

  5. wpf XAML xaml 进行 数据绑定,Resource DataContext ElementName

    先做个声明:这里绑定都在前台实现,至于后台怎么写,那比前台简单多了,但更常用的是xaml中绑定.我们分析下最简单的字符串绑定来弄清楚原理,其他的类推就是. 数据绑定主要是要弄清楚两个东西,一个是源So ...

  6. dedecms后台添加新变量和删除变量的方法

    下面由做网站为大家来介绍dedecms后台添加新变量和删除变量的方法 添加新变量是做什么用的?答:可以在模板内调用的东东. 一.进入网站织梦(Dedecms)后台(以dede5.5为例),依次打开系统 ...

  7. HTML 简单了解

    HTML 特别的通俗易懂!想学自己制作网页的,就来我这看看吧! 首先 我先介绍一下什么是HTML! HTML是用来描述网页的一种语言!他结合CSS样式之后会有非常炫酷的样式! 1.HTML是指一种超文 ...

  8. window.close()方法对谷歌和火狐浏览器无效

    在近期的项目中,遇到了一个问题,就是用户到新浪支付进行操作,操作成功后,指定到一个网页,需求是点击确定,关闭该网页.需求出来以后认为这种就是小菜一碟,直接用 window.close()方法就可以实现 ...

  9. [转] .NET领域驱动设计—实践(穿过迷雾走向光明)

    阅读目录 开篇介绍 1.1示例介绍 (OnlineExamination在线考试系统介绍) 1.2分析.建模 (对真实业务进行分析.模型化) 1.2.1 用例分析 (提取系统的所有功能需求) 1.3系 ...

  10. 页面实现多个定时器(计时器)时选用NSTimer还是GCD?(干货不湿)

    定时器在我们每个人做的iOS项目里面必不可少,如登录页面倒计时.支付期限倒计时等等,一般来说使用NSTimer创建定时器: + (NSTimer *)timerWithTimeInterval:(NS ...