Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
4fc747d9
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4fc747d9
编写于
9月 18, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加创建浏览器窗口示例
上级
143ee26d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
150 addition
and
0 deletion
+150
-0
example/window/new-window/new-window.go
example/window/new-window/new-window.go
+95
-0
example/window/new-window/resources/index.html
example/window/new-window/resources/index.html
+26
-0
example/window/new-window/resources/new-window.html
example/window/new-window/resources/new-window.html
+19
-0
example/window/new-window/resources/other.html
example/window/new-window/resources/other.html
+10
-0
未找到文件。
example/window/new-window/new-window.go
0 → 100644
浏览文件 @
4fc747d9
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package
main
import
(
"embed"
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/cef/ipc/callback"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
)
//go:embed resources
var
resources
embed
.
FS
func
main
()
{
//全局初始化 每个应用都必须调用的
cef
.
GlobalInit
(
nil
,
&
resources
)
//创建应用
app
:=
cef
.
NewApplication
()
//cefApp.SetExternalMessagePump(false)
//cefApp.SetMultiThreadedMessageLoop(false)
//指定一个URL地址,或本地html文件目录
cef
.
BrowserWindow
.
Config
.
Url
=
"fs://energy"
cef
.
BrowserWindow
.
Config
.
LocalResource
(
cef
.
LocalLoadConfig
{
ResRootDir
:
"resources"
,
FS
:
&
resources
,
}
.
Build
())
cef
.
BrowserWindow
.
SetBrowserInit
(
func
(
event
*
cef
.
BrowserEvent
,
window
cef
.
IBrowserWindow
)
{
//浏览器窗口之后回调,在这里获取创建的浏览器ID
event
.
SetOnAfterCreated
(
func
(
sender
lcl
.
IObject
,
browser
*
cef
.
ICefBrowser
,
window
cef
.
IBrowserWindow
)
bool
{
// 创建完之后再拿浏览器id
fmt
.
Println
(
"on-create-window-ok"
,
browser
.
Identifier
(),
window
.
Id
())
ipc
.
Emit
(
"on-create-window-ok"
,
browser
.
Identifier
(),
window
.
Id
())
return
false
// 什么都不做
})
//---- ipc 监听事件
// 监听事件, 创建新窗口
ipc
.
On
(
"createWindow"
,
func
(
name
string
)
{
// 创建窗口常规属性对象
wp
:=
cef
.
NewWindowProperty
()
wp
.
Url
=
"fs://energy/new-window.html"
wp
.
Title
=
name
// 创建新的浏览器窗口
newWindow
:=
cef
.
NewLCLBrowserWindow
(
nil
,
wp
)
newWindow
.
SetWidth
(
800
)
newWindow
.
SetHeight
(
600
)
// EnableAllDefaultEvent 启用所有默认实现事件
// 如果未启用,所有事件需要你自己控制和实现, 大部分功能无法使用
newWindow
.
EnableAllDefaultEvent
()
newWindow
.
SetOnClose
(
func
(
sender
lcl
.
IObject
,
action
*
types
.
TCloseAction
)
bool
{
//窗口关闭时触发
ipc
.
Emit
(
"on-close-window"
,
newWindow
.
Id
())
return
false
// 不做处理
})
window
.
RunOnMainThread
(
func
()
{
// 在主线程中
newWindow
.
Show
()
})
})
// 改变当前窗口大小
ipc
.
On
(
"resize"
,
func
(
_type
int
,
channel
callback
.
IChannel
)
{
println
(
"resize type"
,
_type
,
"channel"
,
channel
.
ChannelId
(),
channel
.
BrowserId
())
win
:=
cef
.
BrowserWindow
.
GetWindowInfo
(
channel
.
BrowserId
())
if
win
==
nil
{
return
}
window
.
RunOnMainThread
(
func
()
{
switch
_type
{
case
1
:
win
.
SetSize
(
400
,
200
)
case
2
:
win
.
SetSize
(
600
,
400
)
case
3
:
win
.
SetSize
(
800
,
600
)
}
})
})
})
//运行应用
cef
.
Run
(
app
)
}
example/window/new-window/resources/index.html
0 → 100644
浏览文件 @
4fc747d9
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
new-window
</title>
<script>
function
createWindow
()
{
ipc
.
emit
(
"
createWindow
"
,
[
"
NewWindowName
"
+
new
Date
().
getTime
()],
function
(
windowId
)
{
});
}
ipc
.
on
(
"
on-create-window-ok
"
,
function
(
id
)
{
document
.
getElementById
(
"
msg
"
).
innerText
=
"
窗口创建成功:
"
+
id
});
ipc
.
on
(
"
on-close-window
"
,
function
(
id
)
{
document
.
getElementById
(
"
msg
"
).
innerText
=
"
窗口被关闭:
"
+
id
});
</script>
</head>
<body
style=
"width: 100%;text-align: center;overflow: hidden;"
>
<button
onclick=
"createWindow()"
>
创建新窗口
</button>
<a
href=
"index.html"
target=
"_blank"
>
超链接打开新窗口
</a>
<div
id=
"msg"
></div>
</body>
</html>
\ No newline at end of file
example/window/new-window/resources/new-window.html
0 → 100644
浏览文件 @
4fc747d9
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
new-window
</title>
<script>
function
resize
(
type
)
{
ipc
.
emit
(
"
resize
"
,
[
type
]);
}
</script>
</head>
<body
style=
"width: 100%;text-align: center;overflow: hidden;"
>
改变当前窗口大小:
<button
onclick=
"resize(1)"
>
小
</button>
<button
onclick=
"resize(2)"
>
中
</button>
<button
onclick=
"resize(3)"
>
大
</button>
<a
href=
"other.html"
>
other
</a>
</body>
</html>
\ No newline at end of file
example/window/new-window/resources/other.html
0 → 100644
浏览文件 @
4fc747d9
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
new-window
</title>
</head>
<body
style=
"width: 100%;text-align: center;overflow: hidden;"
>
<h1>
Other
</h1>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录