提交 4eabf9d9 编写于 作者: yanghye's avatar yanghye

demo: new-window

上级 192e033d
......@@ -29,8 +29,8 @@ func main() {
//创建应用
app := cef.NewApplication()
//强制使用VF窗口
app.SetExternalMessagePump(false)
app.SetMultiThreadedMessageLoop(false)
//app.SetExternalMessagePump(false)
//app.SetMultiThreadedMessageLoop(false)
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "fs://energy"
......@@ -59,7 +59,8 @@ func main() {
wp := cef.NewWindowProperty()
wp.Url = "fs://energy/new-window.html"
wp.Title = name
// 创建新的浏览器窗口
wp.EnableHideCaption = true // 无标题窗口
// 创建浏览器窗口
newWindow := cef.NewBrowserWindow(nil, wp)
newWindow.SetWidth(800)
newWindow.SetHeight(600)
......@@ -68,9 +69,9 @@ func main() {
newWindow.EnableAllDefaultEvent()
window.RunOnMainThread(func() {
println("create-window show", name)
// 在主线程中
newWindow.Show()
})
// 在主线程中
newWindow.Show()
})
// 改变当前窗口大小
ipc.On("resize", func(_type int, channel callback.IChannel) {
......@@ -86,7 +87,7 @@ func main() {
case 2:
win.SetSize(600, 400)
case 3:
win.SetSize(800, 600)
win.SetSize(1024, 768)
}
})
})
......
......@@ -4,15 +4,17 @@
<meta charset="UTF-8">
<title>new-window</title>
<script>
// 创建子窗口
function createWindow() {
ipc.emit("create-window", ["NewWindowName " + new Date().getTime()]);
}
// 子窗口创建
ipc.on("on-create-window-ok", function (id) {
document.getElementById("msg").innerText = "窗口创建成功: " + id
document.getElementById("msg").innerText = "创建 - 窗口ID: " + id
});
// 子窗口关闭
ipc.on("on-close-window", function (id) {
document.getElementById("msg").innerText = "窗口被关闭: " + id
document.getElementById("msg").innerText = "关闭 - 窗口ID: " + id
});
</script>
</head>
......
......@@ -3,17 +3,35 @@
<head>
<meta charset="UTF-8">
<title>new-window</title>
<style type="text/css">
a, button, div {
-webkit-app-region: no-drag;
}
body {
margin: 0px;
padding: 0px;
text-align: center;
overflow: hidden;
-webkit-app-region: drag;
width: 100%;
height: 100vh;
}
</style>
<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>
改变当前窗口大小:
<button onclick="resize(1)"></button>
<button onclick="resize(2)"></button>
<button onclick="resize(3)"></button>
<a href="other.html">other</a>
<div style="height: 100px;width: 100px;background-color: gainsboro;text-align: center;vertical-align: center;">
此区域可右键关闭窗口
</div>
</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.
先完成此消息的编辑!
想要评论请 注册