forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_windows.go
68 lines (57 loc) · 1.69 KB
/
main_windows.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/CzarekTomczak/cef2go
package main
import (
"cef"
"log"
"os"
"syscall"
"time"
"unsafe"
"wingui"
)
var Logger *log.Logger = log.New(os.Stdout, "[main] ", log.Lshortfile)
func main() {
hInstance, e := wingui.GetModuleHandle(nil)
if e != nil {
wingui.AbortErrNo("GetModuleHandle", e)
}
cef.ExecuteProcess(unsafe.Pointer(hInstance))
settings := cef.Settings{}
settings.CachePath = "webcache" // Set to empty to disable
settings.LogSeverity = cef.LOGSEVERITY_DEFAULT // LOGSEVERITY_VERBOSE
cef.Initialize(settings)
wndproc := syscall.NewCallback(WndProc)
Logger.Println("CreateWindow")
hwnd := wingui.CreateWindow("cef2go example", wndproc)
browserSettings := cef.BrowserSettings{}
// TODO: It should be executable's directory used
// rather than working directory.
url, _ := os.Getwd()
url = "file://" + url + "/example.html"
cef.CreateBrowser(unsafe.Pointer(hwnd), browserSettings, url)
// It should be enough to call WindowResized after 10ms,
// though to be sure let's extend it to 100ms.
time.AfterFunc(time.Millisecond*100, func() {
cef.WindowResized(unsafe.Pointer(hwnd))
})
cef.RunMessageLoop()
cef.Shutdown()
os.Exit(0)
}
func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
switch msg {
case wingui.WM_CREATE:
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
case wingui.WM_SIZE:
cef.WindowResized(unsafe.Pointer(hwnd))
case wingui.WM_CLOSE:
wingui.DestroyWindow(hwnd)
case wingui.WM_DESTROY:
cef.QuitMessageLoop()
default:
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
}
return
}